]>
Commit | Line | Data |
---|---|---|
9be00a32 MM |
1 | require 'pronto' |
2 | require 'eslintrb' | |
3 | ||
4 | module Pronto | |
5 | class ESLint < Runner | |
b338a7ad MM |
6 | def run |
7 | return [] unless @patches | |
9be00a32 | 8 | |
b338a7ad | 9 | @patches.select { |patch| patch.additions > 0 } |
9be00a32 MM |
10 | .select { |patch| js_file?(patch.new_file_full_path) } |
11 | .map { |patch| inspect(patch) } | |
12 | .flatten.compact | |
13 | end | |
14 | ||
15 | def inspect(patch) | |
16 | options = File.exist?('.eslintrc') ? :eslintrc : :defaults | |
17 | offences = Eslintrb.lint(patch.new_file_full_path, options).compact | |
18 | ||
19 | offences.map do |offence| | |
20 | patch.added_lines.select { |line| line.new_lineno == offence['line'] } | |
21 | .map { |line| new_message(offence, line) } | |
22 | end | |
23 | end | |
24 | ||
25 | def new_message(offence, line) | |
26 | path = line.patch.delta.new_file[:path] | |
27 | level = :warning | |
28 | ||
b338a7ad | 29 | Message.new(path, line, level, offence['message'], nil, self.class) |
9be00a32 MM |
30 | end |
31 | ||
32 | def js_file?(path) | |
d0d228c9 | 33 | %w(.js .es6 .js.es6).include? File.extname(path) |
9be00a32 MM |
34 | end |
35 | end | |
36 | end |