Running a specific Cop in Rubocop

Problem

You are working on an existing rails project with many rubocop warnings and you would like to fix certain types or warnings by getting only the specified files.

Solution

So for example when you use rubocop you first get the following for all the files in the project:

rubocop
799 files inspected, 17214 offenses detected

You can get a grouping of the errors by using the following:

rubocop --format offenses
7176 Style/StringLiterals
3596 Metrics/LineLength
1031 Style/VariableName
790  Style/IndentationConsistency
548  Style/SpaceAroundOperators
423  Style/Documentation
415  Style/HashSyntax
386  Style/TrailingWhiteSpace
198  Style/SpaceAfterComma
...

If you would like to know only the files for a certain type of warning to be able to fix them you could try the following:

rubocop --only Style/TrailingWhitespace
..... list of files
799 files inspected, 386 offenses detected