Ameba::Rule::Lint::UnusedExpression
Inherits YAML::Serializable < Ameba::Rule::Base < Ameba::Config::RuleConfig < Reference < Object
A rule that disallows unused expressions.
For example, this is considered invalid:
a = obj.method do |x|
x == 1 # => Comparison operation has no effect
puts x
end
Float64 | StaticArray(Float64, 10)
pointerof(foo)
And these are considered valid:
a = obj.method do |x|
x == 1
end
foo : Float64 | StaticArray(Float64, 10) = 0.1
bar = pointerof(foo)
This rule currently supports checking for unused:
- comparison operators:
<,>=, etc. - generics and unions:
String?,Int32 | Float64, etc. - literals: strings, bools, chars, hashes, arrays, range, etc.
- pseudo-method calls:
sizeof,is_a?etc. - variable access: local,
@ivar,@@cvarandself
YAML configuration example:
Lint/UnusedExpression:
Enabled: true
Constants
Constructors
A rule that disallows unused expressions.
For example, this is considered invalid:
a = obj.method do |x|
x == 1 # => Comparison operation has no effect
puts x
end
Float64 | StaticArray(Float64, 10)
pointerof(foo)
And these are considered valid:
a = obj.method do |x|
x == 1
end
foo : Float64 | StaticArray(Float64, 10) = 0.1
bar = pointerof(foo)
This rule currently supports checking for unused:
- comparison operators:
<,>=, etc. - generics and unions:
String?,Int32 | Float64, etc. - literals: strings, bools, chars, hashes, arrays, range, etc.
- pseudo-method calls:
sizeof,is_a?etc. - variable access: local,
@ivar,@@cvarandself
YAML configuration example:
Lint/UnusedExpression:
Enabled: true
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."
Instance methods
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.