From b6c0d3e8ad041b96e58bf6148337446d7143c64c Mon Sep 17 00:00:00 2001 From: Vitalii Elenhaupt Date: Tue, 7 Nov 2017 23:40:06 +0200 Subject: [PATCH] Refactor comparison to boolean rule --- src/ameba/rules/comparison_to_boolean.cr | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ameba/rules/comparison_to_boolean.cr b/src/ameba/rules/comparison_to_boolean.cr index f4e01a95..231d8001 100644 --- a/src/ameba/rules/comparison_to_boolean.cr +++ b/src/ameba/rules/comparison_to_boolean.cr @@ -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