abstract class Ameba::Rule::Base


Represents a base of all rules. In other words, all rules inherits from this struct:

class MyRule < Ameba::Rule::Base
  def test(source)
    if invalid?(source)
      issue_for line, column, "Something wrong."

  private def invalid?(source)
    # ...

Enforces rules to implement an abstract #test method which is designed to test the source passed in. If source has issues that are tested by this rule, it should add an issue.

Included Modules

Direct Known Subclasses

Defined in:


Constant Summary

GROUP_SEVERITY = {Documentation: Ameba::Severity::Warning, Lint: Ameba::Severity::Warning, Metrics: Ameba::Severity::Warning, Performance: Ameba::Severity::Warning}

Class Method Summary

Macro Summary

Instance Method Summary

Macros inherited from module Ameba::Config::RuleConfig

properties(&block) properties

Class Method Detail

def self.default_severity : Ameba::Severity #

Macro Detail

macro issue_for(*args, **kwargs, &block) #

Adds an issue to the source

[View source]

Instance Method Detail

def ==(other) #
Description copied from class Reference

Returns false (other can only be a Value here).

[View source]
def catch(source : Source) #

A convenient addition to #test method that does the same but returns a passed in source as an addition.

source = MyRule.new.catch(source)

[View source]
def excluded?(source) #

Checks whether the source is excluded from this rule. It searches for a path in excluded property which matches the one of the given source.

my_rule.excluded?(source) # => true or false

[View source]
def group #

Returns a group this rule belong to.

class MyGroup::MyRule < Ameba::Rule::Base
  # ...

MyGroup::MyRule.new.group # => "MyGroup"

[View source]
def hash #
Description copied from class Object

Generates an UInt64 hash value for this object.

This method must have the property that a == b implies a.hash == b.hash.

The hash value is used along with #== by the Hash class to determine if two objects reference the same hash key.

Subclasses must not override this method. Instead, they must define hash(hasher), though usually the macro def_hash can be used to generate this method.

[View source]
def name #

Returns a name of this rule, which is basically a class name.

class MyRule < Ameba::Rule::Base
  def test(source)

MyRule.new.name # => "MyRule"

[View source]
def special? #

Returns true if this rule is special and behaves differently than usual rules.

my_rule.special? # => true or false

[View source]
def test(source : Source, node : Crystal::ASTNode, *opts) #

NOTE Can't be abstract

[View source]
def test(source : Source) #

This method is designed to test the source passed in. If source has issues that are tested by this rule, it should add an issue.

By default it uses a node visitor to traverse all the nodes in the source.

NOTE Must be overridden for other type of rules.

[View source]