Is it possible to enable rules in Rubocop only for new classes
I would like to enable ClassLength rule on Rubocop but only for new classes such that we don't start getting alerts for all the legacy code. Is it possible to do?
You can ignore your legacy files in .rubocop.yml, either as a long list or as a few globs if you can isolate them into directories.
Metrics/ClassLength: Exclude: - 'one/file' - 'another/file' - 'some/dir/*'
If there are just a few really bad offenders but the rest are over the default (100 lines), you can pick a higher threshold.
Metrics/ClassLength: max: 200
You can also add annotations to disable cops in each of the files where you want to ignore Metrics/ClassLength:
# rubocop:disable Metrics/ClassLength class SuperLongScaryThing # ... end # rubocop:enable Metrics/ClassLength
And of course, you can always do some refactoring!