aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pronto/eslint_npm.rb25
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/pronto/eslint_npm.rb b/lib/pronto/eslint_npm.rb
index 4f32e5b..6bbef09 100644
--- a/lib/pronto/eslint_npm.rb
+++ b/lib/pronto/eslint_npm.rb
@@ -3,15 +3,30 @@ require 'shellwords'
3 3
4module Pronto 4module Pronto
5 class ESLintNpm < Runner 5 class ESLintNpm < Runner
6 class << self
7 attr_writer :eslint_executable, :files_to_lint
8
9 def eslint_executable
10 @eslint_executable || 'eslint'.freeze
11 end
12
13 def files_to_lint
14 @files_to_lint || /(\.js|\.es6)$/
15 end
16 end
17
6 def run 18 def run
7 return [] unless @patches 19 return [] unless @patches
8 20
9 @patches.select { |patch| patch.additions > 0 } 21 @patches
22 .select { |patch| patch.additions > 0 }
10 .select { |patch| js_file?(patch.new_file_full_path) } 23 .select { |patch| js_file?(patch.new_file_full_path) }
11 .map { |patch| inspect(patch) } 24 .map { |patch| inspect(patch) }
12 .flatten.compact 25 .flatten.compact
13 end 26 end
14 27
28 private
29
15 def inspect(patch) 30 def inspect(patch)
16 @_repo_path ||= @patches.first.repo.path 31 @_repo_path ||= @patches.first.repo.path
17 32
@@ -25,8 +40,6 @@ module Pronto
25 end 40 end
26 end 41 end
27 42
28 private
29
30 def new_message(offence, line) 43 def new_message(offence, line)
31 path = line.patch.delta.new_file[:path] 44 path = line.patch.delta.new_file[:path]
32 level = :warning 45 level = :warning
@@ -35,18 +48,18 @@ module Pronto
35 end 48 end
36 49
37 def js_file?(path) 50 def js_file?(path)
38 %w(.js .es6 .js.es6).include?(File.extname(path)) 51 self.class.files_to_lint =~ path.to_s
39 end 52 end
40 53
41 def run_eslint(patch) 54 def run_eslint(patch)
42 Dir.chdir(@_repo_path) do 55 Dir.chdir(@_repo_path) do
56 escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s)
43 JSON.parse( 57 JSON.parse(
44 `eslint #{Shellwords.escape(patch.new_file_full_path.to_s)} -f json` 58 `#{self.class.eslint_executable} #{escaped_file_path} -f json`
45 ) 59 )
46 end 60 end
47 end 61 end
48 62
49 # rubocop:disable Metrics/LineLength
50 def clean_up_eslint_output(output) 63 def clean_up_eslint_output(output)
51 # 1. Filter out offences without a warning or error 64 # 1. Filter out offences without a warning or error
52 # 2. Get the messages for that file 65 # 2. Get the messages for that file