Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 Fix autocorrect for `Style/HashConversion` to avoid syntax error by koic · Pull Request #14343 · rubocop/rubocop · GitHub
Nothing Special   »   [go: up one dir, main page]

Skip to content

Conversation

koic
Copy link
Member
@koic koic commented Jul 6, 2025

This PR fixes autocorrect code for Style/HashConversion to avoid syntax error.

Before

Autocorrection causes a syntax error.

echo "Hash[].to_h" | bundle exec rubocop --stdin example.rb -A
Inspecting 1 file
F

Offenses:

example.rb:1:1: C: [Corrected] Style/EmptyLiteral: Use hash literal {} instead of Hash[].
Hash[].to_h
^^^^^^
example.rb:1:1: C: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
Hash[].to_h
^
example.rb:1:1: C: [Corrected] Style/HashConversion: Prefer literal hash to Hash[arg1, arg2, ...].
Hash[].to_h
^^^^^^
example.rb:1:8: W: [Corrected] Lint/RedundantTypeConversion: Redundant to_h detected.
Hash[].to_h
^^^^
example.rb:2:3: F: Lint/Syntax: unexpected token tLPAREN2
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
{}()
^

1 file inspected, 5 offenses detected, 4 offenses corrected
====================
# frozen_string_literal: true
{}()

After

No syntax errors.

$ echo "Hash[].to_h" | bundle exec rubocop --stdin example.rb -A
Inspecting 1 file
W

Offenses:

example.rb:1:1: C: [Corrected] Style/EmptyLiteral: Use hash literal {} instead of Hash[].
Hash[].to_h
^^^^^^
example.rb:1:1: C: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
Hash[].to_h
^
example.rb:1:1: C: [Corrected] Style/HashConversion: Prefer literal hash to Hash[arg1, arg2, ...].
Hash[].to_h
^^^^^^
example.rb:1:8: W: [Corrected] Lint/RedundantTypeConversion: Redundant to_h detected.
Hash[].to_h
^^^^
example.rb:2:1: C: [Corrected] Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.
{}
^

1 file inspected, 5 offenses detected, 5 offenses corrected
====================
# frozen_string_literal: true

{}

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 force-pushed the fix_autocorrect_for_style_hash_conversion branch from db3bd54 to 1d474ce Compare July 6, 2025 08:53
@@ -0,0 +1 @@
* [#14343](https://github.com/rubocop/rubocop/pull/14343): Fix autocorrect code for `Style/HashConversion` to avoi syntax error. ([@koic][])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* [#14343](https://github.com/rubocop/rubocop/pull/14343): Fix autocorrect code for `Style/HashConversion` to avoi syntax error. ([@koic][])
* [#14343](https://github.com/rubocop/rubocop/pull/14343): Fix autocorrect code for `Style/HashConversion` to avoid syntax error. ([@koic][])

This PR fixes autocorrect code for `Style/HashConversion`
to avoid syntax error.

## Before

Autocorrection causes a syntax error.

```console
echo "Hash[].to_h" | bundle exec rubocop --stdin example.rb -A
Inspecting 1 file
F

Offenses:

example.rb:1:1: C: [Corrected] Style/EmptyLiteral: Use hash literal {} instead of Hash[].
Hash[].to_h
^^^^^^
example.rb:1:1: C: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
Hash[].to_h
^
example.rb:1:1: C: [Corrected] Style/HashConversion: Prefer literal hash to Hash[arg1, arg2, ...].
Hash[].to_h
^^^^^^
example.rb:1:8: W: [Corrected] Lint/RedundantTypeConversion: Redundant to_h detected.
Hash[].to_h
^^^^
example.rb:2:3: F: Lint/Syntax: unexpected token tLPAREN2
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
{}()
^

1 file inspected, 5 offenses detected, 4 offenses corrected
====================
# frozen_string_literal: true
{}()
```

## After

No syntax errors.

```console
$ echo "Hash[].to_h" | bundle exec rubocop --stdin example.rb -A
Inspecting 1 file
W

Offenses:

example.rb:1:1: C: [Corrected] Style/EmptyLiteral: Use hash literal {} instead of Hash[].
Hash[].to_h
^^^^^^
example.rb:1:1: C: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
Hash[].to_h
^
example.rb:1:1: C: [Corrected] Style/HashConversion: Prefer literal hash to Hash[arg1, arg2, ...].
Hash[].to_h
^^^^^^
example.rb:1:8: W: [Corrected] Lint/RedundantTypeConversion: Redundant to_h detected.
Hash[].to_h
^^^^
example.rb:2:1: C: [Corrected] Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.
{}
^

1 file inspected, 5 offenses detected, 5 offenses corrected
====================
# frozen_string_literal: true

{}
```
@koic koic force-pushed the fix_autocorrect_for_style_hash_conversion branch from 1d474ce to 0ef54b5 Compare July 6, 2025 14:15
@koic koic merged commit 0b08bb8 into rubocop:master Jul 6, 2025
24 checks passed
@koic koic deleted the fix_autocorrect_for_style_hash_conversion branch July 6, 2025 15:11
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

0