feat(config): add strict_config to reject unknown configuration keys - #2081
feat(config): add strict_config to reject unknown configuration keys#2081Manny7717 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. |
|
Closing this as a duplicate of #1961 (bearomorphism), which predates it (opened May 9) and implements the same |
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