class Ameba::Rule::Lint::LiteralsComparison
- Ameba::Rule::Lint::LiteralsComparison
- Ameba::Rule::Base
- Reference
- Object
Overview
This rule is used to identify comparisons between two literals.
They usually have the same result - except for non-primitive types like containers, range or regex.
For example, this will be always false:
"foo" == 42
YAML configuration example:
Lint/LiteralsComparison:
Enabled: true
Included Modules
- Ameba::AST::Util
- YAML::Serializable
- YAML::Serializable::Strict
Defined in:
ameba/rule/lint/literals_comparison.crConstant Summary
-
MSG =
"Comparison always evaluates to %s"
-
MSG_LIKELY =
"Comparison most likely evaluates to %s"
-
OP_NAMES =
["===", "==", "!="] of ::String
Constructors
- .new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
-
.new(config = nil)
This rule is used to identify comparisons between two literals.
Class Method Summary
-
.parsed_doc : String?
Returns documentation for this rule, if there is any.
Instance Method Summary
- #description : String
- #description=(description : String)
- #enabled : Bool
- #enabled=(enabled : Bool)
- #excluded : Array(String)?
- #excluded=(excluded : Array(String)?)
- #severity : Ameba::Severity
- #severity=(severity : Ameba::Severity)
- #test(source, node : Crystal::Call)
-
#test(source)
Edge-case:
{{ T == Nil }}
Instance methods inherited from module Ameba::AST::Util
abort?(node)
abort?,
control_exp_code(node : Crystal::ControlExpression, code_lines)
control_exp_code,
dynamic_literal?(node, include_paths = false) : Bool
dynamic_literal?,
exit?(node)
exit?,
flow_command?(node, in_loop)
flow_command?,
flow_expression?(node, in_loop = false)
flow_expression?,
literal?(node, include_paths = false) : Bool
literal?,
loop?(node)
loop?,
name_end_location(node)
name_end_location,
name_location(node)
name_location,
name_size(node)
name_size,
node_source(node, code_lines)
node_source,
raise?(node)
raise?,
source_between(loc, end_loc, code_lines) : String?
source_between,
static_literal?(node, include_paths = false) : Bool
static_literal?
Instance methods inherited from class Ameba::Rule::Base
==(other)
==,
catch(source : Source)
catch,
excluded?(source)
excluded?,
group
group,
hash
hash,
name
name,
special?
special?,
test(source : Source, node : Crystal::ASTNode, *opts)test(source : Source) test
Constructor Detail
This rule is used to identify comparisons between two literals.
They usually have the same result - except for non-primitive types like containers, range or regex.
For example, this will be always false:
"foo" == 42
YAML configuration example:
Lint/LiteralsComparison:
Enabled: true
Class Method Detail
Returns documentation for this rule, if there is any.
module Ameba
# This is a test rule.
# Does nothing.
class MyRule < Ameba::Rule::Base
def test(source)
end
end
end
MyRule.parsed_doc # => "This is a test rule.\nDoes nothing."
Instance Method Detail
Edge-case: {{ T == Nil }}
Current implementation just skips all macro contexts, regardless of the free variable being present.
Ideally we should only check whether either of the sides is a free var