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

Style/RedundantPercentQ autocorrects Ruby hash output unsafely #12786

Closed
boardfish opened this issue Mar 12, 2024 · 0 comments
Closed

Style/RedundantPercentQ autocorrects Ruby hash output unsafely #12786

boardfish opened this issue Mar 12, 2024 · 0 comments
Labels

Comments

@boardfish
Copy link
Contributor

boardfish commented Mar 12, 2024

Style/RedundantPercentQ will autocorrect given the following, albeit unsafely:

%Q(
  { "foo" => "bar" }
)

It will replace the surrounding %Q with double quotes and will not escape the contents, resulting in syntactically invalid code.

Issue demonstrated in this PR.


Expected behavior

Stylistically I think I would prefer %Q was kept for this multiline output, but I appreciate that that's subjective.

Actual behavior

The code was autocorrected to:

"
  { "foo" => "bar" }
"

As GitHub's syntax highlighting...well, highlights, this doesn't resolve to a string.

Steps to reproduce the problem

rubocop --only Style/RedundantPercentQ -a <some_file_containing_this_input.rb>

RuboCop version

1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.3.0) [arm64-darwin23]
  - rubocop-capybara 2.20.0
  - rubocop-factory_bot 2.25.1
  - rubocop-performance 1.20.2
  - rubocop-rails 2.23.1
  - rubocop-rspec 2.26.1
@koic koic added the bug label Mar 13, 2024
boardfish added a commit to boardfish/rubocop that referenced this issue Mar 13, 2024
boardfish added a commit to boardfish/rubocop that referenced this issue Mar 14, 2024
@koic koic closed this as completed in 72bea19 Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants