News for hackers. Stuff that matters.
Re:Utilities for refactoring and upgrading Ruby code based o... by kelseydh on Tuesday May 07, 2024 @01:54AM (#40282771)
I find Rubocop extremely over-opinionated and enforcing style conventions I actually disagree with. You can disable rubocop rules, but as far I know you can't specify which style in rubocop you want code refactored to, so in those instances this tool could be of use.
Re:Utilities for refactoring and upgrading Ruby code based o... by lloeki on Tuesday May 07, 2024 @02:51AM (#40283059)
> you can't specify which style in rubocop you want code refactored to

You can, with the per-cop `EnforcedStyle` configuration key.

I hate browsing the Rubocop doc so I just put the cop name with that config key set to a bogus value, then Rubocop yells at me about the invalid value and lists the available ones.

There can be more than EnforcedStyle, e.g see these for Style/HashSyntax (scroll up for examples), which autocorrect will respect:

https://docs.rubocop.org/rubocop/cops_style.html#configurabl...

Re:Utilities for refactoring and upgrading Ruby code based o... by hi-v-rocknroll on Tuesday May 07, 2024 @02:16AM (#40282880)
I would suggest invest more time in configuration and developing cops where missing. Almost/all cops can be turned on or off as per the configuration[0], many have several alternative choices, and numerous options. It takes time and diligence to configure it for a particular coding standard, environment, or for personal preferences. You can make it enforce whatever coding style you want, and with a great deal of nuance and to including codemod transformations. This later bit was used extensively for large scale codemods.

Furthermore, writing a cop is surprisingly painless.

0: https://docs.rubocop.org/rubocop/configuration.html

Re:Utilities for refactoring and upgrading Ruby code based o... by baweaver on Tuesday May 07, 2024 @10:16AM (#40285734)
The testing utilities are also great. The difficulty, I'd say, is inherit to working with ASTs and simplifying it is hard. They tried with Node Pattern, synvert tried with NQL, and I wanted to try with pattern matching and potentially more in-Ruby approaches.

Nothing particularly wrong with any of them, but trying to sort out what's not matching and getting an answer for now "close" a node was is a bit involved. Go far enough down that hole and you hit tree edit distance and Zhang Sha Sha algorithms.

Re:Utilities for refactoring and upgrading Ruby code based o... by dolni on Tuesday May 07, 2024 @09:44AM (#40285378)
Worse than that, Rubocop will complain about things that change the meaning of your code.

For example, Rubocop’s default configuration insists on calling “.zero?” over using “== 0”. Not all objects have a “.zero?” method, and even if they did it isn’t guaranteed to be the same as “== 0”.