Class: Yamlint::Rules::DocumentStart

Inherits:
Base
  • Object
show all
Defined in:
lib/yamlint/rules/document_start.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #level

Instance Method Summary collapse

Methods inherited from Base

defaults, desc, inherited, #initialize, rule_id

Constructor Details

This class inherits a constructor from Yamlint::Rules::Base

Instance Method Details

#check(context) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/yamlint/rules/document_start.rb', line 12

def check(context)
  return [] if context.empty?

  has_start = context.lines.any? { |line| line.strip == '---' }
  required = @config[:present]

  if required && !has_start
    [problem(
      line: 1,
      column: 1,
      message: 'missing document start "---"',
      fixable: true
    )]
  elsif !required && has_start
    line_number = context.lines.index { |line| line.strip == '---' } + 1
    [problem(
      line: line_number,
      column: 1,
      message: 'found forbidden document start "---"',
      fixable: true
    )]
  else
    []
  end
end

#fixable?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/yamlint/rules/document_start.rb', line 38

def fixable?
  true
end