Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False negative for Lint/Void for expressions inside brackets #12716

Open
Earlopain opened this issue Feb 27, 2024 · 0 comments
Open

False negative for Lint/Void for expressions inside brackets #12716

Earlopain opened this issue Feb 27, 2024 · 0 comments

Comments

@Earlopain
Copy link
Contributor

Lint/Void leaves expressions like (1 + 1) alone because they are wrapped in brackets.
I tried fixing this myself but it is too complex for me.

Steps to reproduce the problem

Testcase:

it "registers an offense for void op #{op} if used in brackets" do
  expect_offense(<<~RUBY, op: op)
    (a %{op} b)
       ^{op} Operator `#{op}` used in void context.
    ((a %{op} b))
        ^{op} Operator `#{op}` used in void context.
    (((a %{op} b)))
  RUBY

  # Rest handled by Style/RedundantParentheses and Layout/IndentationConsistency
  # Though it would look better here if brackets are removed directly
  expect_correction(<<~RUBY)
    (a
    b)
    ((a
    b))
    (((a %{op} b))) # or maybe just `à %{op} b`? Either way, shouldn't be autocorrected like the others
  RUBY
end

RuboCop version

$ [bundle exec] rubocop -V
1.60.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux]
  - rubocop-performance 1.18.0
  - rubocop-rspec 2.23.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant