Parallel autocorrection is now possible and the default since Rubocop 1.32
The rubocop
binary has a few interesting flags:
rubocop
(using the --parallel
default ) scans the current repository for linting issues while using multiple CPU coresrubocop -a
(or --autocorrect
) safely corrects most offenses while doing a sequential scan
rubocop -A
(or --autocorrect-all
) also tries to correct unsafe suggestionsAutocorrection takes significantly longer on large projects because of the sequential nature.
To speed things up, you can use the following alias. It first checks in parallel if any files need to be corrected, then passes them to the autocorrection command:
alias fixcops="bundle exec rubocop -p | grep -P \"\A[^:]+(?=:\d+:\d+: )\" --only-matching | xargs --no-run-if-empty bundle exec rubocop -a"
bundle exec rubocop -p
quickly scans for issues, listing each affected filegrep -P \"\A[^:]+(?=:\d+:\d+: )\" --only-matching
searches for those file namesxargs --no-run-if-empty bundle exec rubocop -a
only runs autocorrection on selected files if there are any