Ameba::Rule::Style::Elsif
Inherits YAML::Serializable < Ameba::Rule::Base < Ameba::Config::RuleConfig < Reference < Object
A rule that encourages the use of case/when syntax over if/elsif.
For example, this is considered invalid:
if foo
do_something_foo
elsif bar
do_something_bar
end
And should be replaced by the following:
case
when foo
do_something_foo
when bar
do_something_bar
end
If IgnoreSuffix option is set to true (which is the default),
the suffix if nodes will be ignored, i.e., considered valid.
if foo
do_something
else
do_something_else if bar # <- suffix if node
end
YAML configuration example:
Style/Elsif:
Enabled: true
IgnoreSuffix: true
MaxBranches: 0
Constants
Constructors
A rule that encourages the use of case/when syntax over if/elsif.
For example, this is considered invalid:
if foo
do_something_foo
elsif bar
do_something_bar
end
And should be replaced by the following:
case
when foo
do_something_foo
when bar
do_something_bar
end
If IgnoreSuffix option is set to true (which is the default),
the suffix if nodes will be ignored, i.e., considered valid.
if foo
do_something
else
do_something_else if bar # <- suffix if node
end
YAML configuration example:
Style/Elsif:
Enabled: true
IgnoreSuffix: true
MaxBranches: 0
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."