+

+ + class Ameba::Rule::Lint::LiteralAssignmentsInExpressions + +

+ + + + + + + +

+ + + + Overview +

+ +

A rule that disallows assignments with literal values +in control expressions.

+

For example, this is considered invalid:

+
if foo = 42
+  do_something
+end
+

And most likely should be replaced by the following:

+
if foo == 42
+  do_something
+end
+

YAML configuration example:

+
Lint/LiteralAssignmentsInExpressions:
+  Enabled: true
+ + + + + +

+ + + + Included Modules +

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

+ + + + Defined in: +

+ + + + ameba/rule/lint/literal_assignments_in_expressions.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ MSG = "Detected assignment with a literal value in control expression" +
+ + +
+ + + +

+ + + + Constructors +

+ + + + +

+ + + + Class Method Summary +

+ + + + +

+ + + + Instance Method Summary +

+ + + + + + + + + +

+ + + + Constructor Detail +

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

A rule that disallows assignments with literal values +in control expressions.

+

For example, this is considered invalid:

+
if foo = 42
+  do_something
+end
+

And most likely should be replaced by the following:

+
if foo == 42
+  do_something
+end
+

YAML configuration example:

+
Lint/LiteralAssignmentsInExpressions:
+  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::If | Crystal::Unless | Crystal::Case | Crystal::While | Crystal::Until) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +