Table of Contents
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.
- Missing top-level class documentation comment. [Style/Documentation]
You can disable or fix this warning using either of the 3 options:
- Disable cop in configuration file
- Disable cop in only one class
- Add comment just above the class declaration
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
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
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
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.