Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat(config): add strict_config option to reject unknown config keys#1945

Closed
Prayasvadlakonda wants to merge 3 commits intocommitizen-tools:masterfrom
Prayasvadlakonda:feat/strict-config-validation
Closed

feat(config): add strict_config option to reject unknown config keys#1945
Prayasvadlakonda wants to merge 3 commits intocommitizen-tools:masterfrom
Prayasvadlakonda:feat/strict-config-validation

Conversation

@Prayasvadlakonda
Copy link
Copy Markdown

Summary

Closes #300

When users have a typo in their commitizen config (e.g. tga_format instead of tag_format), commitizen silently ignores the unknown key. This PR adds a strict_config option that raises InvalidConfigurationError on unrecognised config keys, catching mistakes early.

Usage

[tool.commitizen]
strict_config = true
tga_format = "v$version"   # typo — raises InvalidConfigurationError
commitizen.exceptions.InvalidConfigurationError: Unknown commitizen config keys: tga_format

When strict_config = false (the default), behaviour is unchanged.

Changes

  • commitizen/defaults.py — added strict_config: bool to Settings TypedDict and "strict_config": False to DEFAULT_SETTINGS
  • commitizen/config/base_config.py — added _VALID_CONFIG_KEYS (derived from Settings.__annotations__); added unknown-key check in update() when strict_config=True
  • commitizen/config/toml_config.py, json_config.py, yaml_config.py — changed self.settings.update(...)self.update(...) so the validation runs during config loading
  • tests/test_conf.py — new TestStrictConfig class covering TOML, JSON, and YAML parsers; default-off behaviour; valid keys; and multi-key error messages

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

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (efb1a7d) to head (0ce9a86).
⚠️ Report is 1 commits behind head on master.

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

@bearomorphism
Copy link
Copy Markdown
Collaborator

please follow our AI assisted PR guidelines, thanks

@bearomorphism
Copy link
Copy Markdown
Collaborator

feel free to reopen this PR after fixing the PR desc format

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