module Nexocop::Rubocop
Public Class Methods
available?()
click to toggle source
# File lib/nexocop/rubocop.rb, line 8 def self.available? !rubocop_cmd.empty? end
count_files(rubocop_json)
click to toggle source
# File lib/nexocop/rubocop.rb, line 52 def self.count_files(rubocop_json) rubocop_json['files'].count end
count_offenses(rubocop_json)
click to toggle source
# File lib/nexocop/rubocop.rb, line 45 def self.count_offenses(rubocop_json) rubocop_json['files'] .map { |file| file['offenses'] } .map(&:count) .reduce(:+) end
has_offenses?(rubocop_json)
click to toggle source
# File lib/nexocop/rubocop.rb, line 38 def self.has_offenses?(rubocop_json) rubocop_json['files'] .map { |file| file['offenses'] } .map(&:count) .any?(&:positive?) end
offense_in_diff?(offense, changed_lines)
click to toggle source
# File lib/nexocop/rubocop.rb, line 26 def self.offense_in_diff?(offense, changed_lines) # make sure this offense is in a file that has changed return false unless changed_lines.key?(offense['path']) changed_lines[offense['path']].any? do |line_range| start_line = offense['location']['start_line'] last_line = offense['location']['last_line'] range = (line_range[0]..line_range[1]) (start_line..last_line).to_a.any? { |line_num| range.include?(line_num) } end end
rubocop_cmd()
click to toggle source
# File lib/nexocop/rubocop.rb, line 12 def self.rubocop_cmd if Sh.run_command('which bundle >/dev/null 2>&1').success? 'bundle exec rubocop' elsif Sh.run_command('which rubocop >/dev/null 2>&1').success? 'rubocop' else '' end end
run(rubocop_args)
click to toggle source
# File lib/nexocop/rubocop.rb, line 22 def self.run(rubocop_args) Sh.run_command("#{rubocop_cmd} #{rubocop_args.join(' ')}") end