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

Invalid autocorrect for Style/HashSyntax #12312

Closed
jcoyne opened this issue Oct 25, 2023 · 3 comments · Fixed by #12316
Closed

Invalid autocorrect for Style/HashSyntax #12312

jcoyne opened this issue Oct 25, 2023 · 3 comments · Fixed by #12316
Labels

Comments

@jcoyne
Copy link

jcoyne commented Oct 25, 2023

This was a String format operator, but it gets transformed to be a String quotation.

Offenses:

app/helpers/application_helper.rb:36:37: C: [Corrected] Style/HashSyntax: Omit the hash value.
      Settings.embed.url % { druid: druid }
                                    ^^^^^

40 files inspected, 1 offense detected, 1 offense corrected

➜  git diff
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 5809493..5468147 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -33,7 +33,7 @@ module ApplicationHelper

   def embeddable_url(druid)
     if Settings.embed.url
-      Settings.embed.url % { druid: druid }
+      Settings.embed.url %({ druid: })
     else
       purl_url(druid)


➜  bundle exec  rubocop -v
1.56.2
@koic
Copy link
Member

koic commented Oct 25, 2023

I cannot reproduce that issue. If only the Style/HashSyntax registering offenses, can you provide your .rubocop.yml configuration?

@jcoyne
Copy link
Author

jcoyne commented Oct 25, 2023

Yes:
https://github.com/sul-dlss/purl/blob/main/.rubocop.yml

You can reproduce by pulling this commit: sul-dlss/purl@c12d669 then changing the ruby language to 3.2 and then autocorrecting with rubocop.

@jcoyne
Copy link
Author

jcoyne commented Oct 25, 2023

Here's a minimal test case:

# test.rb
if Settings.embed.url
  Settings.embed.url % { druid: druid }
else
  purl_url(druid)
end
# .rubocop.yml
AllCops:
  TargetRubyVersion: 3.2

Style/FrozenStringLiteralComment:
  Enabled: false

Style/FormatString:
  Enabled: false

@koic koic added the bug label Oct 25, 2023
koic added a commit to koic/rubocop that referenced this issue Oct 26, 2023
Fixes rubocop#12312.

This PR fixes an incorrect autocorrect for `Style/HashSyntax`
when braced hash key and value are the same and it is used in `if`...`else`.
bbatsov pushed a commit that referenced this issue Oct 26, 2023
Fixes #12312.

This PR fixes an incorrect autocorrect for `Style/HashSyntax`
when braced hash key and value are the same and it is used in `if`...`else`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants