Sha256: f9672e41507ad6d1ae9386ccc98fa21ad2d02da378ba5da6a9d826c037529900
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
require 'json' require 'rubocop' require 'face_control/comment' module FaceControl module Inputs class RubocopJson attr_accessor :ignored_severities, :filename def initialize(ignored_severities = [], filename = 'rubocop.json') self.ignored_severities = ignored_severities self.filename = filename fail "#{filename} does not exist" unless File.exist?(filename) end def comments report['files'].map do |file| file['offenses'].reject do |offense| ignored_severities.include?(offense['severity']) end.map do |offense| Comment.new( file: file['path'], line: offense['location']['line'], text: text(offense, file) ) end end.flatten end private def report JSON.parse(File.read(filename)) end def text(offense, file) text = offense['message'] if (link = style_guide_url(offense)) text << " — [Guide](#{link})" end if can_be_autocorrected?(offense) text << " (Run `rubocop -a #{file['path']}` to fix.)" end text end def style_guide_url(offense) cop_name = offense['cop_name'] cop_config = RuboCop::ConfigLoader.default_configuration[cop_name] cop_config['StyleGuide'] end def can_be_autocorrected?(offense) !offense['corrected'].nil? end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
face_control-0.6.0 | lib/face_control/inputs/rubocop_json.rb |
face_control-0.5.1 | lib/face_control/inputs/rubocop_json.rb |
face_control-0.5.0 | lib/face_control/inputs/rubocop_json.rb |