abstract struct Ameba::Rule::Base
- Ameba::Rule::Base
- Struct
- Value
- Object
Overview
Represents a base of all rules. In other words, all rules inherits from this struct:
struct MyRule < Ameba::Rule::Base
def test(source)
if invalid?(source)
issue_for line, column, "Something wrong."
end
end
private def invalid?(source)
# ...
end
end
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
- Ameba::Config::RuleConfig
Direct Known Subclasses
- Ameba::Rule::Layout::LineLength
- Ameba::Rule::Layout::TrailingBlankLines
- Ameba::Rule::Layout::TrailingWhitespace
- Ameba::Rule::Lint::ComparisonToBoolean
- Ameba::Rule::Lint::DebuggerStatement
- Ameba::Rule::Lint::EmptyEnsure
- Ameba::Rule::Lint::EmptyExpression
- Ameba::Rule::Lint::HashDuplicatedKey
- Ameba::Rule::Lint::LiteralInCondition
- Ameba::Rule::Lint::LiteralInInterpolation
- Ameba::Rule::Lint::PercentArrays
- Ameba::Rule::Lint::RandZero
- Ameba::Rule::Lint::ShadowedArgument
- Ameba::Rule::Lint::ShadowedException
- Ameba::Rule::Lint::ShadowingOuterLocalVar
- Ameba::Rule::Lint::Syntax
- Ameba::Rule::Lint::UnneededDisableDirective
- Ameba::Rule::Lint::UnreachableCode
- Ameba::Rule::Lint::UnusedArgument
- Ameba::Rule::Lint::UselessAssign
- Ameba::Rule::Lint::UselessConditionInWhen
- Ameba::Rule::Metrics::CyclomaticComplexity
- Ameba::Rule::Performance::AnyAfterFilter
- Ameba::Rule::Performance::FirstLastAfterFilter
- Ameba::Rule::Performance::SizeAfterFilter
- Ameba::Rule::Style::ConstantNames
- Ameba::Rule::Style::LargeNumbers
- Ameba::Rule::Style::MethodNames
- Ameba::Rule::Style::NegatedConditionsInUnless
- Ameba::Rule::Style::PredicateName
- Ameba::Rule::Style::RedundantBegin
- Ameba::Rule::Style::RedundantReturn
- Ameba::Rule::Style::TypeNames
- Ameba::Rule::Style::UnlessElse
- Ameba::Rule::Style::VariableNames
- Ameba::Rule::Style::WhileTrue
Defined in:
ameba/rule/base.crConstructors
Class Method Summary
-
.parsed_doc
Returns documentation for this rule if any.
Instance Method Summary
-
#catch(source : Source)
A convenient addition to
#test
method that does the same but returns a passed insource
as an addition. -
#excluded?(source)
Checks whether the source is excluded from this rule.
-
#group
Returns a group this rule belong to.
- #initialize
-
#name
Returns a name of this rule, which is basically a class name.
-
#special?
Returns true if this rule is special and behaves differently than usual rules.
- #test(source : Source, node : Crystal::ASTNode, *opts)
-
#test(source : Source)
This method is designed to test the source passed in.
Macro Summary
Constructor Detail
Class Method Detail
Returns documentation for this rule if any.
module Ameba
# This is a test rule.
# Does nothing.
struct MyRule < Ameba::Rule::Base
def test(source)
end
end
end
MyRule.parsed_doc # => "This is a test rule.\nDoes nothing."
Instance Method Detail
A convenient addition to #test
method that does the same
but returns a passed in source
as an addition.
source = MyRule.new.catch(source)
source.valid?
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
Returns a group this rule belong to.
struct MyGroup::MyRule < Ameba::Rule::Base
# ...
end
MyGroup::MyRule.new.group # => "MyGroup"
Returns a name of this rule, which is basically a class name.
struct MyRule < Ameba::Rule::Base
def test(source)
end
end
MyRule.new.name # => "MyRule"
Returns true if this rule is special and behaves differently than usual rules.
my_rule.special? # => true or false
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.