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?

Answers


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!


Need Your Help

Access a secure cookie from a Greasemonkey script?

firefox cookies firefox-addon greasemonkey cookie-httponly

Is there anyway to access a secure cookie from a Greasemonkey script?

Executing SQLLDR from within a PL-SQL procedure

oracle plsql sql-loader

Hello and thanks in advance. I am running Oracle 11gR2 and want to try to execute an sql loader to insert data into an existing table. I am attempting this via Java stored proc in the database that...