Class: Yamlint::Rules::KeyOrdering

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

Defined Under Namespace

Classes: KeyOrderHandler

Instance Attribute Summary

Attributes inherited from Base

#config, #level

Instance Method Summary collapse

Methods inherited from Base

defaults, desc, #fixable?, 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
# File 'lib/yamlint/rules/key_ordering.rb', line 12

def check(context)
  handler = KeyOrderHandler.new
  parser = Psych::Parser.new(handler)
  handler.parser = parser

  begin
    parser.parse(context.content)
  rescue Psych::SyntaxError
    return []
  end

  handler.problems.map do |prob|
    problem(
      line: prob[:line],
      column: prob[:column],
      message: "wrong ordering of key \"#{prob[:key]}\" (should be before \"#{prob[:prev_key]}\")",
      fixable: false
    )
  end
end