Skip to content

fix: let api.lint() run a Rules collection passed by the caller - #4909

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:fix/api-lint-rules-collection
Oct 30, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:fix/api-lint-rules-collection

Conversation

@hoganbr-amzn

@hoganbr-amzn hoganbr-amzn commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available: fixes #4949

Description of changes:

cfnlint.api.lint() documents a rules parameter and routes it to run_template_by_data, but the isinstance check only accepts the pre-1.0 RulesCollection. Passing the 1.x Rules class falls through to a fresh Runner, which loads every built-in rule and never runs the collection it was handed. Measured: a one-rule Rules passed to lint() ran all built-ins (0.35 s, W8001) and produced none of the caller's findings.

The fix accepts Rules | RulesCollection and updates the docstring. Not changed here: on the legacy RulesCollection path, run_template_by_data calls rules.is_rule_enabled(TransformError(), config) with two arguments while RulesCollection.is_rule_enabled takes one, so a transform error on that path raises TypeError; that predates this change and can be tracked separately. Two tests: a one-rule collection produces exactly that rule's finding, and ignore_checks in config still applies to it.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

lint() documents a rules parameter but only honoured the pre-1.0
RulesCollection class. A Rules collection fell through to a fresh Runner,
which loaded every built-in rule and never ran the rules it was handed.

Signed-off-by: Brenden Hogan <hoganbr@amazon.com>
@kddejong
kddejong force-pushed the fix/api-lint-rules-collection branch from da32335 to eb07a95 Compare October 30, 2026 20:30
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.71%. Comparing base (008ead6) to head (eb07a95).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4909   +/-   ##
=======================================
  Coverage   94.71%   94.71%           
=======================================
  Files         442      442           
  Lines       16087    16087           
  Branches     3120     3120           
=======================================
  Hits        15237    15237           
  Misses        468      468           
  Partials      382      382           
Flag Coverage Δ
unittests 94.71% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kddejong
kddejong merged commit 5d5eddc into aws-cloudformation:main Oct 30, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cfnlint.api.lint() ignores a Rules collection passed as rules and runs the built-in rule set instead

2 participants