Class: Yard::Lint::Validators::Documentation::BlankLineBeforeDefinition::Validator

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

Overview

Validates blank lines between documentation and definitions

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. Checks for blank lines between documentation blocks and definitions.

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

def in_process_query(object, collector)
  return unless object.file && File.exist?(object.file) && object.line.to_i > 1

  source_lines = File.readlines(object.file)
  definition_line = object.line - 1

  blank_count, has_doc_block = analyze_spacing(source_lines, definition_line)

  return if blank_count.zero? || !has_doc_block

  violation_type = blank_count >= 2 ? 'orphaned' : 'single'

  return unless pattern_enabled?(violation_type)

  collector.puts "#{object.file}:#{object.line}: #{object.title}"
  collector.puts "#{violation_type}:#{blank_count}"
end