+

+ + class Ameba::Rule::Naming::AccessorMethodName + +

+ + + + + + + +

+ + + + Overview +

+ +

A rule that makes sure that accessor methods are named properly.

+

Favour this:

+
class Foo
+  def user
+    @user
+  end
+
+  def user=(value)
+    @user = value
+  end
+end
+

Over this:

+
class Foo
+  def get_user
+    @user
+  end
+
+  def set_user(value)
+    @user = value
+  end
+end
+

YAML configuration example:

+
Naming/AccessorMethodName:
+  Enabled: true
+ + + + + +

+ + + + Included Modules +

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

+ + + + Defined in: +

+ + + + ameba/rule/naming/accessor_method_name.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ MSG = "Favour method name '%s' over '%s'" +
+ + +
+ + + +

+ + + + 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 makes sure that accessor methods are named properly.

+

Favour this:

+
class Foo
+  def user
+    @user
+  end
+
+  def user=(value)
+    @user = value
+  end
+end
+

Over this:

+
class Foo
+  def get_user
+    @user
+  end
+
+  def set_user(value)
+    @user = value
+  end
+end
+

YAML configuration example:

+
Naming/AccessorMethodName:
+  Enabled: true
+
+ +
+
+ + [View source] + +
+
+ + + + +

+ + + + Class Method Detail +

+ +
+
+ + def self.parsed_doc : String | Nil + + # +
+ +
+ +

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=(enabled : Bool) + + # +
+ +
+
+ +
+
+ +
+
+ + def enabled? : Bool + + # +
+ +
+
+ +
+
+ +
+
+ + def excluded : Array(String) | Nil + + # +
+ +
+
+ +
+
+ +
+
+ + def excluded=(excluded : Array(String) | Nil) + + # +
+ +
+
+ +
+
+ +
+
+ + def severity : Ameba::Severity + + # +
+ +
+
+ +
+
+ +
+
+ + def severity=(severity : Ameba::Severity) + + # +
+ +
+
+ +
+
+ +
+
+ + def test(source, node : Crystal::ClassDef | Crystal::ModuleDef) + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def test(source, node : Crystal::Def) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +