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

Enable Style/HashSyntax Ruby 1.9 #813

Closed
PanosCodes opened this issue Jan 19, 2023 · 2 comments
Closed

Enable Style/HashSyntax Ruby 1.9 #813

PanosCodes opened this issue Jan 19, 2023 · 2 comments
Assignees

Comments

@PanosCodes
Copy link
Contributor

PanosCodes commented Jan 19, 2023

Motivation

Across the Apipie code base there different ways of using hashes. For consistency reasons. I think we could standardize that.

Proposal

Although that's a personal preference I think we could use the Ruby 1.9 style of Hash syntax and have Symbol keys use : as well as String keys use =>

https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/HashSyntax

Example

# bad
{:a => 2}
{b: 1, :c => 2}

# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden

Implementation

In .rubocop.yml we can enable the Style/HashSyntax rule and run the autocorrector(Can Rubocop challenger do that ?)

Style/HashSyntax:
  EnforcedStyle: ruby19

Any thoughts ?

@mathieujobin
Copy link
Collaborator

When I had to take such a decision in the past, it was for trailing or leading dots for multiline method calls.

Layout/DotPosition:
  Description: 'Checks the position of the dot in multi-line method calls.'
  StyleGuide: '#consistent-multi-line-chains'
  EnforcedStyle: trailing

it was a large code base, and so I tried to do the auto-correct with both settings and chose the one with the least changes. so to keep the code base as consistent as possible.

if its half and half, I'd be tempted only to enforce on new files toward the preference the team has.

@mathieujobin
Copy link
Collaborator

ruby19_no_mixed_keys
142 files inspected, 931 offenses detected, 931 offenses autocorrectable

ruby19
142 files inspected, 928 offenses detected, 928 offenses autocorrectable

hash_rockets
142 files inspected, 336 offenses detected, 336 offenses autocorrectable

no_mixed_keys
142 files inspected, 4 offenses detected, 4 offenses autocorrectable

So I would be tempted to vote for the last one .. and make as little change as needed.

about rubocop_challenger, it would eventually select that rule and propose to make an auto change, ruby19 is the default. but if we want to have another setting, we need an intervention.

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

No branches or pull requests

2 participants