21

Rubycop outputs messages like:

app/controllers/welcome_controller.rb:1:1: C: Missing top-level class documentation comment.
class WelcomeController < ApplicationController
^^^^^

I wonder what does top-level class documentation look like. It's not just a comment, is it? It needs to have a special format, but which one?

  • It's telling you that you need to have documentation "comment" for a "top-level class" which in this case is WelcomeController. Add a comment above the class definition to prevent this message. There may also be other ways to get rid of this message. See documentation for rubocop for details. – vee Apr 6 '16 at 17:12
  • @vee I tried adding a comment below the class definition. Thanks. – DreamWalker Apr 6 '16 at 17:17
  • To overcome the need to add a real comment you could add #:nodoc: at the top of the file – Andrey Deineko Apr 6 '16 at 18:19
32

That said a simple comment like so will do nicely:

# This shiny device polishes bared foos
class FooBarPolisher
       ...

HTH

9

From the Rubocop documentation:

RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.

The Ruby Style Guide "comment" section doesn't use the phrase "Missing top-level class documentation comment" but from reading the guide section on comments, you can quickly infer from the examples that commenting classes and modules is recommended.

The reason is, when using rdoc, the comments for the classes/modules will be used to generate the reference to the code, something that is important whether you're writing code for yourself, for a team or for general release by others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.