feat(config): warn on unknown configuration keys#1961
Open
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
Open
feat(config): warn on unknown configuration keys#1961bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
Conversation
Add a `strict_config` boolean setting (default `False`) that controls how unknown keys inside the commitizen configuration section are handled. * By default, unknown keys produce a warning so typos like `update_changelog_on_bumb` are surfaced without breaking existing setups. * When `strict_config = true` is set, the same condition raises `InvalidConfigurationError` (exit code `INVALID_CONFIGURATION`). Validation is implemented in `BaseConfig._validate_known_keys` and called from each concrete parser (`TomlConfig`, `JsonConfig`, `YAMLConfig`) right after the section is loaded. Closes commitizen-tools#300 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1961 +/- ##
==========================================
+ Coverage 98.23% 98.25% +0.01%
==========================================
Files 61 61
Lines 2779 2800 +21
==========================================
+ Hits 2730 2751 +21
Misses 49 49 ☔ View full report in Codecov by Sentry. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds configurable validation for unknown keys in the commitizen configuration section, warning by default to surface typos while allowing users to opt into strict (error) behavior.
Changes:
- Introduces
strict_configsetting (defaultFalse) and a centralizedKNOWN_SETTINGS_KEYSset. - Adds unknown-key detection in
BaseConfig, warning or raisingInvalidConfigurationErrordepending onstrict_config. - Updates TOML/JSON/YAML config loaders to run the new validation and adds tests + documentation for the new option.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
commitizen/defaults.py |
Adds strict_config to settings and derives KNOWN_SETTINGS_KEYS for validation. |
commitizen/config/base_config.py |
Implements unknown-key detection with warn/raise behavior controlled by strict_config. |
commitizen/config/toml_config.py |
Validates loaded TOML commitizen section keys after parsing. |
commitizen/config/json_config.py |
Validates loaded JSON commitizen section keys after parsing. |
commitizen/config/yaml_config.py |
Validates loaded YAML commitizen section keys after parsing. |
tests/test_conf.py |
Adds coverage for warning behavior, strict-mode error, and known-keys no-op across formats. |
docs/config/option.md |
Documents the new strict_config option and its intended usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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_configboolean setting that controls how unknown keys inside the commitizen configuration section are handled.strict_config = false) – unknown keys emit a warning so typos likeupdate_changelog_on_bumbare surfaced without breaking existing setups.strict_config = true– the same condition raisesInvalidConfigurationError(exit codeINVALID_CONFIGURATION), behaving likepytest --strict-markers.This matches the direction agreed in the issue discussion (#300 (comment)): warnings by default, strict mode opt-in.
Implementation
Settings(commitizen/defaults.py) gainsstrict_config: booland a derivedKNOWN_SETTINGS_KEYSconstant.BaseConfig._validate_known_keys(commitizen/config/base_config.py) computes the unknown keys, raises in strict mode, and warns otherwise.TomlConfig,JsonConfig,YAMLConfig) calls the helper with the loaded section.tests/test_conf.pycover the warning, strict-mode error, and no-op cases for all supported config formats.strict_configsection todocs/config/option.md.Out of scope
pytest --strict-markers. Users can set the option in the config file; a CLI flag can be added later if needed.Checklist
uv run poe format/uv run poe lintclean