Class: Yard::Lint::Validators::Documentation::UndocumentedOptions::Validator

Inherits:
Base
  • Object
show all
Defined in:
lib/yard/lint/validators/documentation/undocumented_options/validator.rb

Overview

Validates that methods with options hash parameters have @option tags

Instance Attribute Summary

Attributes inherited from Base

#config, #selection

Instance Method Summary collapse

Methods inherited from Base

in_process, in_process?, in_process_visibility, #initialize, validator_name

Constructor Details

This class inherits a constructor from Yard::Lint::Validators::Base

Instance Method Details

#in_process_query(object, collector) ⇒ void

This method returns an undefined value.

Execute query for a single object during in-process execution. Finds methods with options parameters but no @option tags.

Parameters:

  • object (YARD::CodeObjects::Base)

    the code object to query

  • collector (Executor::ResultCollector)

    collector for output



18
19
20
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
# File 'lib/yard/lint/validators/documentation/undocumented_options/validator.rb', line 18

def in_process_query(object, collector)
  # Only check method objects
  return unless object.is_a?(YARD::CodeObjects::MethodObject)
  return if parent_class_allowed?(object)

  params = object.parameters || []

  # Check for options-style parameters
  has_options_param = params.any? do |p|
    param_name = p[0].to_s
    # Match options, option, opts, opt, kwargs or double-splat (**)
    param_name.match?(/^(options?|opts?|kwargs)$/) ||
      param_name.start_with?('**')
  end

  return unless has_options_param

  # A named (non-splat) parameter documented with a concrete
  # non-Hash type (via its param tag) is not an options hash, so it
  # does not need option tags.
  return if options_param_documented_as_non_hash?(object)

  # Check if @option tags are missing
  option_tags = object.tags(:option)
  return unless option_tags.empty?

  # Output method location and parameter info
  collector.puts "#{object.file}:#{object.line}: #{object.title}"
  collector.puts params.map { |p| p.join(' ') }.join(', ')
end