+

+ + class Ameba::Rule::Lint::NotNilAfterNoBang + +

+ + + + + + + +

+ + + + Overview +

+ +

This rule is used to identify usage of index/find calls followed by not_nil!.

+

For example, this is considered a code smell:

+
%w[Alice Bob].find(&.match(/^A./)).not_nil!
+

And can be written as this:

+
%w[Alice Bob].find!(&.match(/^A./))
+

YAML configuration example:

+
Lint/NotNilAfterNoBang:
+  Enabled: true
+ + + + + +

+ + + + Included Modules +

+
    + +
  • Ameba::AST::Util
  • + +
  • YAML::Serializable
  • + +
  • YAML::Serializable::Strict
  • + +
+ + + + + + + + + + +

+ + + + Defined in: +

+ + + + ameba/rule/lint/not_nil_after_no_bang.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ BLOCK_CALL_NAMES = ["index", "find"] of ::String +
+ + +
+ CALL_NAMES = ["index"] of ::String +
+ + +
+ MSG = "Use `%s! {...}` instead of `%s {...}.not_nil!`" +
+ + +
+ NOT_NIL_NAME = "not_nil!" +
+ + +
+ + + +

+ + + + 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 usage of index/find calls followed by not_nil!.

+

For example, this is considered a code smell:

+
%w[Alice Bob].find(&.match(/^A./)).not_nil!
+

And can be written as this:

+
%w[Alice Bob].find!(&.match(/^A./))
+

YAML configuration example:

+
Lint/NotNilAfterNoBang:
+  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] + +
+
+ +
+
+ + def test(source) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +