Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an incorrect auto-correct for
Style/HashConversion
This PR fixes the following incorrect auto-correct for `Style/HashConversion` when `Hash[]` as a method argument without parentheses. ```console % cat example.rb do_something Hash[a: b, c: d], 42 % bundle exec rubocop --only Style/HashConversion -a (snip) Inspecting 1 file C Offenses: example.rb:1:14: C: [Corrected] Style/HashConversion: Prefer literal hash to Hash[key: value, ...]. do_something Hash[a: b, c: d], 42 ^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` ## Before Auto-corrected to invalid syntax. ```ruby % cat example.rb do_something {a: b, c: d}, 42 % ruby -c example.rb example.rb:1: syntax error, unexpected ':', expecting '}' do_something {a: b, c: d}, 42 ``` ## After Auto-corrected to valid syntax. ```ruby % cat example.rb do_something({a: b, c: d}, 42) ```
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/fix_an_incorrect_autocorrect_for_style_hash_conversion.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#9712](https://github.com/rubocop/rubocop/pull/9712): Fix an incorrect auto-correct for `Style/HashConversion` when `Hash[]` as a method argument without parentheses. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters