Class: Yard::Lint::Validators::Documentation::MarkdownSyntax::Validator
- Inherits:
-
Base
- Object
- Base
- Yard::Lint::Validators::Documentation::MarkdownSyntax::Validator
- Defined in:
- lib/yard/lint/validators/documentation/markdown_syntax/validator.rb
Overview
Validates markdown syntax in documentation
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#in_process_query(object, collector) ⇒ void
Execute query for a single object during in-process execution.
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 markdown syntax errors in docstrings.
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/markdown_syntax/validator.rb', line 18 def in_process_query(object, collector) docstring_text = object.docstring.to_s return if docstring_text.empty? errors = [] # Check for unclosed backticks backtick_count = docstring_text.scan(/`/).count errors << 'unclosed_backtick' if backtick_count.odd? # Check for unclosed code blocks code_block_count = docstring_text.scan(/^```/).count errors << 'unclosed_code_block' if code_block_count.odd? # Check for unclosed bold markers (excluding code sections) non_code_text = docstring_text.gsub(/`[^`]*`/, '') bold_count = non_code_text.scan(/\*\*/).count errors << 'unclosed_bold' if bold_count.odd? # Check for invalid list markers docstring_text.lines.each_with_index do |line, line_idx| stripped = line.strip errors << "invalid_list_marker:#{line_idx + 1}" if stripped.match?(/^[•·]/) end return if errors.empty? collector.puts "#{object.file}:#{object.line}: #{object.title}" collector.puts errors.join('|') end |