diff --git a/src/cfnlint/rules/conditions/EqualsIsUseful.py b/src/cfnlint/rules/conditions/EqualsIsUseful.py index ee74cf0247..181ecc5be5 100644 --- a/src/cfnlint/rules/conditions/EqualsIsUseful.py +++ b/src/cfnlint/rules/conditions/EqualsIsUseful.py @@ -50,8 +50,16 @@ def equals_is_useful(self, validator, s, instance, schema): first = "true" if first else "false" if str(first) == str(second): yield ValidationError( - f"{instance!r} will always return {True!r} or {False!r}", + f"{instance!r} will always return {True!r}", rule=self, ) + if isinstance(instance[0], (str, float, int, bool)) and isinstance( + instance[1], (str, float, int, bool) + ): + if str(first) != str(second): + yield ValidationError( + f"{instance!r} will always return {False!r}", + rule=self, + ) except: # noqa: E722 pass diff --git a/test/unit/rules/conditions/test_equals_is_useful.py b/test/unit/rules/conditions/test_equals_is_useful.py index 7db7ffa116..421c3d62ea 100644 --- a/test/unit/rules/conditions/test_equals_is_useful.py +++ b/test/unit/rules/conditions/test_equals_is_useful.py @@ -15,10 +15,12 @@ ("Equal string and integer", [1, "1"], 1), ("Equal string and boolean", [True, "true"], 1), ("Equal string and number", [1.0, "1.0"], 1), - ("Not equal string and integer", [1, "1.1"], 0), - ("Not equal string and boolean", [True, "True"], 0), + ("Not equal string and integer", [1, "1.1"], 1), + ("Not equal string and boolean", [True, "True"], 1), ("No error on bad type", {"true": True}, 0), ("No error on bad length", ["a", "a", "a"], 0), + ("No with string and account id", ["A", {"Ref": "AWS::AccountId"}], 0), + ("No with string and account id", [{"Ref": "AWS::AccountId"}, "A"], 0), ], ) def test_names(name, instance, num_of_errors): @@ -26,4 +28,4 @@ def test_names(name, instance, num_of_errors): validator = CfnTemplateValidator({}) assert ( len(list(rule.equals_is_useful(validator, {}, instance, {}))) == num_of_errors - ), f"Expected {num_of_errors} errors for {name}" + ), f"Expected {num_of_errors} errors for {name} and {instance}"