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 #11182] Fix an incorrect autocorrect for Style/IfUnlessModifier with Style/HashSyntax #11185

Conversation

koic
Copy link
Member

@koic koic commented Nov 16, 2022

This PR intentionally separates two commits to resolve #11182.

First, this resolution of #11182 requires a change of Style/HashSyntax behavior.

The first change makes Style/HashSyntax aware of without parentheses call expr follows. It prepares to prevent Style/HashSyntax with Style/IfUnlessModifier autocorrection conflicts that resolve #11182.

Before

Previously Style/HashSyntax accepted the following syntax to prevent syntax errors:

foo bar value: value
baz

This avoids the following incompatible syntax:

foo bar value:
baz

After

Style/HashSyntax registers an offense for:

foo bar value: value
baz

And the autocorrection adds parentheses to prevent syntax errors shown in the URL:
https://bugs.ruby-lang.org/issues/18396

foo bar(value:)
baz

By assuming the above first change of Style/HashSyntax, the next commit fixes an incorrect autocorrect for EnforcedShorthandSyntax: always of Style/HashSyntax with Style/IfUnlessModifier when using Ruby 3.1.


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.

@koic koic changed the title Fix an incorrect autocorrect for style if unless modifier [Fix #11182] Fix an incorrect autocorrect for Style/IfUnlessModifier with Style/HashSyntax Nov 16, 2022
Prepare to solve rubocop#11182.

This commit makes `Style/HashSyntax` aware of without parentheses call expr follows.
It prepares to prevent `Style/HashSyntax` with `Style/IfUnlessModifier`
autocorrection conflicts that resolve rubocop#11182.

## Before

Previously `Style/HashSyntax` accepted the following syntax to prevent syntax errors:

```ruby
foo bar value: value
baz
```

This avoids the following incompatible syntax:

```ruby
foo bar value:
baz
```

## After

`Style/HashSyntax` registers an offense for:

```ruby
foo bar value: value
baz
```

And the autocorrection adds parentheses to prevent syntax errors shown in the URL:
https://bugs.ruby-lang.org/issues/18396

```ruby
foo bar(value:)
baz
```
…odifier`

This commit fixes an incorrect autocorrect for `EnforcedShorthandSyntax: always` of
`Style/HashSyntax` with `Style/IfUnlessModifier` when using Ruby 3.1.
@koic koic force-pushed the fix_an_incorrect_autocorrect_for_style_if_unless_modifier branch from 0df9e1f to 7745a29 Compare November 16, 2022 16:28
@bbatsov bbatsov merged commit 37aa05b into rubocop:master Nov 22, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 22, 2022

Thanks!

@koic koic deleted the fix_an_incorrect_autocorrect_for_style_if_unless_modifier branch November 22, 2022 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants