feat(config): add strict_config option to reject unknown config keys#1945
Closed
Prayasvadlakonda wants to merge 3 commits intocommitizen-tools:masterfrom
Closed
feat(config): add strict_config option to reject unknown config keys#1945Prayasvadlakonda wants to merge 3 commits intocommitizen-tools:masterfrom
Prayasvadlakonda wants to merge 3 commits intocommitizen-tools:masterfrom
Conversation
Add a `strict_config` boolean option (default: false). When enabled, commitizen raises InvalidConfigurationError if any key in the config file is not a recognised Settings field. This catches typos early instead of silently ignoring them. - Add `strict_config` to the Settings TypedDict and DEFAULT_SETTINGS - Add `_VALID_CONFIG_KEYS` in base_config derived from Settings.__annotations__ - Validate unknown keys in BaseConfig.update() when strict_config=True - Route all _parse_setting calls through self.update() so validation runs - Add tests covering TOML, JSON, YAML parsers and edge cases Closes commitizen-tools#300
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1945 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 61 61
Lines 2772 2779 +7
=======================================
+ Hits 2723 2730 +7
Misses 49 49 ☔ View full report in Codecov by Sentry. |
Collaborator
|
please follow our AI assisted PR guidelines, thanks |
Collaborator
|
feel free to reopen this PR after fixing the PR desc format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #300
When users have a typo in their commitizen config (e.g.
tga_formatinstead oftag_format), commitizen silently ignores the unknown key. This PR adds astrict_configoption that raisesInvalidConfigurationErroron unrecognised config keys, catching mistakes early.Usage
When
strict_config = false(the default), behaviour is unchanged.Changes
commitizen/defaults.py— addedstrict_config: booltoSettingsTypedDict and"strict_config": FalsetoDEFAULT_SETTINGScommitizen/config/base_config.py— added_VALID_CONFIG_KEYS(derived fromSettings.__annotations__); added unknown-key check inupdate()whenstrict_config=Truecommitizen/config/toml_config.py,json_config.py,yaml_config.py— changedself.settings.update(...)→self.update(...)so the validation runs during config loadingtests/test_conf.py— newTestStrictConfigclass covering TOML, JSON, and YAML parsers; default-off behaviour; valid keys; and multi-key error messages