rubocop: Missing top-level class documentation comment.

I’m new to rubocop, and one function is annoying to me.

Why I get Missing top-level class documentation comment. before each class or module definition?

class UsersController < InheritedResources::Base
^^^^^

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 17

Most upvoted comments

Documentation should not be nested under AllCops. It’s a top-level key.

@justinschier You write a comment above it (describing what it is). If you feel that’s unnecessary, you can add a # :nodoc: comment at the end of the first line.

I have the same problem. I have added comment before class

#Your comment
class UsersController < InheritedResources::Base

Using this doesn’t work for me:

AllCops:
  Documentation:
    Enabled: false

However, removing AllCops does the trick:

Documentation:
  Enabled: false

Can I ask what WOULD be the correct way to write my class definition so that it passes the rubocop check?

class LocationFeatureSchedule < ActiveRecord::BasePIOPS2
  belongs_to :location
end

Because it’s a good practice to document top-level (non-namespace) classes and modules. Feel free to disable the check.

@nghiabk change #Your comment into # Your comment that will solve your problem, rubocop wants space between command tag and the description

@bbatsov, why I need to insert the comment before User model & ApplicationController?

This way you duplicate “convention over configuration” principle

According to the document, I think we should use

Style/Documentation:
  Enabled: false

to avoid the doc checking, configure rules with type’s name.

image

Otherwise, without the type’s name, I will get this warning(I am working in version 0.88)

/xxxxxx/.rubocop.yml: Warning: no department given for Documentation.

You’re thinking mostly in terms of your particular use-case. While in a webapp controller documentation might not be essential, it’s crucial in many other apps and libraries. It’s also a good practice to document models, helpers, service classes, etc. As I said - if you don’t find a cop useful - just disable it (in master cops can also be disabled for particular files/folder).

I came across this issue via Google, but before that I was struggling to figure out how to disable the class docs warning.

Should Documentation be added to https://github.com/bbatsov/rubocop/blob/master/config/default.yml? The README directs people there to discover the default options.