-
Notifications
You must be signed in to change notification settings - Fork 213
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
Request to change Style/HashSyntax to ruby19 (the default) #650
Comments
The commit and the reason behind the decision: 3e2ccfc |
Hi Jennifer! I understand your gripe here, and this is 100% my fault, not Cam's. Since 2018 I have tried to establish as much consistency as possible throughout Standard, and this is one where both solutions are bad, IMO. Cases like yours that use
I favor keeping this as-is for two reasons:
Open to more discussion |
Just to be clear, you are thinking that keeping the rule as is will be safer for code bases that might have hashes like this:
and you want to ensure they don't get looping assuming every key is a symbol? Still annoyed, but I'm fine closing in the name of saving others from foolishness. |
Even if my code does look uglier and there's nothing I can do about it other than make an exception which will just make it uglier 😝 |
I literally laughed, out loud. 😂 APPROVED! |
I just made this change in one of UC's (big, internal) Rails apps. I disabled this cop for the whole |
It would be nice if you could differentiate hashes passed to a method call vs just hash literals. IMO the rule makes sense for hash literals, but maybe not so much for hashes passed to a method call 🤷🏻♀️*. The code in *On the other other hand, you can't do code like this: def foo(args, a:)
end
foo("a" => "b", a: 123) So IMO the only time it makes sense to mix hash key types is for DSLs. |
Honestly mixing hash keys like this is kind of a pain for the routes file implementation as well. If I may, I'd encourage people to use the mount Sidekiq::Web, to: "/jobs", as: "jobs", constraints: Constraints::Staff.new |
I only run into this in routes files and after blanket disabling the rule for that file for a while I gave in and just fixed them all. I do hate the |
I'm with @searls on this one specifically because of the "consistent within a hash" argument. Sidesteps a sizeable pile of trouble down the line. |
I'll be totally honest, I didn't even know that routes.rb still supported If anything, the fact the only counter-example being raised here is routes.rb is making me feel more like the rule as-is identifies a code smell in the method (which should really be fixed in rails but whatcha gonna do) |
Personally I think I’d rather not use or put another way, there’s going to be inconsistency either way, and forcing people to use the less-preferred syntax doesn’t actually get rid of the inconsistency. |
I have this line in my code:
I wanted to change it to:
but Standard wouldn't allow it and it's driving me up a wall. I was reading the reason behind the current rule choice and I think ruby19 would fit just as well (encourage 3.1 syntax but allow hash rockets if one isn't a symbol). I don't think this change would make any changes to existing standard projects either, but would allow more flexibility in the future. If not, I'll probably let this go and every time I see this line I'll just cringe. And while @camilopayan told me to say it was his fault, I git blamed and it was definitely @searls.
Also for reference, here is the rule and it's options: https://rubydoc.info/gems/rubocop/RuboCop/Cop/Style/HashSyntax
The text was updated successfully, but these errors were encountered: