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

hash symbol key incorrectly converted to string #1684

Closed
edvardm opened this issue Mar 3, 2015 · 5 comments
Closed

hash symbol key incorrectly converted to string #1684

edvardm opened this issue Mar 3, 2015 · 5 comments
Labels

Comments

@edvardm
Copy link

edvardm commented Mar 3, 2015

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?

@bbatsov bbatsov added the bug label Mar 6, 2015
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 7, 2015

I'm having trouble reproducing this on the current master. Can you check if the problem is present there? If so - add more detailed steps on how to reproduce it.

@edvardm
Copy link
Author

edvardm commented Mar 7, 2015

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/**/*'

@bbatsov bbatsov closed this as completed in 89e5eb3 Mar 7, 2015
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 7, 2015

With the extra info I located and eradicated the bug. :-)

@edvardm
Copy link
Author

edvardm commented Mar 7, 2015

Ah, dem regexes :) Always write-only they are. Thank you!

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 7, 2015

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.

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