From ba5fb8e6b7d6cc2b077765aeeeadb3a015baf1e0 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sat, 23 Nov 2024 02:44:40 -0800 Subject: [PATCH 01/19] Add `Lint/LogicalWithoutParenthesis` (#313) --- .../rule/lint/logical_without_paren_spec.cr | 44 ++++++++++++++++ src/ameba/rule/lint/logical_without_paren.cr | 51 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 spec/ameba/rule/lint/logical_without_paren_spec.cr create mode 100644 src/ameba/rule/lint/logical_without_paren.cr diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr new file mode 100644 index 000000000..6063112c7 --- /dev/null +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -0,0 +1,44 @@ +require "../../../spec_helper" + +module Ameba::Rule::Lint + describe LogicalWithoutParenthesis do + subject = LogicalWithoutParenthesis.new + + it "passes if logical operator in call args has parenthesis" do + expect_no_issues subject, <<-CRYSTAL + if foo.includes?("bar" || foo.includes? "batz") + puts "this code is bug-free" + end + + if foo.includes?("bar") || foo.includes?("batz") + puts "this code is bug-free" + end + + form.add("query", "val_1" || "val_2") + form.add "query", ("val_1" || "val_2") + CRYSTAL + end + + it "passes if logical operator in assignment call" do + expect_no_issues subject, <<-CRYSTAL + hello.there = "world" || method.call + CRYSTAL + end + + it "passes if logical operator in square bracket call" do + expect_no_issues subject, <<-CRYSTAL + hello["world" || :thing] + this.is[1 || method.call] + CRYSTAL + end + + it "fails if logical operator in call args doesn't have parenthesis" do + expect_issue subject, <<-CRYSTAL + if foo.includes? "bar" || foo.includes? "batz" + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Logical operator in method args without parenthesis is not allowed + puts "this code is not bug-free" + end + CRYSTAL + end + end +end diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr new file mode 100644 index 000000000..86c55d591 --- /dev/null +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -0,0 +1,51 @@ +module Ameba::Rule::Lint + # A rule that disallows logical operators in method args without parenthesis. + # + # For example, this is considered invalid: + # + # ``` + # if a.includes? "b" && c.includes? "c" + # end + # + # form.add "query", "val_1" || "val_2" + # ``` + # + # And need to be written as: + # + # ``` + # if a.includes?("b") && c.includes?("c") + # end + # + # form.add("query", "val_1" || "val_2") + # # OR + # form.add "query", ("val_1" || "val_2") + # ``` + # + # YAML configuration example: + # + # ``` + # Lint/LogicalWithoutParenthesis: + # Enabled: true + # ``` + class LogicalWithoutParenthesis < Base + properties do + description "Disallows logical operators in method args without parenthesis" + end + + MSG = "Logical operator in method args without parenthesis is not allowed" + + def test(source, node : Crystal::Call) + return if node.args.size == 0 || + node.has_parentheses? || + node.name.ends_with?("=") || + node.name.in?(["[]?", "[]"]) + + node.args.each do |arg| + case arg + when Crystal::BinaryOp + issue_for arg, MSG + end + end + end + end +end From 9eba3530dc2e712921b0cf40f5b13cbbf9852cf9 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sat, 23 Nov 2024 18:34:19 -0800 Subject: [PATCH 02/19] Limit Lint/LogicalWithoutParenthesis to just binary ops with a right call that has args --- .../rule/lint/logical_without_paren_spec.cr | 2 +- src/ameba/rule/lint/logical_without_paren.cr | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr index 6063112c7..db125e9a3 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -35,7 +35,7 @@ module Ameba::Rule::Lint it "fails if logical operator in call args doesn't have parenthesis" do expect_issue subject, <<-CRYSTAL if foo.includes? "bar" || foo.includes? "batz" - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Logical operator in method args without parenthesis is not allowed + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Logical operator in method args without parenthesis is not allowed puts "this code is not bug-free" end CRYSTAL diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index 86c55d591..d9edb7ce3 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -6,8 +6,6 @@ module Ameba::Rule::Lint # ``` # if a.includes? "b" && c.includes? "c" # end - # - # form.add "query", "val_1" || "val_2" # ``` # # And need to be written as: @@ -16,9 +14,10 @@ module Ameba::Rule::Lint # if a.includes?("b") && c.includes?("c") # end # - # form.add("query", "val_1" || "val_2") - # # OR - # form.add "query", ("val_1" || "val_2") + # # or + # + # if a.includes?("b" && c.includes? "c") + # end # ``` # # YAML configuration example: @@ -43,7 +42,12 @@ module Ameba::Rule::Lint node.args.each do |arg| case arg when Crystal::BinaryOp - issue_for arg, MSG + case right = arg.right + when Crystal::Call + if right.args.size > 0 + issue_for node, MSG + end + end end end end From 404a5e1c0ece693f5cc8f7e4d27008571d10b4b9 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 10:59:18 -0500 Subject: [PATCH 03/19] Update spec/ameba/rule/lint/logical_without_paren_spec.cr Co-authored-by: Sijawusz Pur Rahnama --- spec/ameba/rule/lint/logical_without_paren_spec.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr index db125e9a3..19577232e 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -16,6 +16,7 @@ module Ameba::Rule::Lint form.add("query", "val_1" || "val_2") form.add "query", ("val_1" || "val_2") + form.add "query", "val_1" || "val_2" CRYSTAL end From 3a4b22f5e6e6d51e76289e655c0c646c5d2c90c3 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 10:59:33 -0500 Subject: [PATCH 04/19] Update src/ameba/rule/lint/logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index d9edb7ce3..75eba3850 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -4,7 +4,7 @@ module Ameba::Rule::Lint # For example, this is considered invalid: # # ``` - # if a.includes? "b" && c.includes? "c" + # if foo.includes? "bar" || foo.includes? "batz" # end # ``` # From d1126c119a4cfd1d9a2f4f1fab37794588bea346 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 14:57:37 -0800 Subject: [PATCH 05/19] Update logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index 75eba3850..9e251b96a 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -11,12 +11,7 @@ module Ameba::Rule::Lint # And need to be written as: # # ``` - # if a.includes?("b") && c.includes?("c") - # end - # - # # or - # - # if a.includes?("b" && c.includes? "c") + # if foo.includes?("bar") || foo.includes?("batz") # end # ``` # From a276f44ba97423d3d789a1c1cd3d0c7b4b55ef4e Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:05:11 -0800 Subject: [PATCH 06/19] Update logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index 9e251b96a..e391a895d 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -35,8 +35,7 @@ module Ameba::Rule::Lint node.name.in?(["[]?", "[]"]) node.args.each do |arg| - case arg - when Crystal::BinaryOp + if arg.is_a?(Crystal::BinaryOp) case right = arg.right when Crystal::Call if right.args.size > 0 From 4e8aa897fc85bbe01963e3a9f564596e0fec325c Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:05:18 -0800 Subject: [PATCH 07/19] Update logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index e391a895d..fde267a15 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -36,8 +36,7 @@ module Ameba::Rule::Lint node.args.each do |arg| if arg.is_a?(Crystal::BinaryOp) - case right = arg.right - when Crystal::Call + if (right = arg.right).is_a?(Crystal::Call) if right.args.size > 0 issue_for node, MSG end From 40b94bdada3ba5b4eb62e80d630d466539c7dfef Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:05:31 -0800 Subject: [PATCH 08/19] Update logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index fde267a15..888ff4f19 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -37,9 +37,7 @@ module Ameba::Rule::Lint node.args.each do |arg| if arg.is_a?(Crystal::BinaryOp) if (right = arg.right).is_a?(Crystal::Call) - if right.args.size > 0 - issue_for node, MSG - end + issue_for node, MSG unless right.args.empty? end end end From 5eb446c5a4251a47fe1cf3f528083fbe26eb4a4e Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:05:54 -0800 Subject: [PATCH 09/19] Update logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index 888ff4f19..bc65108f1 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -28,11 +28,13 @@ module Ameba::Rule::Lint MSG = "Logical operator in method args without parenthesis is not allowed" + ALLOWED_CALL_NAMES = %w{[]? []} + def test(source, node : Crystal::Call) - return if node.args.size == 0 || + return if node.args.empty? || node.has_parentheses? || - node.name.ends_with?("=") || - node.name.in?(["[]?", "[]"]) + node.name.ends_with?('=') || + node.name.in?(ALLOWED_CALL_NAMES) node.args.each do |arg| if arg.is_a?(Crystal::BinaryOp) From fa0357da8d39481622d0b06ffcf76ba0eb3ce4c6 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:06:04 -0800 Subject: [PATCH 10/19] Update logical_without_paren_spec.cr Co-authored-by: Sijawusz Pur Rahnama --- spec/ameba/rule/lint/logical_without_paren_spec.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr index 19577232e..325b46e68 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -23,6 +23,7 @@ module Ameba::Rule::Lint it "passes if logical operator in assignment call" do expect_no_issues subject, <<-CRYSTAL hello.there = "world" || method.call + hello.there ||= "world" || method.call CRYSTAL end From 3c8f139766e06eca04aa99608fc1ed39d101ed75 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:06:12 -0800 Subject: [PATCH 11/19] Update logical_without_paren_spec.cr Co-authored-by: Sijawusz Pur Rahnama --- spec/ameba/rule/lint/logical_without_paren_spec.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr index 325b46e68..aa572155a 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -30,6 +30,7 @@ module Ameba::Rule::Lint it "passes if logical operator in square bracket call" do expect_no_issues subject, <<-CRYSTAL hello["world" || :thing] + hello["world" || :thing]? this.is[1 || method.call] CRYSTAL end From ef7eeb9d925a7eb6f0d092fc35e05fa6070eac5a Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:10:55 -0800 Subject: [PATCH 12/19] Update logical_without_paren_spec.cr Co-authored-by: Sijawusz Pur Rahnama --- spec/ameba/rule/lint/logical_without_paren_spec.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr index aa572155a..9b5185f35 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -6,17 +6,17 @@ module Ameba::Rule::Lint it "passes if logical operator in call args has parenthesis" do expect_no_issues subject, <<-CRYSTAL - if foo.includes?("bar" || foo.includes? "batz") + if foo.includes?("bar") || foo.includes?("batz") puts "this code is bug-free" end - if foo.includes?("bar") || foo.includes?("batz") + if foo.includes?("bar" || foo.includes? "batz") puts "this code is bug-free" end form.add("query", "val_1" || "val_2") - form.add "query", ("val_1" || "val_2") form.add "query", "val_1" || "val_2" + form.add "query", ("val_1" || "val_2") CRYSTAL end From 8f4410a68b68818019c34bc91510d471a82183c3 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:36:47 -0800 Subject: [PATCH 13/19] Update logical_without_paren_spec.cr Co-authored-by: Sijawusz Pur Rahnama --- spec/ameba/rule/lint/logical_without_paren_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr index 9b5185f35..d4977f7a9 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -4,7 +4,7 @@ module Ameba::Rule::Lint describe LogicalWithoutParenthesis do subject = LogicalWithoutParenthesis.new - it "passes if logical operator in call args has parenthesis" do + it "passes if logical operator in call args has parentheses" do expect_no_issues subject, <<-CRYSTAL if foo.includes?("bar") || foo.includes?("batz") puts "this code is bug-free" From d89b565fdae39915f5e3aae9221d856df9932017 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:36:53 -0800 Subject: [PATCH 14/19] Update logical_without_paren_spec.cr Co-authored-by: Sijawusz Pur Rahnama --- spec/ameba/rule/lint/logical_without_paren_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/logical_without_paren_spec.cr index d4977f7a9..4c6f6f9bb 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/logical_without_paren_spec.cr @@ -35,7 +35,7 @@ module Ameba::Rule::Lint CRYSTAL end - it "fails if logical operator in call args doesn't have parenthesis" do + it "fails if logical operator in call args doesn't have parentheses" do expect_issue subject, <<-CRYSTAL if foo.includes? "bar" || foo.includes? "batz" # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Logical operator in method args without parenthesis is not allowed From 7e6d53fedcaec51fe467257a2acd1b1903817613 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 15:37:13 -0800 Subject: [PATCH 15/19] Update logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index bc65108f1..a390ad4de 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -1,5 +1,7 @@ module Ameba::Rule::Lint - # A rule that disallows logical operators in method args without parenthesis. + # A rule that disallows method calls with at least one argument, where no + # parentheses are used around the argument list, and a logical operator + # (`&&` or `||`) is used within the argument list. # # For example, this is considered invalid: # From 5d56b04566ba2653630e9ff01791009e18890455 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 19:48:49 -0500 Subject: [PATCH 16/19] Update src/ameba/rule/lint/logical_without_paren.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/logical_without_paren.cr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/logical_without_paren.cr index a390ad4de..d584f86fc 100644 --- a/src/ameba/rule/lint/logical_without_paren.cr +++ b/src/ameba/rule/lint/logical_without_paren.cr @@ -20,15 +20,15 @@ module Ameba::Rule::Lint # YAML configuration example: # # ``` - # Lint/LogicalWithoutParenthesis: + # Lint/RequireParentheses: # Enabled: true # ``` - class LogicalWithoutParenthesis < Base + class RequireParentheses < Base properties do - description "Disallows logical operators in method args without parenthesis" + description "Disallows method calls with no parentheses and a logical operator in the argument list" end - MSG = "Logical operator in method args without parenthesis is not allowed" + MSG = "Use parentheses in the method call to avoid confusion about precedence" ALLOWED_CALL_NAMES = %w{[]? []} From 3cba25ab141097f45bd5ef72fa855c52e2968286 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 19:50:28 -0500 Subject: [PATCH 17/19] LogicalWithoutParenthesis -> RequireParentheses --- ...l_without_paren_spec.cr => require_parentheses_spec.cr.cr} | 4 ++-- .../lint/{logical_without_paren.cr => require_parentheses.cr} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename spec/ameba/rule/lint/{logical_without_paren_spec.cr => require_parentheses_spec.cr.cr} (94%) rename src/ameba/rule/lint/{logical_without_paren.cr => require_parentheses.cr} (100%) diff --git a/spec/ameba/rule/lint/logical_without_paren_spec.cr b/spec/ameba/rule/lint/require_parentheses_spec.cr.cr similarity index 94% rename from spec/ameba/rule/lint/logical_without_paren_spec.cr rename to spec/ameba/rule/lint/require_parentheses_spec.cr.cr index 4c6f6f9bb..49003ecae 100644 --- a/spec/ameba/rule/lint/logical_without_paren_spec.cr +++ b/spec/ameba/rule/lint/require_parentheses_spec.cr.cr @@ -1,8 +1,8 @@ require "../../../spec_helper" module Ameba::Rule::Lint - describe LogicalWithoutParenthesis do - subject = LogicalWithoutParenthesis.new + describe RequireParentheses do + subject = RequireParentheses.new it "passes if logical operator in call args has parentheses" do expect_no_issues subject, <<-CRYSTAL diff --git a/src/ameba/rule/lint/logical_without_paren.cr b/src/ameba/rule/lint/require_parentheses.cr similarity index 100% rename from src/ameba/rule/lint/logical_without_paren.cr rename to src/ameba/rule/lint/require_parentheses.cr From fdaa2fc7c19898c424488dab895903b088d68d86 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sun, 24 Nov 2024 19:56:27 -0500 Subject: [PATCH 18/19] Fix specs --- ..._parentheses_spec.cr.cr => require_parentheses_spec.cr} | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) rename spec/ameba/rule/lint/{require_parentheses_spec.cr.cr => require_parentheses_spec.cr} (77%) diff --git a/spec/ameba/rule/lint/require_parentheses_spec.cr.cr b/spec/ameba/rule/lint/require_parentheses_spec.cr similarity index 77% rename from spec/ameba/rule/lint/require_parentheses_spec.cr.cr rename to spec/ameba/rule/lint/require_parentheses_spec.cr index 49003ecae..88b5eb414 100644 --- a/spec/ameba/rule/lint/require_parentheses_spec.cr.cr +++ b/spec/ameba/rule/lint/require_parentheses_spec.cr @@ -38,7 +38,12 @@ module Ameba::Rule::Lint it "fails if logical operator in call args doesn't have parentheses" do expect_issue subject, <<-CRYSTAL if foo.includes? "bar" || foo.includes? "batz" - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Logical operator in method args without parenthesis is not allowed + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use parentheses in the method call to avoid confusion about precedence + puts "this code is not bug-free" + end + + if foo.in? "bar", "baz" || foo.ends_with? "qux" + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use parentheses in the method call to avoid confusion about precedence puts "this code is not bug-free" end CRYSTAL From ef3f3c43c89351cd704bd0c396762d26677d2781 Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Mon, 25 Nov 2024 19:22:47 -0500 Subject: [PATCH 19/19] Update src/ameba/rule/lint/require_parentheses.cr Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/rule/lint/require_parentheses.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ameba/rule/lint/require_parentheses.cr b/src/ameba/rule/lint/require_parentheses.cr index d584f86fc..c62cb82c6 100644 --- a/src/ameba/rule/lint/require_parentheses.cr +++ b/src/ameba/rule/lint/require_parentheses.cr @@ -25,6 +25,7 @@ module Ameba::Rule::Lint # ``` class RequireParentheses < Base properties do + since_version "1.7.0" description "Disallows method calls with no parentheses and a logical operator in the argument list" end