fables-tales / rubyfmt

Ruby Autoformatter!
MIT License
1.08k stars 50 forks source link

Respecting rubocop config? #445

Closed pjg closed 9 months ago

pjg commented 1 year ago

Is it possible to configure ruby-fmt to respect the project's rubocop config when using ruby-fmt?

reese commented 10 months ago

A lot of the selling point for rubyfmt is it's basically not configurable (and it would be pretty painful to try and keep it in sync with another project's configuration formats and so on -- at that point you may as well just use rubocop for formatting). Realistically, I would imagine something like #424 is probably the better path forward, which would be somehow maintaining a list of cops to disable that conflict between the two.

pjg commented 9 months ago

I agree. With time I came to the conclusion that rubyfmt is/should be a tool standing independently from rubocop. There could be a bridge tool, something like rubyfmt-rubocop-config, which would disable all necessary rubocop rules conflicting with rubyfmt (in the spirit of eslint-config-prettier) as mentioned in #424.

FWIW I was able to configure my editor (vim) to run rubyfmt first, and then run rubocop on its output (in the spirit of prettier-eslint). This allowed me to "correct" most of the rubyfmt's styling choices I didn't like (double quotes, spaces inside hash literals, etc) with one big exception: parentheses.

The way rubyfmt force adds parentheses to almost everything hurts my eyes. Unfortunately it is impossible to configure rubocop to correct rubyfmt's output in this regard. It's only all parenthesis or no parenthesis there, with no way to configure rubocop to remove parentheses from a subset of methods.

Current list of exceptions when adding parenthesis only makes things inconsistent, and doesn't really help/do much.

And this force adding of parenthesis is one of the issues (the other being missing ruby 3.0+ features/compatibility) prevents me from using rubyfmt, which makes me sad because I love this tool. rubyfmt could, of course, not force add parentheses to everything (instead looking at the original code and keeping only what parentheses the user had originally), but I don't believe it will happen.

All in all, I believe this issue can be closed.