Class: RuboCop::Cop::Homebrew::PublicApiDocumentation Private

Inherits:
Base
  • Object
show all
Defined in:
rubocops/public_api_documentation.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Ensures that methods/attributes annotated with @api public have proper YARD documentation beyond just the annotation itself. A bare # @api public with no preceding description is not sufficient for public API methods.

Example

# bad
# @api public
sig { returns(String) }
def foo; end

# good
# The name of this object.
#
# @api public
sig { returns(String) }
def foo; end

Constant Summary collapse

MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"`@api public` methods must have a descriptive YARD comment, not just the annotation."
MISSING_INCLUDE_MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"`%<file>s` contains `@api public` but is missing from `Style/Documentation.Include`."
EXTRA_INCLUDE_MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"`%<file>s` is included in `Style/Documentation.Include` but does not contain " \
"`@api public`."

Instance Method Summary collapse

Instance Method Details

#on_new_investigationvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'rubocops/public_api_documentation.rb', line 34

def on_new_investigation
  super

  comments = processed_source.comments
  comments.each do |comment|
    next unless api_public_comment?(comment)

    add_offense(comment) unless descriptive_comment_preceding?(comment)
  end

  documentation_include = config.dig("Style/Documentation", "Include")
  file_path = processed_source.file_path
  return if documentation_include.nil? || file_path.nil?

  api_public_comments = comments.select { |comment| api_public_comment?(comment) }
  relative_path = file_path.sub(%r{.*/Library/Homebrew/}, "")
  included = Array(documentation_include).include?(relative_path)
  if api_public_comments.any? && !included
    add_offense(api_public_comments.first, message: format(MISSING_INCLUDE_MSG, file: relative_path))
  elsif api_public_comments.empty? && included
    add_offense(
      processed_source.ast || processed_source.buffer.source_range,
      message: format(EXTRA_INCLUDE_MSG, file: relative_path),
    )
  end
end