Skip to content

--disable-pending-cops causes rubocop false positives #782

Closed

Description

@mattbrictson

Overcommit 0.59.0 added --disable-pending-cops to the default rubocop flags. This causes rubocop to now report violations in some cases, where before this change it would not.

In my project, I have explicitly configured rubocop via .rubocop.yml to enable all pending cops, like this:

AllCops:
  NewCops: enable

When overcommit 0.59.0 executes rubocop, it specifies --disable-pending-cops, which contradicts and overrides my NewCops: enable setting. This causes a violation to be reported like this:

Warnings on modified lines:
/home/circleci/project/test/system/article_integration_test.rb:4:54: W: [Correctable] Lint/RedundantCopDisableDirective: Unnecessary disabling of `Minitest/MultipleAssertions`.

This is because Minitest/MultipleAssertions is a "pending" cop that I have explicitly opted into using NewCops: enable. The code in question has this comment:

# rubocop:disable Minitest/MultipleAssertions

When overcommit runs rubocop --disable-pending-cops, rubocop now treats the Minitest/MultipleAssertions cop is if it doesn't exist, thus this error:

Unnecessary disabling of `Minitest/MultipleAssertions`

My workaround is to customize my .overcommit.yml to redefine the rubocop flags, like this (i.e. omitting --disable-pending-cops):

RuboCop:
  enabled: true
  flags: ["--format=emacs", "--force-exclusion", "--display-cop-names"]

In my opinion, overcommit should not be passing flags to rubocop that change its behavior. It should limit itself to passing flags that are purely related to command line output, like --format=emacs. If someone wants pending cops to be skipped, they should say so in .rubocop.yml like this:

AllCops:
  NewCops: disable

Why is overcommit overriding this setting?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions