Skip to content

feat(config): warn on unknown configuration keys#1961

Open
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
bearomorphism:feat/strict-config-validation
Open

feat(config): warn on unknown configuration keys#1961
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
bearomorphism:feat/strict-config-validation

Conversation

@bearomorphism
Copy link
Copy Markdown
Collaborator

Description

Closes #300.

Adds a new strict_config boolean setting that controls how unknown keys inside the commitizen configuration section are handled.

  • Default (strict_config = false) – unknown keys emit a warning so typos like update_changelog_on_bumb are surfaced without breaking existing setups.
  • strict_config = true – the same condition raises InvalidConfigurationError (exit code INVALID_CONFIGURATION), behaving like pytest --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) gains strict_config: bool and a derived KNOWN_SETTINGS_KEYS constant.
  • BaseConfig._validate_known_keys (commitizen/config/base_config.py) computes the unknown keys, raises in strict mode, and warns otherwise.
  • Each concrete parser (TomlConfig, JsonConfig, YAMLConfig) calls the helper with the loaded section.
  • New tests in tests/test_conf.py cover the warning, strict-mode error, and no-op cases for all supported config formats.
  • Added a strict_config section to docs/config/option.md.

Out of scope

  • Type validation of values – mentioned as a follow-up in the discussion. Could be done in a later PR using decli's argparse-based typing.
  • CLI flag mirroring pytest --strict-markers. Users can set the option in the config file; a CLI flag can be added later if needed.

Checklist

  • Add tests
  • Update documentation
  • uv run poe format / uv run poe lint clean
  • Existing test suite green locally on Windows

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
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.25%. Comparing base (4b93a50) to head (96edb12).
⚠️ Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@bearomorphism bearomorphism requested a review from Copilot May 9, 2026 09:52
@bearomorphism bearomorphism marked this pull request as ready for review May 9, 2026 09:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_config setting (default False) and a centralized KNOWN_SETTINGS_KEYS set.
  • Adds unknown-key detection in BaseConfig, warning or raising InvalidConfigurationError depending on strict_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check unknown config in configuration file

2 participants