Class: Yard::Lint::Validators::Documentation::UndocumentedObjects::Parser
- Inherits:
-
Parsers::Base
- Object
- Parsers::Base
- Yard::Lint::Validators::Documentation::UndocumentedObjects::Parser
- 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
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
-
#call(yard_list_output, config: nil, **_kwargs) ⇒ Array<Hash>
Array with undocumented objects details.
Methods inherited from Parsers::Base
Instance Method Details
#call(yard_list_output, config: nil, **_kwargs) ⇒ Array<Hash>
Returns 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 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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' ) || [] excluded_objects = config&.validator_config( 'Documentation/UndocumentedObjects', 'ExcludedObjects' ) || [] # Ensure patterns are Arrays and sanitize: remove nil, empty, # whitespace-only, and normalize excluded_methods = sanitize_patterns(Array(excluded_methods)) excluded_objects = sanitize_patterns(Array(excluded_objects)) 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 the fully-qualified object name is excluded. Unlike # ExcludedMethods (which matches only the trailing method name # and never applies to classes/modules/constants), # ExcludedObjects matches the whole element - so it can # exclude constants (e.g. "Foo::KEY_A") and lets a regex be # anchored to the full path. next if object_excluded?(element, arity, excluded_objects) # 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 |