- class Ameba::Rule::Lint::StaticComparison + class Ameba::Rule::Lint::LiteralsComparison

- + @@ -749,12 +749,13 @@ Overview -

This rule is used to identify static comparisons - -the ones that will always have the same result.

+

This rule is used to identify comparisons between two literals.

+

They usually have the same result - except for non-primitive +types like containers, range or regex.

For example, this will be always false:

"foo" == 42

YAML configuration example:

-
Lint/StaticComparison:
+
Lint/LiteralsComparison:
   Enabled: true
@@ -798,8 +799,8 @@ the ones that will always have the same result.

- - ameba/rule/lint/static_comparison.cr + + ameba/rule/lint/literals_comparison.cr
@@ -819,18 +820,33 @@ the ones that will always have the same result.

+
+ DYNAMIC_LITERAL_TYPES = {Crystal::RangeLiteral, Crystal::RegexLiteral, Crystal::TupleLiteral, Crystal::NamedTupleLiteral, Crystal::ArrayLiteral, Crystal::HashLiteral} +
+ + +
+ LITERAL_TYPES = PRIMITIVE_LITERAL_TYPES + DYNAMIC_LITERAL_TYPES +
+ +
MSG = "Comparison always evaluates to %s"
+
+ MSG_LIKELY = "Comparison most likely evaluates to %s" +
+ +
OP_NAMES = ["===", "==", "!="] of ::String
-
- PRIMITIVES = {Crystal::NilLiteral, Crystal::BoolLiteral, Crystal::NumberLiteral, Crystal::CharLiteral, Crystal::StringLiteral, Crystal::SymbolLiteral, Crystal::RangeLiteral, Crystal::RegexLiteral, Crystal::TupleLiteral, Crystal::NamedTupleLiteral, Crystal::ArrayLiteral, Crystal::HashLiteral, Crystal::ProcLiteral} +
+ PRIMITIVE_LITERAL_TYPES = {Crystal::NilLiteral, Crystal::BoolLiteral, Crystal::NumberLiteral, Crystal::CharLiteral, Crystal::StringLiteral, Crystal::SymbolLiteral, Crystal::ProcLiteral, Crystal::Path}
@@ -856,7 +872,7 @@ the ones that will always have the same result.

  • .new(config = nil) -

    This rule is used to identify static comparisons - the ones that will always have the same result.

    +

    This rule is used to identify comparisons between two literals.

  • @@ -1167,19 +1183,20 @@ the ones that will always have the same result.

    -

    This rule is used to identify static comparisons - -the ones that will always have the same result.

    +

    This rule is used to identify comparisons between two literals.

    +

    They usually have the same result - except for non-primitive +types like containers, range or regex.

    For example, this will be always false:

    "foo" == 42

    YAML configuration example:

    -
    Lint/StaticComparison:
    +
    Lint/LiteralsComparison:
       Enabled: true