How to disable 'warning no department given for 'COP' message on running rubocop

Viewed 8032

In my .rubocop.yml have some config for disabling some of the style cops.

Documentation:
  Enabled: false
ClassAndModuleChildren:
  Enabled: false
LineLength:
  Max: 120
GuardClause:
  Enabled: false
IfUnlessModifier: 
  Enabled: false

When running rubocop in the terminal it works fine and disables the unwanted style cops and lints as usual but every time it runs i get this warning error for all the disabled cops:

Warning: no department given for Documentation.

Is there a way of disabling the warning message?

1 Answers

A qualified cop name is Department/CopName. For example, Style/Documentation is qualified and Documentation is unqualified.

The documentation indicates that:

Qualifying cop name with its type, e.g., Style, is recommended, but not necessary as long as the cop name is unique across all types.

But they show a warning for unqualified names. That happens here:

# RuboCop::Cop::Registry
def qualified_cop_name(name, path, shall_warn = true)
  badge = Badge.parse(name)
  if shall_warn && department_missing?(badge, name)
    print_warning(name, path)
  end
  return name if registered?(badge)

  potential_badges = qualify_badge(badge)

  case potential_badges.size
  when 0 then name # No namespace found. Deal with it later in caller.
  when 1 then resolve_badge(badge, potential_badges.first, path)
  else raise AmbiguousCopName.new(badge, path, potential_badges)
  end
end

shall_warn is only false when the --auto-correct option is in use. There isn't a way to disable it currently.

The only way to silence the warning is to include the department for each cop in your config like:

Style/Documentation:
  Enabled: false
Style/ClassAndModuleChildren:
  Enabled: false
Metrics/LineLength:
  Max: 120
Style/GuardClause:
  Enabled: false
Style/IfUnlessModifier: 
  Enabled: false
Related