Repository navigation
Conversation
Contributor
Author
|
Hi maintainers, this PR is ready for review. The CI workflows are waiting on first-time-contributor approval, so a workflow run approval would be appreciated when you get a chance. Thanks. |
kddejong
approved these changes
Nov 20, 2026
Since 1.26.0, Sub.fn_sub rebound value to the string element of the two-element form before calling its child rules, so SubParametersUsed (W1019) received only a string and returned early without ever checking the variable map. Restore the whole Fn::Sub value for the child rule calls, as was the case before aws-cloudformation#3962, and make the W1051 child rule handle the two-element form by checking its string element. W1020 already handled both forms and is unchanged in behavior. Fixes aws-cloudformation#4959 Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
kddejong
force-pushed
the
fix-4959-w1019-unused-sub-vars
branch
from
November 20, 2026 18:51
7129aa5 to
f19adb1
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4964 +/- ##
=======================================
Coverage 94.82% 94.82%
=======================================
Files 441 441
Lines 16185 16187 +2
Branches 3138 3139 +1
=======================================
+ Hits 15348 15350 +2
Misses 463 463
Partials 374 374
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What broke
W1019 (unused
Fn::Subvariables) no longer reports anything since 1.26.0. A template with a variable map key that the string never uses produces no finding at all.Root cause
In
src/cfnlint/rules/functions/Sub.py,fn_subrebindsvalue = value[0]for the two-element form and then calls each child rule withrule.validate(value_validator, s, value, schema). W1019 therefore receives only the string, andSubParametersUsed.validatereturns early on a string (if validator.is_type(instance, "string"): return), so the variable map is never checked. The child call passedinstance.get("Fn::Sub")(the whole pair) until #3962, first released in 1.26.0. W1020 still fired because it already handles both the string and pair forms.Fix
Sub.fn_subagain passes the wholeFn::Subvalue to its child rules, restoring the pre-Add rule W1051 to validate if dyn ref when arn #3962 behavior. W1019 sees the variable map again; W1020 is unchanged in behavior.DynamicReferenceSecretsManagerArn(W1051, also a child rule ofSub) now handles the two-element form by checking its string element, so restoring the pair cannot break it.Reproduction
Template (from the issue): two
AWS::SSM::Parameterresources using!Subwith a two-element form where map keyBis never used in the string.Before (upstream
mainat008ead690):After (this branch):
This matches the 1.25.1 output quoted in the issue, including the W1020 finding still firing.
Tests
test/unit/rules/functions/test_sub.py(test_sub_child_rules_get_whole_sub_value, 3 cases): unused variable in the two-element form, unused variable with no variable used at all (W1019 plus W1020), and all variables used (no findings). Verified the two W1019 cases fail with the fix reverted and pass with it.pytest test/unit/rules/functions/test_sub.py test/unit/rules/functions/test_sub_parameters_used.py test/unit/rules/functions/test_sub_unneeded.py test/unit/rules/functions/test_sub_needed.py test/unit/rules/functions/test_sub_not_join.py: 54 passed.pytest test/unit/rules/functions/: 296 passed.pytest test/unit/rules/: 2185 passed.ruff checkon all three changed files: clean.Fixes #4959