Skip to content

Conversation

@koic
Copy link
Member

@koic koic commented Oct 3, 2025

This PR fixes the following incorrect autocorrect for Style/Semicolon when a method call using hash value omission without parentheses is terminated with a semicolon:

$ echo 'm key:;do_something' | RUBOCOP_TARGET_RUBY_VERSION=3.1 bundle exec rubocop --stdin example.rb -A --only Style/Semicolon
Inspecting 1 file
C

Offenses:

example.rb:1:7: C: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
m key:;do_something
      ^

1 file inspected, 1 offense detected, 1 offense corrected
====================
m key:
do_something

This changes the meaning so that the standalone expression do_something is treated as a hash key.


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.

This PR fixes the following incorrect autocorrect for Style/Semicolon when
a method call using hash value omission without parentheses is terminated with a semicolon:

```console
$ echo 'm key:;do_something' | RUBOCOP_TARGET_RUBY_VERSION=3.1 bundle exec rubocop --stdin example.rb -A --only Style/Semicolon
Inspecting 1 file
C

Offenses:

example.rb:1:7: C: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
m key:;do_something
      ^

1 file inspected, 1 offense detected, 1 offense corrected
====================
m key:
do_something
```

This changes the meaning so that the standalone expression `do_something` is treated as a hash key.
@koic koic force-pushed the fix_incorrect_autocorrect_for_style_semicolon branch from 7214027 to c3eef10 Compare October 3, 2025 07:08
@koic koic merged commit 5a8bb49 into rubocop:master Oct 3, 2025
22 checks passed
@koic koic deleted the fix_incorrect_autocorrect_for_style_semicolon branch October 3, 2025 15:07
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.

1 participant