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

Lint/Void removing valid block content #12274

Closed
janbiedermann opened this issue Oct 13, 2023 · 0 comments · Fixed by #12306
Closed

Lint/Void removing valid block content #12274

janbiedermann opened this issue Oct 13, 2023 · 0 comments · Fixed by #12306
Labels

Comments

@janbiedermann
Copy link

Before:

    e.each do |_k, v|
      v == 'b'
    end

After autocorecction:

    e.each do |_k, v|
    end

In my case e is a enumerator that filters. Of course, that fails after autocorrection. But also, removing block contents and leaving a empty block is not so useful either.

@koic koic added the bug label Oct 24, 2023
koic added a commit to koic/rubocop that referenced this issue Oct 24, 2023
Fixes rubocop#12274.

This PR fixes a false positive for `Lint/Void` when `each`'s receiver is
an object of `Enumerator` to which `filter` has been applied.

`each` blocks are allowed to prevent false positives.
The expression inside the following block is not void:

```ruby
enumerator = [1, 2, 3].filter
enumerator.each { |item| item >= 2 } #=> [2, 3]
```

This might introduce false negatives, but higher severity Lint cop should
aim for as safe detections as possible, I think.
bbatsov pushed a commit that referenced this issue Oct 25, 2023
Fixes #12274.

This PR fixes a false positive for `Lint/Void` when `each`'s receiver is
an object of `Enumerator` to which `filter` has been applied.

`each` blocks are allowed to prevent false positives.
The expression inside the following block is not void:

```ruby
enumerator = [1, 2, 3].filter
enumerator.each { |item| item >= 2 } #=> [2, 3]
```

This might introduce false negatives, but higher severity Lint cop should
aim for as safe detections as possible, I think.
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this issue Nov 1, 2023
https://build.opensuse.org/request/show/1121572
by user dancermak + dimstar_suse
- updated to version 1.57.2
  ## 1.57.2 (2023-10-26)
  ### Bug fixes
  * [#12274](rubocop/rubocop#12274): Fix a false positive for `Lint/Void` when `each`'s receiver is an object of `Enumerator` to which `filter` has been applied. ([@koic][])
  * [#12291](rubocop/rubocop#12291): Fix a false positive for `Metrics/ClassLength` when a class with a singleton class definition. ([@koic][])
  * [#12293](rubocop/rubocop#12293): Fix a false positive for `Style/RedundantDoubleSplatHashBraces` when using double splat hash braces with `merge` and method chain. ([@koic][])
  * [#12298](rubocop/rubocop#12298): Fix a false positive for `Style/RedundantParentheses` when using a parenthesized hash literal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants