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.
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)
- Run RuboCop autocorrect, which removes redundant disable comments.
- Review the removed comments.
- Re-run RuboCop to confirm the offense is gone.
bundle exec rubocop -aDelete 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.