Class: Ruber::YAMLSyntaxChecker::Checker

Inherits:
Object
  • Object
show all
Defined in:
plugins/yaml_syntax_checker/yaml_syntax_checker.rb,
plugins/yaml_syntax_checker/yaml_syntax_checker.rb,
plugins/yaml_syntax_checker/yaml_syntax_checker.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) check_syntax(str, format)



43
44
45
46
47
48
49
50
51
52
53
54
# File 'plugins/yaml_syntax_checker/yaml_syntax_checker.rb', line 43

def check_syntax str, format
  begin 
    YAML.parse str
    nil
  rescue ArgumentError => e
    match = e.message.match %r{syntax error on line\s+(-?\d+),\s+col\s+(-?\d+)}i
    return [] unless match
    line = [match[1].to_i, 0].max
    col = [match[2].to_i, 0].max
    [SyntaxError.new(line, col, 'Syntax error', 'Syntax error')]
  end
end