Refactor comparison to boolean rule

This commit is contained in:
Vitalii Elenhaupt 2017-11-07 23:40:06 +02:00
parent 362b66ce81
commit b6c0d3e8ad
No known key found for this signature in database
GPG Key ID: 7558EF3A4056C706
1 changed files with 7 additions and 6 deletions

View File

@ -18,12 +18,13 @@ module Ameba::Rules
end
def test(source, node : Crystal::Call)
if %w(== != ===).includes?(node.name) && (
node.args.first?.try &.is_a?(Crystal::BoolLiteral) ||
node.obj.is_a?(Crystal::BoolLiteral)
)
source.error self, node.location, "Comparison to a boolean is pointless"
end
comparison? = %w(== != ===).includes?(node.name)
to_boolean? = node.args.first?.try &.is_a?(Crystal::BoolLiteral) ||
node.obj.is_a?(Crystal::BoolLiteral)
return unless comparison? && to_boolean?
source.error self, node.location, "Comparison to a boolean is pointless"
end
end
end