Skip to content

Commit e43f660

Browse files
authored
Change transform check in W3037 (#4041)
1 parent 8ed4399 commit e43f660

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/cfnlint/rules/functions/SubUnneeded.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import regex as re
99

10-
from cfnlint.helpers import REGEX_SUB_PARAMETERS, ensure_list
10+
from cfnlint.helpers import REGEX_SUB_PARAMETERS, TRANSFORM_SAM, ensure_list
1111
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
1212
from cfnlint.rules import CloudFormationLintRule
1313

@@ -24,9 +24,7 @@ class SubUnneeded(CloudFormationLintRule):
2424
def validate(
2525
self, validator: Validator, s: Any, instance: Any, schema: Any
2626
) -> ValidationResult:
27-
if "AWS::Serverless-2016-10-31" in ensure_list(
28-
validator.cfn.transform_pre.get("Transform")
29-
):
27+
if TRANSFORM_SAM in ensure_list(validator.cfn.transform_pre.get("Transform")):
3028
return
3129
if validator.is_type(instance, "string"):
3230
variables = re.findall(REGEX_SUB_PARAMETERS, instance)

src/cfnlint/rules/resources/HardCodedArnProperties.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import regex as re
77

88
from cfnlint._typing import RuleMatches
9+
from cfnlint.helpers import TRANSFORM_SAM
910
from cfnlint.rules import CloudFormationLintRule, RuleMatch
1011
from cfnlint.template import Template
1112

@@ -87,7 +88,7 @@ def match(self, cfn: Template) -> RuleMatches:
8788

8889
transforms = cfn.transform_pre["Transform"]
8990
transforms = transforms if isinstance(transforms, list) else [transforms]
90-
if "AWS::Serverless-2016-10-31" in cfn.transform_pre["Transform"]:
91+
if TRANSFORM_SAM in cfn.transform_pre["Transform"]:
9192
return matches
9293

9394
# Get a list of paths to every leaf node string containing at least one ${parameter}

src/cfnlint/rules/resources/iam/Permissions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import regex as re
1111

1212
from cfnlint.data import AdditionalSpecs
13-
from cfnlint.helpers import ensure_list, load_resource
13+
from cfnlint.helpers import TRANSFORM_SAM, ensure_list, load_resource
1414
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
1515
from cfnlint.rules.jsonschema.CfnLintKeyword import CfnLintKeyword
1616

@@ -41,7 +41,7 @@ def validate(
4141
) -> ValidationResult:
4242
# Escape validation when using SAM transforms as a result of
4343
# https://github.com/aws/serverless-application-model/issues/3633
44-
if validator.context.transforms.has_sam_transform():
44+
if TRANSFORM_SAM in validator.cfn.transform_pre["Transform"]:
4545
return
4646

4747
actions = ensure_list(instance)

src/cfnlint/template/template.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def __init__(
7272
self.transform_pre["Fn::Sub"] = self.search_deep_keys("Fn::Sub")
7373
self.transform_pre["Fn::If"] = self.search_deep_keys("Fn::If")
7474
self.transform_pre["Fn::FindInMap"] = self.search_deep_keys("Fn::FindInMap")
75-
self.transform_pre["Transform"] = self.template.get("Transform", [])
75+
self.transform_pre["Transform"] = cfnlint.helpers.ensure_list(
76+
self.template.get("Transform", [])
77+
)
7678
self.transform_pre["Fn::ForEach"] = self.search_deep_keys(
7779
cfnlint.helpers.FUNCTION_FOR_EACH
7880
)
@@ -155,14 +157,13 @@ def has_serverless_transform(self) -> bool:
155157
Returns:
156158
bool: True if the AWS::Serverless-2016-10-31 transform is declared, False otherwise.
157159
"""
158-
lang_extensions_transform = "AWS::Serverless-2016-10-31"
159160
transform_declaration = self.transform_pre["Transform"]
160161
transform_type = (
161162
transform_declaration
162163
if isinstance(transform_declaration, list)
163164
else [transform_declaration]
164165
)
165-
return bool(lang_extensions_transform in transform_type)
166+
return bool(cfnlint.helpers.TRANSFORM_SAM in transform_type)
166167

167168
def is_cdk_template(self) -> bool:
168169
"""Check if the template was created by the AWS Cloud Development Kit (CDK).

src/cfnlint/template/transforms/transform.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from cfnlint.conditions import Conditions
1212
from cfnlint.context import create_context_for_template
1313
from cfnlint.graph import Graph
14-
from cfnlint.helpers import format_json_string
14+
from cfnlint.helpers import TRANSFORM_SAM, format_json_string
1515
from cfnlint.match import Match
1616
from cfnlint.template.transforms._language_extensions import language_extension
1717
from cfnlint.template.transforms._sam import sam
@@ -23,7 +23,7 @@
2323
class Transform:
2424
def __init__(self) -> None:
2525
self.transforms: Mapping[str, Callable[[Any], TransformResult]] = {
26-
"AWS::Serverless-2016-10-31": sam,
26+
TRANSFORM_SAM: sam,
2727
"AWS::LanguageExtensions": language_extension,
2828
}
2929

@@ -62,7 +62,7 @@ def transform(self, cfn: Any) -> list[Match]:
6262
# SAM will erase the entire Transform section
6363
# this sets it back with all transforms except SAM
6464
cfn.template["Transform"] = [
65-
t for t in transform_type if t != "AWS::Serverless-2016-10-31"
65+
t for t in transform_type if t != TRANSFORM_SAM
6666
]
6767

6868
LOGGER.info("Transformed template: \n%s", format_json_string(cfn.template))

0 commit comments

Comments
 (0)