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

Expand Lint/Void to catch other void contexts, specifically inside if statements #12393

Open
jez opened this issue Nov 15, 2023 · 0 comments
Open

Comments

@jez
Copy link

jez commented Nov 15, 2023

Is your feature request related to a problem? Please describe.

Version

❯ rubocop -V
1.57.2 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 2.7.2) [arm64-darwin22]

foo.rb

# frozen_string_literal: true

def example
  ''
  if T.unsafe(true)
    puts
    ''
  end
  nil
end

Output

❯ rubocop foo.rb
Inspecting 1 file
W

Offenses:

foo.rb:4:3: W: [Correctable] Lint/Void: Literal '' used in void context.
  ''
  ^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

In this example, we see that the '' on the first line of the example method reports a Lint/Void violation.

Describe the solution you'd like

The '' inside the if is also useless—it would be nice to have a rule which catches problems like this. This sort of code usually indicates that someone expected to be assigning '' to a variable, but no assignment is happening.

Describe alternatives you've considered

One solution would be adding this to Lint/Void.
Another solution would be creating a new rule for this.

Additional context

n/a

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