Ameba::Rule::Lint::DuplicateBranch
Inherits Ameba::AST::Util < YAML::Serializable < Ameba::Rule::Base < Ameba::Config::RuleConfig < Reference < Object
Checks that there are no repeated bodies within if/unless,
case-when, case-in and rescue constructs.
This is considered invalid:
if foo
do_foo
do_something_else
elsif bar
do_foo
do_something_else
end
And this is valid:
if foo || bar
do_foo
do_something_else
end
With IgnoreLiteralBranches: true, branches are not registered
as offenses if they return a basic literal value (string, symbol,
integer, float, true, false, or nil), or return an array,
hash, regexp or range that only contains one of the above basic
literal values.
With IgnoreConstantBranches: true, branches are not registered
as offenses if they return a constant value.
With IgnoreDuplicateElseBranch: true, in conditionals with multiple branches,
duplicate 'else' branches are not registered as offenses.
YAML configuration example:
Lint/DuplicateBranch:
Enabled: true
IgnoreLiteralBranches: false
IgnoreConstantBranches: false
IgnoreDuplicateElseBranch: false
Constants
Constructors
Checks that there are no repeated bodies within if/unless,
case-when, case-in and rescue constructs.
This is considered invalid:
if foo
do_foo
do_something_else
elsif bar
do_foo
do_something_else
end
And this is valid:
if foo || bar
do_foo
do_something_else
end
With IgnoreLiteralBranches: true, branches are not registered
as offenses if they return a basic literal value (string, symbol,
integer, float, true, false, or nil), or return an array,
hash, regexp or range that only contains one of the above basic
literal values.
With IgnoreConstantBranches: true, branches are not registered
as offenses if they return a constant value.
With IgnoreDuplicateElseBranch: true, in conditionals with multiple branches,
duplicate 'else' branches are not registered as offenses.
YAML configuration example:
Lint/DuplicateBranch:
Enabled: true
IgnoreLiteralBranches: false
IgnoreConstantBranches: false
IgnoreDuplicateElseBranch: false
Class methods
Returns true if this rule is deprecated, false otherwise.
Returns the deprecation reason for this rule, if there is any.
Returns the documentation URL for this rule.
Ameba::Rule::Lint::Syntax.documentation_url
# => "https://crystal-ameba.org/api/master/Ameba/Rule/Lint/Syntax.html"
Returns the documentation for this rule, if there is any.
module Ameba
# This is a test rule.
# Does nothing.
class Rule::MyRule < Rule::Base
def test(source)
end
end
end
Ameba::Rule::MyRule.parsed_doc # => "This is a test rule.\nDoes nothing."