Represents the argument of some node.
Holds the reference to the variable, thus to scope.
-
For example, all these vars are arguments:
-
defmethod(a, b, c =10, &block)
3.times do|i|end
@@ -674,7 +677,7 @@ Holds the reference to the variable, thus to scope.
-
+
ameba/ast/variabling/argument.cr
@@ -696,7 +699,7 @@ Holds the reference to the variable, thus to scope.
Represents the branch in Crystal code.
Branch is a part of a branchable statement.
For example, the branchable if statement contains 3 branches:
-
if a = something # --> Branch A
a =1# --> Branch B
put a ifout# --> Branch C
@@ -673,7 +677,7 @@ For example, the branchable if statement contains 3 branches:
-
+
ameba/ast/branch.cr
@@ -695,7 +699,7 @@ For example, the branchable if statement contains 3 branches:
A generic entity to represent a branchable Crystal node.
For example, Crystal::If, Crystal::Unless, Crystal::While
are branchables.
-
white a >100# Branchable Aif b >2# Branchable B
a += 1
@@ -686,7 +690,7 @@ are branchables.
-
+
ameba/ast/branchable.cr
@@ -708,7 +712,7 @@ are branchables.
Represents a flow expression in Crystal code.
For example,
-
deffoobar
a =3return42# => flow expression
a +1end
-
Flow expression contains an actual node of a control expression and
a parent node, which allows easily search through the related statement
(i.e. find unreachable code)
@@ -689,7 +692,7 @@ a parent node, which allows easily search through the related statement
-
+
ameba/ast/flow_expression.cr
@@ -711,7 +714,7 @@ a parent node, which allows easily search through the related statement
BadDirective
@@ -665,7 +670,7 @@ This is where the local variables belong to.
-
+
ameba/ast/scope.cr
@@ -687,7 +692,7 @@ This is where the local variables belong to.
Returns a list of paths (with wildcards) to files.
Represents a list of sources to be inspected.
If globs are not set, it will return default list of files.
Returns a list of paths (with wildcards) to files.
Represents a list of sources to be inspected.
If globs are not set, it will return default list of files.
Returns a list of sources matching globs and excluded sections.
-
config =Ameba::Config.load
config.sources # => list of default sources
config.globs = ["**/*.cr"]
@@ -1215,7 +1208,7 @@ config.sources # => list of sources pointing to files found b
Creates a new instance of ExplainFormatter.
Accepts output which indicates the io where the explanation will be wrtitten to.
Second argument is location which indicates the location to explain.
Represents a base of all rules. In other words, all rules
inherits from this struct:
-
classMyRule<Ameba::Rule::Basedeftest(source)
if invalid?(source)
@@ -653,8 +657,7 @@ inherits from this struct:
# ...endend
-
-
Enforces rules to implement an abstract #test method which
+
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.
@@ -696,6 +699,8 @@ that are tested by this rule, it should add an issue.
@@ -799,7 +804,7 @@ that are tested by this rule, it should add an issue.
-
+
ameba/rule/base.cr
@@ -844,21 +849,21 @@ that are tested by this rule, it should add an issue.
@@ -1134,12 +1135,9 @@ the one of the given source.
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
+
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.
@@ -1147,7 +1145,7 @@ though usually the macro def_hash can be used to generate this meth
A rule that reports incorrect comment directives for Ameba.
-
For example, the user can mistakenly add a directive
to disable a rule that even doesn't exist:
-
# ameba:disable BadRuleNamedeffoo:barend
-
YAML configuration example:
-
Lint/BadDirective:
Enabled: true
@@ -693,7 +694,7 @@ to disable a rule that even doesn't exist:
-
+
ameba/rule/lint/bad_directive.cr
@@ -744,12 +745,12 @@ to disable a rule that even doesn't exist:
@@ -1016,7 +1013,7 @@ to disable a rule that even doesn't exist:
def description : String
- #
+ #
@@ -1030,7 +1027,7 @@ to disable a rule that even doesn't exist:
def description=(description : String)
- #
+ #
@@ -1044,7 +1041,7 @@ to disable a rule that even doesn't exist:
def enabled : Bool
- #
+ #
@@ -1058,7 +1055,7 @@ to disable a rule that even doesn't exist:
def enabled=(enabled)
- #
+ #
@@ -1072,7 +1069,7 @@ to disable a rule that even doesn't exist:
def excluded : Array(String)?
- #
+ #
@@ -1086,7 +1083,7 @@ to disable a rule that even doesn't exist:
def excluded=(excluded : Array(String)?)
- #
+ #
@@ -1100,7 +1097,7 @@ to disable a rule that even doesn't exist:
def severity : Ameba::Severity
- #
+ #
@@ -1114,7 +1111,7 @@ to disable a rule that even doesn't exist:
def severity=(severity)
- #
+ #
@@ -1128,13 +1125,13 @@ to disable a rule that even doesn't exist:
def test(source)
- #
+ #
This is because these expressions evaluate to true or false, so you
could get the same result by using either the variable directly,
or negating the variable.
This is because these expressions evaluate to true or false, so you
could get the same result by using either the variable directly,
or negating the variable.
A rule that disallows useless conditional statements that contain a literal
in place of a variable or predicate function.
-
This is because a conditional construct with a literal predicate will
always result in the same behaviour at run time, meaning it can be
replaced with either the body of the construct, or deleted entirely.
-
This is considered invalid:
-
if"something":okend
-
YAML configuration example:
-
Lint/LiteralInCondition:
Enabled: true
@@ -698,7 +698,7 @@ replaced with either the body of the construct, or deleted entirely.
-
+
ameba/rule/lint/literal_in_condition.cr
@@ -739,12 +739,12 @@ replaced with either the body of the construct, or deleted entirely.
A rule that disallows useless conditional statements that contain a literal
in place of a variable or predicate function.
-
This is because a conditional construct with a literal predicate will
always result in the same behaviour at run time, meaning it can be
replaced with either the body of the construct, or deleted entirely.
-
This is considered invalid:
-
if"something":okend
-
YAML configuration example:
-
Lint/LiteralInCondition:
Enabled: true
@@ -1059,7 +1059,7 @@ replaced with either the body of the construct, or deleted entirely.
@@ -1099,7 +1099,7 @@ replaced with either the body of the construct, or deleted entirely.
def description : String
- #
+ #
@@ -1113,7 +1113,7 @@ replaced with either the body of the construct, or deleted entirely.
def description=(description : String)
- #
+ #
@@ -1127,7 +1127,7 @@ replaced with either the body of the construct, or deleted entirely.
def enabled : Bool
- #
+ #
@@ -1141,7 +1141,7 @@ replaced with either the body of the construct, or deleted entirely.
def enabled=(enabled)
- #
+ #
@@ -1155,7 +1155,7 @@ replaced with either the body of the construct, or deleted entirely.
def excluded : Array(String)?
- #
+ #
@@ -1169,7 +1169,7 @@ replaced with either the body of the construct, or deleted entirely.
def excluded=(excluded : Array(String)?)
- #
+ #
@@ -1183,7 +1183,7 @@ replaced with either the body of the construct, or deleted entirely.
def severity : Ameba::Severity
- #
+ #
@@ -1197,7 +1197,7 @@ replaced with either the body of the construct, or deleted entirely.
def severity=(severity)
- #
+ #
@@ -1211,13 +1211,13 @@ replaced with either the body of the construct, or deleted entirely.
def test(source, node : Crystal::If)
- #
+ #
A rule that disallows useless string interpolations
that contain a literal value instead of a variable or function.
-
For example:
-
"Hello, #{:Ary}""There are #{4} cats"
-
YAML configuration example:
-
Lint/LiteralInInterpolation
Enabled: true
@@ -693,7 +694,7 @@ that contain a literal value instead of a variable or function.
-
+
ameba/rule/lint/literal_in_interpolation.cr
@@ -734,12 +735,12 @@ that contain a literal value instead of a variable or function.
@@ -1058,7 +1060,7 @@ that contain a literal value instead of a variable or function.
def description : String
- #
+ #
@@ -1072,7 +1074,7 @@ that contain a literal value instead of a variable or function.
def description=(description : String)
- #
+ #
@@ -1086,7 +1088,7 @@ that contain a literal value instead of a variable or function.
def enabled : Bool
- #
+ #
@@ -1100,7 +1102,7 @@ that contain a literal value instead of a variable or function.
def enabled=(enabled)
- #
+ #
@@ -1114,7 +1116,7 @@ that contain a literal value instead of a variable or function.
def excluded : Array(String)?
- #
+ #
@@ -1128,7 +1130,7 @@ that contain a literal value instead of a variable or function.
def excluded=(excluded : Array(String)?)
- #
+ #
@@ -1142,7 +1144,7 @@ that contain a literal value instead of a variable or function.
def severity : Ameba::Severity
- #
+ #
@@ -1156,7 +1158,7 @@ that contain a literal value instead of a variable or function.
def severity=(severity)
- #
+ #
@@ -1170,13 +1172,13 @@ that contain a literal value instead of a variable or function.
def test(source, node : Crystal::StringInterpolation)
- #
+ #
This rule is able to find the shared variables between fibers, which are mutated
during iterations. So it reports the issue on the first sample and passes on
the second one.
-
There are also other technics to solve the problem above which are
officially documented
This rule is able to find the shared variables between fibers, which are mutated
during iterations. So it reports the issue on the first sample and passes on
the second one.
-
There are also other technics to solve the problem above which are
officially documented
In specs focus: true is mainly used to focus on a spec
item locally during development. However, if such change
is committed, it silently runs only focused spec on all
other environment, which is undesired.
-
This is considered bad:
-
describe MyClass, focus: truedoend
@@ -659,9 +661,7 @@ context "my context", focus: tr
it "works", focus: truedoend
-
And it should be written as the following:
-
describe MyClassdoend
@@ -673,9 +673,7 @@ context "my context"do
it "works"doend
In specs focus: true is mainly used to focus on a spec
item locally during development. However, if such change
is committed, it silently runs only focused spec on all
other environment, which is undesired.
-
This is considered bad:
-
describe MyClass, focus: truedoend
@@ -1018,9 +1013,7 @@ context "my context", focus: tr
it "works", focus: truedoend
-
And it should be written as the following:
-
describe MyClassdoend
@@ -1032,9 +1025,7 @@ context "my context"do
it "works"doend
A rule that reports unneeded disable directives.
For example, this is considered invalid:
-
# ameba:disable Style/PredicateNamedefcomment?
do_something
end
-
as the predicate name is correct and the comment directive does not
have any effect, the snippet should be written as the following:
-
defcomment?
do_something
end
-
YAML configuration example:
-
Lint/UnneededDisableDirective
Enabled: true
@@ -698,7 +698,7 @@ have any effect, the snippet should be written as the following:
-
+
ameba/rule/lint/unneeded_disable_directive.cr
@@ -739,12 +739,12 @@ have any effect, the snippet should be written as the following:
@@ -1016,7 +1011,7 @@ have any effect, the snippet should be written as the following:
def description : String
- #
+ #
@@ -1030,7 +1025,7 @@ have any effect, the snippet should be written as the following:
def description=(description : String)
- #
+ #
@@ -1044,7 +1039,7 @@ have any effect, the snippet should be written as the following:
def enabled : Bool
- #
+ #
@@ -1058,7 +1053,7 @@ have any effect, the snippet should be written as the following:
def enabled=(enabled)
- #
+ #
@@ -1072,7 +1067,7 @@ have any effect, the snippet should be written as the following:
def excluded : Array(String)?
- #
+ #
@@ -1086,7 +1081,7 @@ have any effect, the snippet should be written as the following:
def excluded=(excluded : Array(String)?)
- #
+ #
@@ -1100,7 +1095,7 @@ have any effect, the snippet should be written as the following:
def severity : Ameba::Severity
- #
+ #
@@ -1114,7 +1109,7 @@ have any effect, the snippet should be written as the following:
def severity=(severity)
- #
+ #
@@ -1128,13 +1123,13 @@ have any effect, the snippet should be written as the following:
def test(source)
- #
+ #
A rule that reports unused arguments.
For example, this is considered invalid:
-
defmethod(a, b, c)
a + b
end
-
and should be written as:
-
defmethod(a, b)
a + b
end
-
YAML configuration example:
-
Lint/UnusedArgument:
Enabled: true
IgnoreDefs: true
@@ -699,7 +699,7 @@ For example, this is considered invalid:
-
+
ameba/rule/lint/unused_argument.cr
@@ -740,12 +740,12 @@ For example, this is considered invalid:
@@ -1063,7 +1058,7 @@ For example, this is considered invalid:
def description : String
- #
+ #
@@ -1077,7 +1072,7 @@ For example, this is considered invalid:
def description=(description : String)
- #
+ #
@@ -1091,7 +1086,7 @@ For example, this is considered invalid:
def enabled : Bool
- #
+ #
@@ -1105,7 +1100,7 @@ For example, this is considered invalid:
def enabled=(enabled)
- #
+ #
@@ -1119,7 +1114,7 @@ For example, this is considered invalid:
def excluded : Array(String)?
- #
+ #
@@ -1133,7 +1128,7 @@ For example, this is considered invalid:
def excluded=(excluded : Array(String)?)
- #
+ #
@@ -1147,7 +1142,7 @@ For example, this is considered invalid:
def ignore_blocks : Bool
- #
+ #
@@ -1161,7 +1156,7 @@ For example, this is considered invalid:
def ignore_blocks=(ignore_blocks : Bool)
- #
+ #
@@ -1175,7 +1170,7 @@ For example, this is considered invalid:
def ignore_defs : Bool
- #
+ #
@@ -1189,7 +1184,7 @@ For example, this is considered invalid:
def ignore_defs=(ignore_defs : Bool)
- #
+ #
@@ -1203,7 +1198,7 @@ For example, this is considered invalid:
def ignore_procs : Bool
- #
+ #
@@ -1217,7 +1212,7 @@ For example, this is considered invalid:
def ignore_procs=(ignore_procs : Bool)
- #
+ #
@@ -1231,7 +1226,7 @@ For example, this is considered invalid:
def severity : Ameba::Severity
- #
+ #
@@ -1245,7 +1240,7 @@ For example, this is considered invalid:
def severity=(severity)
- #
+ #
@@ -1259,13 +1254,13 @@ For example, this is considered invalid:
def test(source, node : Crystal::ProcLiteral, scope : AST::Scope)
- #
+ #
A rule that disallows useless conditions in when clause
where it is guaranteed to always return the same result.
-
For example, this is considered invalid:
-
casewhen utc?
io <<" UTC"when local?
Format.new(" %:z").format(self, io) if local?
end
-
And has to be written as the following:
-
casewhen utc?
io <<" UTC"when local?
Format.new(" %:z").format(self, io)
end
-
YAML configuration example:
-
Lint/UselessConditionInWhen:
Enabled: true
@@ -704,7 +703,7 @@ where it is guaranteed to always return the same result.
-
+
ameba/rule/lint/useless_condition_in_when.cr
@@ -745,12 +744,12 @@ where it is guaranteed to always return the same result.
@@ -1028,7 +1021,7 @@ where it is guaranteed to always return the same result.
def description : String
- #
+ #
@@ -1042,7 +1035,7 @@ where it is guaranteed to always return the same result.
def description=(description : String)
- #
+ #
@@ -1056,7 +1049,7 @@ where it is guaranteed to always return the same result.
def enabled : Bool
- #
+ #
@@ -1070,7 +1063,7 @@ where it is guaranteed to always return the same result.
def enabled=(enabled)
- #
+ #
@@ -1084,7 +1077,7 @@ where it is guaranteed to always return the same result.
def excluded : Array(String)?
- #
+ #
@@ -1098,7 +1091,7 @@ where it is guaranteed to always return the same result.
def excluded=(excluded : Array(String)?)
- #
+ #
@@ -1112,7 +1105,7 @@ where it is guaranteed to always return the same result.
def severity : Ameba::Severity
- #
+ #
@@ -1126,7 +1119,7 @@ where it is guaranteed to always return the same result.
def severity=(severity)
- #
+ #
@@ -1140,13 +1133,13 @@ where it is guaranteed to always return the same result.
def test(source, node : Crystal::When)
- #
+ #
This rule is used to identify usage of arg-less Enumerable#any? calls.
-
Using Enumerable#any? instead of Enumerable#empty? might lead to an
unexpected results (like [nil, false].any? # => false). In some cases
it also might be less efficient, since it iterates until the block will
return a truthy value, instead of just checking if there's at least
one value present.
This rule is used to identify usage of arg-less Enumerable#any? calls.
-
Using Enumerable#any? instead of Enumerable#empty? might lead to an
unexpected results (like [nil, false].any? # => false). In some cases
it also might be less efficient, since it iterates until the block will
return a truthy value, instead of just checking if there's at least
one value present.
-
For example, this is considered invalid:
-
[1, 2, 3].any?
-
And it should be written as this:
-
![1, 2, 3].empty?
-
YAML configuration example:
-
Performance/AnyInsteadOfEmpty:
Enabled: true
@@ -1043,29 +1034,22 @@ one value present.
def self.new(config = nil)
- #
+ #
This rule is used to identify usage of arg-less Enumerable#any? calls.
-
Using Enumerable#any? instead of Enumerable#empty? might lead to an
unexpected results (like [nil, false].any? # => false). In some cases
it also might be less efficient, since it iterates until the block will
return a truthy value, instead of just checking if there's at least
one value present.
A rule that disallows usage of large numbers without underscore.
These do not affect the value of the number, but can help read
large numbers more easily.
-
For example, these are considered invalid:
-
100001415926545.12345
-
And has to be rewritten as the following:
-
10_000141_592_6545.123_45
-
YAML configuration example:
-
Style/LargeNumbers:
Enabled: true
IntMinDigits: 5 # i.e. integers higher than 9999
A rule that disallows usage of large numbers without underscore.
These do not affect the value of the number, but can help read
large numbers more easily.
-
For example, these are considered invalid:
-
100001415926545.12345
-
And has to be rewritten as the following:
-
10_000141_592_6545.123_45
-
YAML configuration example:
-
Style/LargeNumbers:
Enabled: true
IntMinDigits: 5 # i.e. integers higher than 9999
@@ -1020,7 +1011,7 @@ that is executed if a negated condition is NOT met.
def description : String
- #
+ #
@@ -1034,7 +1025,7 @@ that is executed if a negated condition is NOT met.
def description=(description : String)
- #
+ #
@@ -1048,7 +1039,7 @@ that is executed if a negated condition is NOT met.
def enabled : Bool
- #
+ #
@@ -1062,7 +1053,7 @@ that is executed if a negated condition is NOT met.
def enabled=(enabled)
- #
+ #
@@ -1076,7 +1067,7 @@ that is executed if a negated condition is NOT met.
def excluded : Array(String)?
- #
+ #
@@ -1090,7 +1081,7 @@ that is executed if a negated condition is NOT met.
def excluded=(excluded : Array(String)?)
- #
+ #
@@ -1104,7 +1095,7 @@ that is executed if a negated condition is NOT met.
def severity : Ameba::Severity
- #
+ #
@@ -1118,7 +1109,7 @@ that is executed if a negated condition is NOT met.
def severity=(severity)
- #
+ #
@@ -1132,13 +1123,13 @@ that is executed if a negated condition is NOT met.
def test(source, node : Crystal::Unless)
- #
+ #
A rule that disallows tautological predicate names, meaning those that
start with the prefix has_ or the prefix is_. Ignores if the alternative isn't valid Crystal code (e.g. is_404?).
-
Favour these:
-
defvalid?(x)
enddefpicture?(x)
end
-
Over these:
-
defis_valid?(x)
enddefhas_picture?(x)
end
-
YAML configuration example:
-
Style/PredicateName:
Enabled: true
@@ -702,7 +701,7 @@ start with the prefix has_ or the prefix is_. Ignores
-
+
ameba/rule/style/predicate_name.cr
@@ -743,12 +742,12 @@ start with the prefix has_ or the prefix is_. Ignores
A rule that disallows tautological predicate names, meaning those that
start with the prefix has_ or the prefix is_. Ignores if the alternative isn't valid Crystal code (e.g. is_404?).
-
Favour these:
-
defvalid?(x)
enddefpicture?(x)
end
-
Over these:
-
defis_valid?(x)
enddefhas_picture?(x)
end
-
YAML configuration example:
-
Style/PredicateName:
Enabled: true
@@ -1000,7 +993,7 @@ start with the prefix has_ or the prefix is_. Ignores
BadDirective
@@ -643,13 +648,10 @@
a block to skip to the next iteration early, however, it is considered
redundant in cases where it is the last expression in a block or combines
into the node which is the last in a block.
-
For example, this is considered invalid:
-
block do|v|next v +1end
-
block do|v|case v
when .nil?
@@ -660,13 +662,10 @@ into the node which is the last in a block.
next"empty"endend
-
And has to be written as the following:
-
block do|v|
v +1end
-
block do|v|case arg
when .nil?
@@ -677,51 +676,42 @@ into the node which is the last in a block.
"empty"endend
-
Configuration params
-
-
allow_multi_next, default: true
-
+
+
allow_multi_next, default: true
+
Allows end-user to configure whether to report or not the next statements
which yield tuple literals i.e.
-
block donext a, b
end
-
If this param equals to false, the block above will be forced to be written as:
-
block do
{a, b}
end
-
-
allow_empty_next, default: true
-
+
+
allow_empty_next, default: true
+
Allows end-user to configure whether to report or not the next statements
without arguments. Sometimes such statements are used to yild the nil value explicitly.
-
block do
@foo =:emptynextend
-
If this param equals to false, the block above will be forced to be written as:
-
block do
@foo =:emptynilend
-
YAML config example
-
Style/RedundantNext:
Enabled: true
AllowMultiNext: true
@@ -766,7 +756,7 @@ without arguments. Sometimes such statements are used to yild the nil
-
+
ameba/rule/style/redundant_next.cr
@@ -807,12 +797,12 @@ without arguments. Sometimes such statements are used to yild the nil
@@ -1065,13 +1055,10 @@ without arguments. Sometimes such statements are used to yild the nil
-
For example, this is considered invalid:
-
block do|v|next v +1end
-
block do|v|case v
when .nil?
@@ -1082,13 +1069,10 @@ into the node which is the last in a block.
next"empty"endend
-
And has to be written as the following:
-
block do|v|
v +1end
-
block do|v|case arg
when .nil?
@@ -1099,51 +1083,42 @@ into the node which is the last in a block.
"empty"endend
-
Configuration params
-
-
allow_multi_next, default: true
-
+
+
allow_multi_next, default: true
+
Allows end-user to configure whether to report or not the next statements
which yield tuple literals i.e.
-
block donext a, b
end
-
If this param equals to false, the block above will be forced to be written as:
-
block do
{a, b}
end
-
-
allow_empty_next, default: true
-
+
+
allow_empty_next, default: true
+
Allows end-user to configure whether to report or not the next statements
without arguments. Sometimes such statements are used to yild the nil value explicitly.
-
block do
@foo =:emptynextend
-
If this param equals to false, the block above will be forced to be written as:
-
block do
@foo =:emptynilend
-
YAML config example
-
Style/RedundantNext:
Enabled: true
AllowMultiNext: true
@@ -1153,7 +1128,7 @@ without arguments. Sometimes such statements are used to yild the nil
@@ -1177,7 +1152,7 @@ without arguments. Sometimes such statements are used to yild the nilallow_empty_next : Bool
- #
+ #
@@ -1191,7 +1166,7 @@ without arguments. Sometimes such statements are used to yild the nilallow_empty_next=(allow_empty_next : Bool)
- #
+ #
@@ -1205,7 +1180,7 @@ without arguments. Sometimes such statements are used to yild the nilallow_multi_next : Bool
- #
+ #
@@ -1219,7 +1194,7 @@ without arguments. Sometimes such statements are used to yild the nilallow_multi_next=(allow_multi_next : Bool)
- #
+ #
@@ -1233,7 +1208,7 @@ without arguments. Sometimes such statements are used to yild the nildescription : String
- #
+ #
@@ -1247,7 +1222,7 @@ without arguments. Sometimes such statements are used to yild the nildescription=(description : String)
- #
+ #
@@ -1261,7 +1236,7 @@ without arguments. Sometimes such statements are used to yild the nilenabled : Bool
- #
+ #
@@ -1275,7 +1250,7 @@ without arguments. Sometimes such statements are used to yild the nilenabled=(enabled)
- #
+ #
@@ -1289,7 +1264,7 @@ without arguments. Sometimes such statements are used to yild the nilexcluded : Array(String)?
- #
+ #
@@ -1303,7 +1278,7 @@ without arguments. Sometimes such statements are used to yild the nilexcluded=(excluded : Array(String)?)
- #
+ #
@@ -1317,7 +1292,7 @@ without arguments. Sometimes such statements are used to yild the nilseverity : Ameba::Severity
- #
+ #
@@ -1331,7 +1306,7 @@ without arguments. Sometimes such statements are used to yild the nilseverity=(severity)
- #
+ #
@@ -1345,13 +1320,13 @@ without arguments. Sometimes such statements are used to yild the niltest(source, node : Crystal::Next, visitor : AST::RedundantControlExpressionVisitor)
- #
+ #
A rule that disallows redundant return expressions.
-
For example, this is considered invalid:
-
deffooreturn:barend
-
defbar(arg)
case arg
when .nil?
@@ -657,13 +659,10 @@
return"empty"endend
-
And has to be written as the following:
-
deffoo:barend
-
defbar(arg)
case arg
when .nil?
@@ -674,51 +673,42 @@
"empty"endend
-
Configuration params
-
-
allow_multi_return, default: true
-
+
+
allow_multi_return, default: true
+
Allows end-user to configure whether to report or not the return statements
which return tuple literals i.e.
-
defmethod(a, b)
return a, b
end
-
If this param equals to false, the method above has to be written as:
-
defmethod(a, b)
{a, b}
end
-
-
allow_empty_return, default: true
-
+
+
allow_empty_return, default: true
+
Allows end-user to configure whether to report or not the return statements
without arguments. Sometimes such returns are used to return the nil value explicitly.
-
defmethod
@foo =:emptyreturnend
-
If this param equals to false, the method above has to be written as:
-
defmethod
@foo =:emptynilend
-
YAML config example
-
Style/RedundantReturn:
Enabled: true
AllowMutliReturn: true
@@ -763,7 +753,7 @@ without arguments. Sometimes such returns are used to return the nil
-
+
ameba/rule/style/redundant_return.cr
@@ -804,12 +794,12 @@ without arguments. Sometimes such returns are used to return the nil
A rule that disallows redundant return expressions.
-
For example, this is considered invalid:
-
deffooreturn:barend
-
defbar(arg)
case arg
when .nil?
@@ -1076,13 +1063,10 @@ without arguments. Sometimes such returns are used to return the nilreturn "empty"endend
-
And has to be written as the following:
-
deffoo:barend
-
defbar(arg)
case arg
when .nil?
@@ -1093,51 +1077,42 @@ without arguments. Sometimes such returns are used to return the nil"empty"
endend
-
Configuration params
-
-
allow_multi_return, default: true
-
+
+
allow_multi_return, default: true
+
Allows end-user to configure whether to report or not the return statements
which return tuple literals i.e.
-
defmethod(a, b)
return a, b
end
-
If this param equals to false, the method above has to be written as:
-
defmethod(a, b)
{a, b}
end
-
-
allow_empty_return, default: true
-
+
+
allow_empty_return, default: true
+
Allows end-user to configure whether to report or not the return statements
without arguments. Sometimes such returns are used to return the nil value explicitly.
-
defmethod
@foo =:emptyreturnend
-
If this param equals to false, the method above has to be written as:
-
defmethod
@foo =:emptynilend
-
YAML config example
-
Style/RedundantReturn:
Enabled: true
AllowMutliReturn: true
@@ -1147,7 +1122,7 @@ without arguments. Sometimes such returns are used to return the nil
@@ -1171,7 +1146,7 @@ without arguments. Sometimes such returns are used to return the nilallow_empty_return : Bool
- #
+ #
@@ -1185,7 +1160,7 @@ without arguments. Sometimes such returns are used to return the nilallow_empty_return=(allow_empty_return : Bool)
- #
+ #
@@ -1199,7 +1174,7 @@ without arguments. Sometimes such returns are used to return the nilallow_multi_return : Bool
- #
+ #
@@ -1213,7 +1188,7 @@ without arguments. Sometimes such returns are used to return the nilallow_multi_return=(allow_multi_return : Bool)
- #
+ #
@@ -1227,7 +1202,7 @@ without arguments. Sometimes such returns are used to return the nildescription : String
- #
+ #
@@ -1241,7 +1216,7 @@ without arguments. Sometimes such returns are used to return the nildescription=(description : String)
- #
+ #
@@ -1255,7 +1230,7 @@ without arguments. Sometimes such returns are used to return the nilenabled : Bool
- #
+ #
@@ -1269,7 +1244,7 @@ without arguments. Sometimes such returns are used to return the nilenabled=(enabled)
- #
+ #
@@ -1283,7 +1258,7 @@ without arguments. Sometimes such returns are used to return the nilexcluded : Array(String)?
- #
+ #
@@ -1297,7 +1272,7 @@ without arguments. Sometimes such returns are used to return the nilexcluded=(excluded : Array(String)?)
- #
+ #
@@ -1311,7 +1286,7 @@ without arguments. Sometimes such returns are used to return the nilseverity : Ameba::Severity
- #
+ #
@@ -1325,7 +1300,7 @@ without arguments. Sometimes such returns are used to return the nilseverity=(severity)
- #
+ #
@@ -1339,13 +1314,13 @@ without arguments. Sometimes such returns are used to return the niltest(source, node : Crystal::Return, visitor : AST::RedundantControlExpressionVisitor)
- #
+ #
But it considers this one invalid as it is an unless with an else:
-
unless something
:oneelse:twoend
-
The solution is to swap the order of the blocks, and change the unless to
an if, so the previous invalid example would become this:
-
if something
:twoelse:oneend
-
YAML configuration example:
-
Style/UnlessElse:
Enabled: true
@@ -714,7 +711,7 @@ an if, so the previous invalid example would become this:
-
+
ameba/rule/style/unless_else.cr
@@ -755,12 +752,12 @@ an if, so the previous invalid example would become this: