DEV Community

Cover image for [Fix] Missing top level class documentation comment Rubocop
Prabin Poudel for Truemark Technology

Posted on • Updated on • Originally published at thedevpost.com

[Fix] Missing top level class documentation comment Rubocop

Rubocop is the best way to enforce best practices in our rails project. While working on the project with rubocop enabled, it's normal to stumble upon the warning: Missing top-level class documentation comment. [Style/Documentation]. When this happens, we have three options to fix or disable the warning.

Warning

  • Missing top-level class documentation comment. [Style/Documentation]

Options Available for Fix

You can disable or fix this warning using either of the 3 options:

  1. Disable cop in the project
  2. Disable cop in only one class
  3. Add comment just above the class declaration

Option 1: Disable cop in the project

Most of the classes we use are self describing, meaning as a developer, you can easily make sense of what the class is doing. Normally I find this rule not very useful, so most of the time I disable it in the whole project. Add the following cop to your configuration file to disable it project wide:

# .rubocop.yml

Style/Documentation:
  Enabled: false
Enter fullscreen mode Exit fullscreen mode

Option 2: Disable cop in only one class

If you feel this cop is important in your project and don't want to disable it in the configuration file, then you can disable it in only one class as required.

# app/models/user.rb

# rubocop:disable Style/Documentation
class User
end
Enter fullscreen mode Exit fullscreen mode

Option 3: Add comment just above the class declaration

You can also make the warning go away by adding the comment as warning suggests.

# app/models/user.rb

# Service to download ftp files from the server
class FtpService
end
Enter fullscreen mode Exit fullscreen mode

Though this article is specific to resolving Missing top-level class documentation comment. [Style/Documentation], this fix also works on every other warning that rubocop throws. Did I miss any option that you are using? Let me know in the comments below.

Image Credits: Cover Image by Matt Popovich on Unsplash

Top comments (0)