Sha256: 0135e07fd63e5294036656466fc43473bb4682e54934fc26ffdbf49acad8510b
Contents?: true
Size: 1.71 KB
Versions: 3
Compression:
Stored size: 1.71 KB
Contents
# encoding: utf-8 module Rubocop module Cop module Style # This cop 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 or other other modules. class Documentation < Cop MSG = 'Missing top-level %s documentation comment.' def inspect(source_buffer, source, tokens, ast, comments) return unless ast ast_with_comments = Parser::Source::Comment.associate(ast, comments) check_classes(ast, ast_with_comments) check_modules(ast, ast_with_comments) end private def check_classes(ast, ast_with_comments) on_node(:class, ast) do |node| _name, _superclass, body = *node if body != nil && ast_with_comments[node].empty? add_offence(:convention, node.loc.keyword, format(MSG, 'class')) end end end def check_modules(ast, ast_with_comments) on_node(:module, ast) do |node| _name, body = *node if body.nil? namespace = false elsif body.type == :begin namespace = body.children.all? do |n| [:class, :module].include?(n.type) end elsif body.type == :class || body.type == :module namespace = true else namespace = false end if !namespace && ast_with_comments[node].empty? add_offence(:convention, node.loc.keyword, format(MSG, 'module')) end end end end end end end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
rubocop-0.9.1 | lib/rubocop/cop/style/documentation.rb |
sabat-rubocop-0.9.0 | lib/rubocop/cop/style/documentation.rb |
rubocop-0.9.0 | lib/rubocop/cop/style/documentation.rb |