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 an autocorrect for Style/RedundantSort with logical operator #10853

Merged

Conversation

ydah
Copy link
Member

@ydah ydah commented Aug 2, 2022

This PR is fix an autocorrect for Style/RedundantSort with logical operator

If you have a code like the following:

[1, 2, 3]
  .sort_by { |x| x.length }
  .first || []

After autocorrection it will look like this:

[1, 2, 3]
  .sort_by { |x| x.length }
  || []

This is a syntax error.

Error: : eval:3: syntax error, unexpected '|', expecting end-of-input
  || []
  ^
 (SyntaxError)

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.

@ydah ydah force-pushed the fix_false_positive_for_style_redundant_sort branch from 4b0c643 to 4c4f77f Compare August 2, 2022 10:01
@@ -0,0 +1 @@
* [#10853](https://github.com/rubocop/rubocop/pull/10853): Fix an autocorrect for `Style/RedundantSort` with predicate operator. ([@ydah][])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean logical operator instead of predicate operator?

Copy link
Member Author

@ydah ydah Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, you are right. I fixed it. Thank you so much.

@ydah ydah changed the title Fix an autocorrect for Style/RedundantSort with predicate operator Fix an autocorrect for Style/RedundantSort with logical operator Aug 2, 2022
This PR is fix an autocorrect for `Style/RedundantSort` with predicate operator

If you have a code like the following:
```ruby
[1, 2, 3]
  .sort_by { |x| x.length }
  .first || []
```

After autocorrection it will look like this:
```ruby
[1, 2, 3]
  .sort_by { |x| x.length }
  || []
```

This is a syntax error.
```
Error: : eval:3: syntax error, unexpected '|', expecting end-of-input
  || []
  ^
 (SyntaxError)
 ```
@ydah ydah force-pushed the fix_false_positive_for_style_redundant_sort branch from 4c4f77f to 4dd187a Compare August 2, 2022 10:09
@ydah ydah requested a review from koic August 2, 2022 10:10
@koic koic merged commit 8ff7270 into rubocop:master Aug 3, 2022
@koic
Copy link
Member

koic commented Aug 3, 2022

Thanks!

@ydah ydah deleted the fix_false_positive_for_style_redundant_sort branch August 3, 2022 02:14
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.

None yet

2 participants