""" Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: MIT-0 """ from cfnlint.rules import CloudFormationLintRule, RuleMatch class SubNotJoin(CloudFormationLintRule): """Check if Join is being used with no join characters""" id = "I1022" shortdesc = "Use Sub instead of Join" description = ( "Prefer a sub instead of Join when using a join delimiter that is empty" ) source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html" tags = ["functions", "sub", "join"] def _check_element(self, element): if isinstance(element, dict): if len(element) == 1: for key, value in element.items(): if key in ["Fn::Sub"]: if not isinstance(value, str): return False elif key not in ["Ref", "Fn::GetAtt"]: return False return True def _check_elements(self, elements): for element in elements: if not self._check_element(element): return False return True def match(self, cfn): matches = [] join_objs = cfn.search_deep_keys("Fn::Join") for join_obj in join_objs: if isinstance(join_obj[-1], list): join_operator = join_obj[-1][0] join_elements = join_obj[-1][1] if isinstance(join_operator, str): if join_operator == "": if isinstance(join_elements, list): if self._check_elements(join_elements): matches.append( RuleMatch( join_obj[0:-1], "Prefer using Fn::Sub over Fn::Join with an empty delimiter", ) ) return matches
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
Base64.py | File | 1.72 KB | 0644 |
|
Cidr.py | File | 11.94 KB | 0644 |
|
DynamicReferenceSecureString.py | File | 5.72 KB | 0644 |
|
FindInMap.py | File | 11.25 KB | 0644 |
|
FindInMapKeys.py | File | 3.89 KB | 0644 |
|
GetAtt.py | File | 6.05 KB | 0644 |
|
GetAz.py | File | 2.76 KB | 0644 |
|
If.py | File | 1.45 KB | 0644 |
|
ImportValue.py | File | 2.45 KB | 0644 |
|
Join.py | File | 8.63 KB | 0644 |
|
Length.py | File | 3.31 KB | 0644 |
|
Not.py | File | 978 B | 0644 |
|
Ref.py | File | 1.02 KB | 0644 |
|
RefExist.py | File | 1.26 KB | 0644 |
|
RefInCondition.py | File | 1.36 KB | 0644 |
|
RelationshipConditions.py | File | 5.35 KB | 0644 |
|
Select.py | File | 4.41 KB | 0644 |
|
Split.py | File | 3.11 KB | 0644 |
|
Sub.py | File | 9.49 KB | 0644 |
|
SubNeeded.py | File | 5.48 KB | 0644 |
|
SubNotJoin.py | File | 2 KB | 0644 |
|
SubParametersUsed.py | File | 1.4 KB | 0644 |
|
SubUnneeded.py | File | 1.27 KB | 0644 |
|
ToJsonString.py | File | 1.75 KB | 0644 |
|
__init__.py | File | 106 B | 0644 |
|