Skip to content
Latchkey

RuboCop "Unnecessary disabling" (RedundantCopDisableDirective) in CI

The Lint/RedundantCopDisableDirective cop flags a # rubocop:disable comment that is no longer needed because the code under it no longer triggers the disabled cop. The stale directive becomes its own offense.

What this error means

RuboCop reports "W: Lint/RedundantCopDisableDirective: Unnecessary disabling of X" at a # rubocop:disable comment, and the build fails because of it.

RuboCop
app/services/report.rb:3:1: W: Lint/RedundantCopDisableDirective:
Unnecessary disabling of `Metrics/MethodLength`.
# rubocop:disable Metrics/MethodLength
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Common causes

The underlying offense was fixed but the disable stayed

Code was refactored so the cop no longer fires, but the # rubocop:disable comment was left behind and is now redundant.

A cop config change made the directive moot

Loosening a cop or raising a threshold means the disabled cop no longer applies, so its disable comment is unnecessary.

How to fix it

Remove the stale directive (autocorrect)

  1. Run RuboCop autocorrect, which removes redundant disable comments.
  2. Review the removed comments.
  3. Re-run RuboCop to confirm the offense is gone.
Terminal
bundle exec rubocop -a

Delete the comment by hand

Remove the specific # rubocop:disable/# rubocop:enable pair that no longer suppresses anything.

How to prevent it

  • Re-check disable comments when you refactor the code they cover.
  • Let autocorrect clean up redundant directives regularly.
  • Prefer narrowly scoped disables so they fall away with the code.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →