Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rubocop

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?

like image 415
Christian Bell Avatar asked Oct 03 '19 11:10

Christian Bell


People also ask

How do I disable Rubocop police?

If you want to disable a cop that inspects comments, you can do so by adding an "inner comment" on the comment line. Running rubocop --autocorrect --disable-uncorrectable will create comments to disable all offenses that can't be automatically corrected.

Where is Rubocop located?

The default configuration for RuboCop is placed in its configuration home directory ( ~/. config/rubocop/default. yml ), and all other config files inherit from it.


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
like image 191
cschroed Avatar answered Sep 22 '22 21:09

cschroed