Skip to content

Don't override `relevant_file?`

Peter Leitzen requested to merge pl-cop-description-example-method-defined into master

What does this MR do and why?

This MR removes the override relevant_file? from InternalAffairs/CopDescriptionWithExample and uses Include configuration directive instead.

In order to make it work we need to remove parent's (InternalAffairs/CopDescription) relevant_file? as well. See https://github.com/rubocop/rubocop/pull/13209#issuecomment-2337963170

How to verify locally?

  1. Add a new file which would cause an offenses for InternalAffairs/CopDescriptionWithExample (placed out side of lib/rubocop/cop).
$ cat lib/rubocop/foo.rb
# frozen_string_literal: true

module RuboCop::Cop
  module Bar
    #
    # OK
    class Baz < Base
      def bar
        23
      end
    end
  end
end
  1. Run rubocop -C false lib/rubocop/foo.rb on this branch - It passes 💚
  2. Revert changes in rubocop-internal-affairs.yml and rerun:
$ be rubocop -C false  lib/rubocop/foo.rb
Inspecting 1 file
C

Offenses:

lib/rubocop/foo.rb:5:1: C: [Correctable] InternalAffairs/CopDescription: Description should not start with an empty comment line.
    # ...
^^^^^
lib/rubocop/foo.rb:5:1: C: [Correctable] InternalAffairs/CopDescriptionWithExample: Description should not start with an empty comment line.
    # ...
^^^^^

1 file inspected, 2 offenses detected, 2 offenses autocorrectable
Edited by Peter Leitzen

Merge request reports