Class: Ruber::SyntaxChecker::YamlSyntaxChecker

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

Overview

Class which checks the syntax of a ruby file.

It calls the YAML.load method on the document’s content within a begin/rescue block, rescuing any ArgumentError exception. The message of the exception is used to find information about the error

Instance Method Summary (collapse)

Constructor Details

- (YamlSyntaxChecker) initialize(doc)

Creates a new instance

Parameters:

  • doc (Document)

    the document to check



563
564
# File 'plugins/syntax_checker/syntax_checker.rb', line 563

def initialize doc
end

Instance Method Details

- (String) check(str)

Checks the syntax of the given string.

concerning syntax errors or an empty string if there were no syntax error

Parameters:

  • str (String)

    the string to check (usually, it’ll be the document’s text)

Returns:

  • (String)

    a string containing the lines of output produced by YAML.load



573
574
575
576
577
578
579
580
# File 'plugins/syntax_checker/syntax_checker.rb', line 573

def check str
  begin 
    YAML.load str
    ''
  rescue ArgumentError => e
    e.message
  end
end

- (<SyntaxCheckerPlugin::ErrorDescription>) convert_check_result(str)

Parses the output of #check

corresponding to the syntax errors mentioned in str

Parameters:

  • str (String)

    the string to parse.

Returns:



589
590
591
592
593
594
# File 'plugins/syntax_checker/syntax_checker.rb', line 589

def convert_check_result str
  return [] if str.empty?
  str.match(/^syntax error on line (\d+), col (\d+): `(.*)'$/)
  error = SyntaxCheckerPlugin::ErrorDescription.new $1.to_i, 'Syntax error', $3.to_s, $2.to_i
  [error]
end