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

Fix Performance/MapCompact autocorrect causing invalid syntax #291

Conversation

QQism
Copy link
Contributor

@QQism QQism commented Jun 3, 2022

This commit fixes the issue when Performance/MapCompact auto-correction
fails to detect the argument block of an assignment method so it deletes
the block ending (i.e. end or }) when map { ... }.compact is
multiline.

Before

object.new_collection = collection.map do |item|
end.compact

# auto-corrected
object.new_collection = collection.filter_map do |item|

After

object.new_collection = collection.map do |item|
end.compact

# auto-corrected
object.new_collection = collection.filter_map do |item|
end

Rubocop Version

rubocop -V
1.28.2 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 3.0.1 x86_64-darwin20)
  - rubocop-performance 1.14.0

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@QQism QQism force-pushed the qq/fix/autocorrection-performance-mapcompact-break-syntax-with-assignment-methods branch 2 times, most recently from 3d340da to 9bb0b0d Compare June 3, 2022 05:36
@QQism QQism changed the title Fix auto-correction of Performance/MapCompact causing invalid syntax Fix Performance/MapCompact autocorrect causing invalid syntax Jun 3, 2022
@QQism QQism marked this pull request as ready for review June 3, 2022 05:41
@QQism QQism force-pushed the qq/fix/autocorrection-performance-mapcompact-break-syntax-with-assignment-methods branch from 9bb0b0d to 3865688 Compare June 3, 2022 05:45
CHANGELOG.md Outdated Show resolved Hide resolved
This commit fixes the issue when `Performance/MapCompact` auto-correction
fails to detect the argument block of an assignment method so it deletes
the block ending (i.e. `end` or `}`) when `map { ... }.compact` is
multiline.

Before

```ruby
object.new_collection = collection.map do |item|
end.compact

object.new_collection = collection.filter_map do |item|
```

After

```ruby
object.new_collection = collection.map do |item|
end.compact

object.new_collection = collection.filter_map do |item|
end
```
@QQism QQism force-pushed the qq/fix/autocorrection-performance-mapcompact-break-syntax-with-assignment-methods branch from 3865688 to 2ac0334 Compare June 3, 2022 06:04
@koic koic merged commit 297d8c7 into rubocop:master Jun 3, 2022
@koic
Copy link
Member

koic commented Jun 3, 2022

Nice! Thank you 👍

@QQism QQism deleted the qq/fix/autocorrection-performance-mapcompact-break-syntax-with-assignment-methods branch June 3, 2022 06:15
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

Successfully merging this pull request may close these issues.

2 participants