Rubocop --only with multiple cops named on the command line?

1.5k Views Asked by At

How can I run rubocop from the command line, for only several cops?

I can run it successfully for a single cop:

rubocop --only Layout/HeredocIndentation 

That works, but I want to run it for multiple cops, all in one pass. I've tried three different variants, without luck:

rubocop --only Rails/Blank --only Layout/HeredocIndentation --only Naming/FileName 
rubocop --only Rails/Blank Layout/HeredocIndentation Naming/FileName 
rubocop --only Rails/Blank, Layout/HeredocIndentation, Naming/FileName 

https://docs.rubocop.org/rubocop/usage/basic_usage.html says:

--only  |  Run only the specified cop(s) and/or cops in the specified departments.

...but doesn't give a syntax example.

How can I run rubocop against only several cops, all given on the command line?

1

There are 1 best solutions below

1
On BEST ANSWER

To run rubocop against several cops named on the command line, separate cops with commas, but NO SPACES:

rubocop --only Rails/Blank,Layout/HeredocIndentation,Naming/FileName