Class: Yard::Lint::Validators::Documentation::UndocumentedObjects::Parser

Inherits:
Parsers::Base
  • Object
show all
Defined in:
lib/yard/lint/validators/documentation/undocumented_objects/parser.rb

Overview

Class used to extract details about undocumented objects from raw yard list output

Examples:

Output format (skip-lint)

/path/to/file.rb:3: UndocumentedClass
/path/to/file.rb:4: UndocumentedClass#method_one|2

Constant Summary collapse

LINE_REGEX =

Regex used to parse yard list output format Format: file.rb:LINE: ObjectName or ObjectName|ARITY

/^(.+):(\d+): (.+?)(?:\|(\d+))?$/

Instance Method Summary collapse

Methods inherited from Parsers::Base

#match

Instance Method Details

#call(yard_list_output, config: nil, **_kwargs) ⇒ Array<Hash>

Returns Array with undocumented objects details.

Parameters:

  • yard_list_output (String)

    raw yard list results string

  • config (Yard::Lint::Config, nil) (defaults to: nil)

    configuration object (optional)

  • _kwargs (Hash)

    a customizable set of options

Options Hash (**_kwargs):

  • :unused (Object)

    this parameter accepts no options (reserved for future use)

Returns:

  • (Array<Hash>)

    Array with undocumented objects details



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yard/lint/validators/documentation/undocumented_objects/parser.rb', line 21

def call(yard_list_output, config: nil, **_kwargs)
  excluded_methods = config&.validator_config(
    'Documentation/UndocumentedObjects',
    'ExcludedMethods'
  ) || []

  # Ensure excluded_methods is an Array
  excluded_methods = Array(excluded_methods)

  # Sanitize patterns: remove nil, empty, whitespace-only, and normalize
  excluded_methods = sanitize_patterns(excluded_methods)

  yard_list_output
    .split("\n")
    .map(&:strip)
    .reject(&:empty?)
    .filter_map do |line|
      match = line.match(LINE_REGEX)
      next unless match

      element = match[3]
      arity = match[4]&.to_i

      # Skip if method is in excluded list
      next if method_excluded?(element, arity, excluded_methods)

      {
        location: match[1],
        line: match[2].to_i,
        element: element
      }
    end
end