-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
hash symbol key incorrectly converted to string #1684
Comments
I'm having trouble reproducing this on the current |
Sure. And thanks for checking this issue, it's the only thing that's wrong with auto-correct in our current projects. Code follows: $ cat test.rb h = { :"foo" => 1 } puts h $ rubocop -a test.rb Inspecting 1 file C Offenses: test.rb:1:7: C: [Corrected] Use the new Ruby 1.9 hash syntax. h = { :"foo" => 1 } ^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected $ cat test.rb h = { "foo": 1 } puts h $ cat .rubocop.yml Lint/AssignmentInCondition: AllowSafeAssignment: true Style/EmptyElse: Enabled: false Style/StringLiterals: Enabled: false Style/TrivialAccessors: AllowPredicates: true Style/GlobalVars: AllowedVariables: [$logger] Style/GuardClause: Enabled: false Style/Documentation: Enabled: false Style/CaseEquality: Enabled: true Metrics/LineLength: Enabled: true AllowURI: true Max: 100 Metrics/MethodLength: Max: 16 Metrics/AbcSize: Max: 45 Metrics/CyclomaticComplexity: Max: 12 Style/SignalException: Enabled: false AllCops: Include: - '**/config.ru' Exclude: - 'lib/templates/**/*' - 'db/**/*' - 'script/**/*' - 'bin/**/*' - 'config/**/*' |
With the extra info I located and eradicated the bug. :-) |
Ah, dem regexes :) Always write-only they are. Thank you! |
Actually the problem wasn't in the regexp, but in the fact that the parser normalizes string names and strips their quotes when they're not needed. |
This is a rare case I assume, but in a certain app we have all hash keys as symbols. However, one particular key may contain spaces, so we have to represent that key as string, which is then turned into symbol. An example:
{ ... :"custom column" => 42 }
Rubocop transforms this to
{ ... "custom column": 42 }
which breaks the code. I wonder would be the proper solution: could it be just assumed that if form :"" is used, it's explicitly made so and should be preserved?
The text was updated successfully, but these errors were encountered: