Class: Skeptic::Rules::CheckSyntax

Inherits:
Object
  • Object
show all
Defined in:
lib/skeptic/rules/check_syntax.rb

Constant Summary collapse

DESCRIPTION =
'Check the syntax'

Instance Method Summary collapse

Constructor Details

#initialize(enabled = false) ⇒ CheckSyntax

Returns a new instance of CheckSyntax.



8
9
10
# File 'lib/skeptic/rules/check_syntax.rb', line 8

def initialize(enabled = false)
  @errors = []
end

Instance Method Details

#apply_to(code, tokens, sexp) ⇒ Object



12
13
14
15
16
# File 'lib/skeptic/rules/check_syntax.rb', line 12

def apply_to(code, tokens, sexp)
  output, error, status = Open3.capture3 'ruby -c', stdin_data: code
  @errors << "Invalid syntax:\n#{error.gsub(/^/m, '  ')}" unless output.chomp == 'Syntax OK'
  self
end

#nameObject



22
23
24
# File 'lib/skeptic/rules/check_syntax.rb', line 22

def name
  'Syntax check'
end

#violationsObject



18
19
20
# File 'lib/skeptic/rules/check_syntax.rb', line 18

def violations
  @errors
end