class Pronto::ESLint
Public Instance Methods
inspect(patch)
click to toggle source
# File lib/pronto/eslint.rb, line 15 def inspect(patch) offences = Eslintrb.lint(patch.new_file_full_path, options).compact fatals = offences.select { |offence| offence['fatal'] } .map { |offence| new_message(offence, nil) } return fatals if fatals && !fatals.empty? offences.map do |offence| patch.added_lines.select { |line| line.new_lineno == offence['line'] } .map { |line| new_message(offence, line) } end end
js_file?(path)
click to toggle source
# File lib/pronto/eslint.rb, line 46 def js_file?(path) %w[.js .es6 .js.es6 .jsx].include?(File.extname(path)) end
new_message(offence, line)
click to toggle source
# File lib/pronto/eslint.rb, line 37 def new_message(offence, line) path = line ? line.patch.delta.new_file[:path] : '.eslintrc' level = line ? :warning : :fatal message = offence['message'] message = "#{offence['ruleId']}: #{message}" if offence['ruleId'] Message.new(path, line, level, message, nil, self.class) end
options()
click to toggle source
# File lib/pronto/eslint.rb, line 29 def options if ENV['ESLINT_CONFIG'] JSON.parse(IO.read(ENV['ESLINT_CONFIG'])) else File.exist?('.eslintrc') ? :eslintrc : :defaults end end
run()
click to toggle source
# File lib/pronto/eslint.rb, line 6 def run return [] unless @patches @patches.select { |patch| patch.additions > 0 } .select { |patch| js_file?(patch.new_file_full_path) } .map { |patch| inspect(patch) } .flatten.compact end