+

+ + class Ameba::Rule::Lint::StaticComparison + +

+ + + + + + + +

+ + + + Overview +

+ +

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

+

For example, this will be always false:

+
"foo" == 42
+

YAML configuration example:

+
Lint/StaticComparison:
+  Enabled: true
+ + + + + +

+ + + + Included Modules +

+ + + + + + + + + + + +

+ + + + Defined in: +

+ + + + ameba/rule/lint/static_comparison.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ MSG = "Comparison always 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} +
+ + +
+ + + +

+ + + + Constructors +

+ + + + +

+ + + + Class Method Summary +

+ + + + +

+ + + + Instance Method Summary +

+ + + + + + + + + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) + + # +
+ +
+
+ +
+
+ +
+
+ + def self.new(config = nil) + + # +
+ +
+ +

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

+

For example, this will be always false:

+
"foo" == 42
+

YAML configuration example:

+
Lint/StaticComparison:
+  Enabled: true
+
+ +
+
+ + [View source] + +
+
+ + + + +

+ + + + Class Method Detail +

+ +
+
+ + def self.parsed_doc : String? + + # +
+ +
+ +

Returns documentation for this rule, if there is any.

+
module Ameba
+  # This is a test rule.
+  # Does nothing.
+  class MyRule < Ameba::Rule::Base
+    def test(source)
+    end
+  end
+end
+
+MyRule.parsed_doc # => "This is a test rule.\nDoes nothing."
+
+ +
+
+ +
+
+ + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def description : String + + # +
+ +
+
+ +
+
+ +
+
+ + def description=(description : String) + + # +
+ +
+
+ +
+
+ +
+
+ + def enabled : Bool + + # +
+ +
+
+ +
+
+ +
+
+ + def enabled=(enabled : Bool) + + # +
+ +
+
+ +
+
+ +
+
+ + def excluded : Array(String)? + + # +
+ +
+
+ +
+
+ +
+
+ + def excluded=(excluded : Array(String)?) + + # +
+ +
+
+ +
+
+ +
+
+ + def severity : Ameba::Severity + + # +
+ +
+
+ +
+
+ +
+
+ + def severity=(severity : Ameba::Severity) + + # +
+ +
+
+ +
+
+ +
+
+ + def test(source, node : Crystal::Call) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +