Instead of adding the new rule to support enforcing parens around assignments, refactor existing RedundantParentheses rule

This commit is contained in:
Sijawusz Pur Rahnama 2022-11-18 05:27:05 +01:00
parent 94a271b2a1
commit eabe463386
3 changed files with 32 additions and 51 deletions

View file

@ -75,7 +75,7 @@ module Ameba::Rule::Style
end
end
context "#exclude_assignments=" do
context "#parenthesized_assignments=" do
it "reports assignments by default" do
expect_issue subject, <<-CRYSTAL
if (foo = @foo)
@ -83,11 +83,24 @@ module Ameba::Rule::Style
foo
end
CRYSTAL
expect_no_issues subject, <<-CRYSTAL
if foo = @foo
foo
end
CRYSTAL
end
it "allows to configure assignments" do
rule = Rule::Style::RedundantParentheses.new
rule.exclude_assignments = true
rule.parenthesized_assignments = true
expect_issue rule, <<-CRYSTAL
if foo = @foo
# ^^^^^^^^^^ error: Missing parentheses
foo
end
CRYSTAL
expect_no_issues rule, <<-CRYSTAL
if (foo = @foo)