Don’t allocate the array on every call

This commit is contained in:
Sijawusz Pur Rahnama 2021-01-17 17:49:45 +01:00
parent 5e58a60ade
commit fd4b2f309c

View file

@ -25,10 +25,11 @@ module Ameba::Rule::Lint
description "Disallows comparison to booleans"
end
MSG = "Comparison to a boolean is pointless"
MSG = "Comparison to a boolean is pointless"
OP_NAMES = %w(== != ===)
def test(source, node : Crystal::Call)
comparison = %w(== != ===).includes?(node.name)
comparison = node.name.in?(OP_NAMES)
to_boolean = node.args.first?.try &.is_a?(Crystal::BoolLiteral) ||
node.obj.is_a?(Crystal::BoolLiteral)