Hacker News new | ask | show | jobs
by sergiotapia 4124 days ago
Is there a way to have RuboCop automatically clean up things it detects? Obviously I would run this one file at a time, and git diff it before committing it.
4 comments

Rubocop organizes violations into a set of distinct 'cops', each of which is responsible for checking for a single type of style violation - about half of them can be autocorrected (--auto-correct argument from the command line).

Rather than running it one file at a time, I found that I got an easier to inspect diff by running it one cop at a time. Rubocop simplifies this approach by allowing you to auto-generate a '.rubocop_todo.yml' file that specifies settings for every 'cop' that would allow your project to produce no warnings. Then you just remove one section of config at a time, autocorrect or manually correct all the errors that pop up, and make a commit describing what style change it introduced across the project. In the process, you also gain a full understanding of really what is required by the cops - there are a couple that I have tuned to be more relaxed than the default, because the defaults seem silly (like cyclomatic complexity, and method length).

The -a flag will do this for some of the offenses.
I found it was cleaner to run it with -a (autocorrect) enabling one cop at a time between commits. Less giant patch storm of everything, and more coherent changesets.