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/HashSyntax to support hash rockets when pointing to symbols #1437

Closed
brodock opened this issue Nov 7, 2014 · 8 comments · Fixed by #1589
Closed

Style/HashSyntax to support hash rockets when pointing to symbols #1437

brodock opened this issue Nov 7, 2014 · 8 comments · Fixed by #1589

Comments

@brodock
Copy link

brodock commented Nov 7, 2014

While this is not covered by the ruby style guide yet, I've seen benefits of using hash rocket instead of 1.9 when pointing to symbols:

# bad
{key: :value}

# good
{:key => :value}

As I beleive this may not be consensus, I suggest to make it specific configurable:

Style/HashSyntax:
  AllowHashRocketForSymbolicValues: true/false

This may be related to #519.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 7, 2014

The cop is already supporting this style (EnforcedStyle: hash_rockets).

@bbatsov bbatsov closed this as completed Nov 7, 2014
@brodock
Copy link
Author

brodock commented Nov 7, 2014

I mean a different situation, to make it more clear:

# bad
{key: :value}
{:key => 'valeu'}
{:key => 1}

# good
{:key => :value}
{key: 'value'}
{key: 1}

@bbatsov bbatsov reopened this Nov 8, 2014
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 8, 2014

OK, now I get what you mean. Guess we can add another enforced style for this.

@ghost
Copy link

ghost commented Nov 19, 2014

👍

@maksar
Copy link

maksar commented Nov 26, 2014

Excuse me for stupid question @brodock, but can you please briefly describe benefits of hash rocket usage when it points to symbols?

@brodock
Copy link
Author

brodock commented Nov 27, 2014

@maksar: no hidden secret or ancient optimization, it's just a f... lot more readable when using good code highlight (github doesn't help much demonstrating it).

get this example:

{ attribute: true, size: 50, height: 60, type: :something, points: 333, title: 'Some phrase goes here', subtitle: "now with #{interpolated} string"}
{ attribute: true, size: 50, height: 60, :type => :something, points: 333, title: 'Some phrase goes here', subtitle: "now with #{interpolated} string"}

find the value of ":type" key.

another one:

{ from_a: :to_b, from_c: :to_d, from_d: :to_c }
{ :from_a => :to_b, :from_c => :to_d, :from_d => :to_c }

which one you think it's more clear?

@maksar
Copy link

maksar commented Nov 27, 2014

@brodock Agree with you on clarity point. However, line length counts too.
Personally, first example you provided would look like

{
  attribute: true,
  size:      50,
  height:    60,
  type:      :something,
  points:    333,
  title:     'Some phrase goes here',
  subtitle:  "now with #{interpolated} string"
}

in my code, which solves both 'where the value of given key' and 'why lines are so long' problems.

Thanks for you explanation, though. In short cases hash rockets do indeed look nicer, besides, can't still be avoided with string keys...

@rrosenblum
Copy link
Contributor

I have an idea on how to implement this feature and have started on some code for it. I will try to put together a pull request soon.

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 a pull request may close this issue.

4 participants