Class: RuboCop::Cop::Style::Documentation
- Includes:
- DocumentationComment, ProjectIndexHelp, RangeHelp
- Defined in:
- lib/rubocop/cop/style/documentation.rb
Overview
Checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, constant definitions or constant visibility declarations.
The documentation requirement is annulled if the class or module has
a #:nodoc: comment next to it. Likewise, #:nodoc: all does the
same for all its children.
When AllCops/UseProjectIndex is enabled and the rubydex gem is
installed, a reopened class or module is not reported when any of its
other definition sites (in the same or another file) carries a
documentation comment.
Constant Summary collapse
- MSG =
'Missing top-level documentation comment for `%<type>s %<identifier>s`.'- DIRECTIVE_COMMENT_REGEXP =
Comments that configure tooling rather than document the code.
/\A\#\s*(rubocop:|frozen_string_literal:|encoding:| shareable_constant_value:|typed:|-\*-)/x.freeze
Constants included from RangeHelp
RangeHelp::BYTE_ORDER_MARK, RangeHelp::NOT_GIVEN
Constants included from ProjectIndexHelp
ProjectIndexHelp::BUILTIN_DOCUMENT_URI, ProjectIndexHelp::FILE_URI_PREFIX, ProjectIndexHelp::WINDOWS_DRIVE_PREFIX
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#config, #processed_source, #project_index
Instance Method Summary collapse
- #constant_definition?(node) ⇒ Object
- #constant_visibility_declaration?(node) ⇒ Object
- #include_statement?(node) ⇒ Object
- #on_class(node) ⇒ Object
- #on_module(node) ⇒ Object
- #outer_module(node) ⇒ Object
Methods included from ProjectIndexHelp
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, #always_autocorrect?, autocorrect_incompatible_with, badge, #begin_investigation, #callbacks_needed, callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #contextual_autocorrect?, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_new_investigation, #on_other_file, #parse, #parser_engine, #ready, #relevant_file?, requires_gem, #string_literals_frozen_by_default?, support_autocorrect?, support_multiple_source?, #target_gem_version, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
cop_dir_for, #exclude_limit, read_limits
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Instance Method Details
#constant_definition?(node) ⇒ Object
89 |
# File 'lib/rubocop/cop/style/documentation.rb', line 89 def_node_matcher :constant_definition?, '{class module casgn}' |
#constant_visibility_declaration?(node) ⇒ Object
95 96 97 |
# File 'lib/rubocop/cop/style/documentation.rb', line 95 def_node_matcher :constant_visibility_declaration?, <<~PATTERN (send nil? {:public_constant :private_constant} ({sym str} _)) PATTERN |
#include_statement?(node) ⇒ Object
100 101 102 |
# File 'lib/rubocop/cop/style/documentation.rb', line 100 def_node_matcher :include_statement?, <<~PATTERN (send nil? {:include :extend :prepend} const) PATTERN |
#on_class(node) ⇒ Object
104 105 106 107 108 |
# File 'lib/rubocop/cop/style/documentation.rb', line 104 def on_class(node) return unless node.body check(node, node.body) end |
#on_module(node) ⇒ Object
110 111 112 |
# File 'lib/rubocop/cop/style/documentation.rb', line 110 def on_module(node) check(node, node.body) end |
#outer_module(node) ⇒ Object
92 |
# File 'lib/rubocop/cop/style/documentation.rb', line 92 def_node_search :outer_module, '(const (const nil? _) _)' |