class Renegade::Linters
Run linters
Attributes
errors[R]
Public Class Methods
new(label, extension, exec_command)
click to toggle source
# File lib/renegade/linters.rb, line 9 def initialize(label, extension, exec_command) # Instance variables @label = label @extension = extension @exec_command = exec_command @errors = [] end
Public Instance Methods
append_file_count(files)
click to toggle source
Add the file count to the end of the label
# File lib/renegade/linters.rb, line 30 def append_file_count(files) file_size = files.size label_count = (file_size == 0 || file_size > 1) ? "#{file_size} files" : '1 file' @label = "#{@label} (#{label_count})" end
exec(files)
click to toggle source
# File lib/renegade/linters.rb, line 39 def exec(files) # http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby stdin, stdout, stderr, wait_thread = Open3.popen3(@exec_command + " #{files.join(' ')}") @errors.push(stdout.read) if wait_thread.value.exitstatus == 1 stdin.close stdout.close stderr.close wait_thread.value.exitstatus == 0 end
filter_files(file_list)
click to toggle source
# File lib/renegade/linters.rb, line 53 def filter_files(file_list) filtered_files = [] file_list.each do |file| filtered_files.push(file) if File.extname(file) == @extension end filtered_files end
run(files)
click to toggle source
# File lib/renegade/linters.rb, line 17 def run(files) files = filter_files(files) append_file_count(files) # Only run check if there are relevant files being committed if files.empty? Status.report(@label, true) else Status.report(@label, exec(files)) end end