lib/codeqa/checkers/rubocop_full.rb in codeqa-0.4.0.pre vs lib/codeqa/checkers/rubocop_full.rb in codeqa-0.4.0.pre2
- old
+ new
@@ -1,6 +1,6 @@
-require 'ostruct'
+require 'multi_json'
module Codeqa
module Checkers
class Rubocop < Checker
def self.check?(sourcefile)
@@ -43,28 +43,28 @@
def default_args
%w(--format json)
end
def handle_rubocop_results(raw)
- data = JSON.parse raw, :object_class => OpenStruct
- data.files.
- reject{ |f| f.offenses.empty? }.
- each do |file|
- file.offenses.each do |offense|
- position = [offense.location.line, offense.location.column]
- errors.add(position, "#{offense.cop_name}: #{offense.message}")
- end
- end
+ MultiJson.load(raw)['files'].
+ reject{ |f| f['offenses'].empty? }.
+ each do |file|
+ file['offenses'].each do |offense|
+ position = [offense['location']['line'], offense['location']['column']]
+ errors.add(position, "#{offense['cop_name']}: #{offense['message']}")
+ end
+ end
end
def self.rubocop?
@loaded ||= begin
require 'rubocop'
true
end
end
# Since using the json format we only care about stdout
- # stderr will be silent
+ # stderr will be silenced
+ # (internal rubocop errors/warning will be printed there)
def capture
$stdout, stdout = StringIO.new, $stdout
$stderr, stderr = StringIO.new, $stderr
result = yield
# [result, $stdout.string + $stderr.string]