Class: Rubocop::Cop::Syntax
Instance Attribute Summary
Attributes inherited from Cop
#correlations, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, #has_report?, inherited, #initialize
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#inspect(file, source, tokens, sexp) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubocop/cop/syntax.rb', line 8 def inspect(file, source, tokens, sexp) stderr = nil # it's extremely important to run the syntax check in a # clean environment - otherwise it will be extremely slow if defined? Bundler Bundler.with_clean_env do _, stderr, _ = Open3.capture3('ruby -wc', stdin_data: source.join("\n")) end else _, stderr, _ = Open3.capture3('ruby -wc', stdin_data: source.join("\n")) end stderr.each_line do |line| # discard lines that are not containing relevant info if line =~ /.+:(\d+): (.+)/ line_no, severity, = process_line(line) add_offence(severity, line_no, ) end end end |
#process_line(line) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/syntax.rb', line 32 def process_line(line) line_no, = line.match(/.+:(\d+): (.+)/).captures if .start_with?('warning: ') [line_no.to_i, :warning, .sub(/warning: /, '').capitalize] else [line_no.to_i, :error, .capitalize] end end |