feat(config): add strict_config to reject unknown configuration keys - #2081
Open
Manny7717 wants to merge 2 commits into
Open
feat(config): add strict_config to reject unknown configuration keys#2081Manny7717 wants to merge 2 commits into
Manny7717 wants to merge 2 commits into
Conversation
When enabled, unknown top-level keys in the [tool.commitizen] section (e.g. a typo like 'bump_mesage') raise InvalidConfigurationError instead of being silently ignored. Mirrors pytest's --strict-markers. - Add strict_config setting (default False) to Settings/DEFAULT_SETTINGS - Validate parsed keys against known settings in BaseConfig - Wire the check into the TOML, JSON and YAML config parsers - Document the option and add regression tests Closes commitizen-tools#300
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2081 +/- ##
==========================================
+ Coverage 98.19% 98.27% +0.07%
==========================================
Files 61 61
Lines 2829 2844 +15
==========================================
+ Hits 2778 2795 +17
+ Misses 51 49 -2 ☔ View full report in Codecov by Harness. |
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.
Description
Closes #300.
Adds a new
strict_configconfiguration option (defaultfalse). When enabled, Commitizen rejects unknown top-level keys in the[tool.commitizen](orcommitizen) section of the configuration file with anInvalidConfigurationErrorlisting the offending keys — the same spirit as pytest's--strict-markers. This makes typos likebump_mesagefail loudly instead of being silently ignored.Changes:
SettingsTypedDict +DEFAULT_SETTINGS: newstrict_configkeyBaseConfig._check_unknown_keys(): validates parsed top-level keys against the known settings (derived from theSettingsTypedDict, plusannotated_tag_messagewhich predates the TypedDict)strict_configsection indocs/config/option.mdand a category entry inconfiguration_file.mdKeys nested under
customizeandextrasare plugin-owned and deliberately not checked.Checklist
Was generative AI tooling used to co-author this PR?
Code Changes
uv run poe alllocally to ensure this change passes linter check and tests (ruff check, ruff format --check, mypy, full pytest suite — see below)strict_config = true+ typo'd key →InvalidConfigurationErrornaming the key; same config withoutstrict_config→ loads normally; valid keys with strict mode on → loads normallyannotated_tag_message(consumed but not in the TypedDict) acceptedfalse, so existing configurations are unaffectedTests
1314 passed, 2 xfailed(uv run pytest -n auto)ruff checkclean,ruff format --checkclean,mypy commitizen/clean