Class: Yard::Lint::Validators::Documentation::MarkdownSyntax::MessagesBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/lint/validators/documentation/markdown_syntax/messages_builder.rb

Overview

Builds human-readable messages for MarkdownSyntax violations

Constant Summary collapse

ERROR_DESCRIPTIONS =

Maps markdown syntax error types to human-readable descriptions

{
  'unclosed_backtick' => 'Unclosed backtick in documentation',
  'unclosed_code_block' => 'Unclosed code block (```) in documentation',
  'unclosed_bold' => 'Unclosed bold formatting (**) in documentation',
  'invalid_list_marker' => 'Invalid list marker (use - or * instead)'
}.freeze

Class Method Summary collapse

Class Method Details

.call(offense) ⇒ String

Formats a violation message

Parameters:

  • offense (Hash)

    the offense details

Returns:

  • (String)

    formatted message



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/yard/lint/validators/documentation/markdown_syntax/messages_builder.rb', line 22

def call(offense)
  object_name = offense[:object_name]
  errors = offense[:errors]

  error_messages = errors.map do |error|
    if error.start_with?('invalid_list_marker:')
      line_num = error.split(':').last
      "#{ERROR_DESCRIPTIONS['invalid_list_marker']} at line #{line_num}"
    else
      ERROR_DESCRIPTIONS[error] || error
    end
  end

  "Markdown syntax errors in '#{object_name}': " \
    "#{error_messages.join(', ')}"
end