aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorMarkus Doits <markus.doits@stellenticket.de>2016-07-25 16:03:07 +0200
committerMarkus Doits <markus.doits@stellenticket.de>2016-07-25 16:03:07 +0200
commit295096252547f3abb76788fbadf0ce059e74f2cc (patch)
tree3694ebac61dadfc16e1103c4b9e2882ac203b519 /lib
parent676cea90d963dc89ca9a9a38625fc7cd1cf3b5bc (diff)
downloadpronto-hlint-295096252547f3abb76788fbadf0ce059e74f2cc.tar.gz
pronto-hlint-295096252547f3abb76788fbadf0ce059e74f2cc.tar.zst
pronto-hlint-295096252547f3abb76788fbadf0ce059e74f2cc.zip
Use system eslint instead of eslintrb
This makes sure `eslint` works as expected, e.g. the config used is respected and full feature set is present. One has to make sure `eslint` is properly installed, though.
Diffstat (limited to 'lib')
-rw-r--r--lib/pronto/eslint.rb38
1 files changed, 14 insertions, 24 deletions
diff --git a/lib/pronto/eslint.rb b/lib/pronto/eslint.rb
index 990081e..fa4261d 100644
--- a/lib/pronto/eslint.rb
+++ b/lib/pronto/eslint.rb
@@ -1,6 +1,4 @@
1require 'pronto' 1require 'pronto'
2require 'eslintrb'
3require 'globby'
4 2
5module Pronto 3module Pronto
6 class ESLint < Runner 4 class ESLint < Runner
@@ -14,8 +12,19 @@ module Pronto
14 end 12 end
15 13
16 def inspect(patch) 14 def inspect(patch)
17 options = File.exist?('.eslintrc') ? :eslintrc : :defaults 15 @_repo_path ||= @patches.first.repo.path
18 offences = Eslintrb.lint(patch.new_file_full_path, options).compact 16
17 offences =
18 Dir.chdir(@_repo_path) do
19 JSON.parse(`eslint #{patch.new_file_full_path} -f json`)
20 end
21
22 offences =
23 offences
24 .select { |offence| offence['errorCount'] > 0 || offence['warningCount'] > 0 } # no warning or error, no problem
25 .map { |offence| offence['messages'] } # get error messages for that file
26 .flatten
27 .select { |offence| offence['line'] } # for now ignore errors without a line number
19 28
20 offences.map do |offence| 29 offences.map do |offence|
21 patch.added_lines.select { |line| line.new_lineno == offence['line'] } 30 patch.added_lines.select { |line| line.new_lineno == offence['line'] }
@@ -31,26 +40,7 @@ module Pronto
31 end 40 end
32 41
33 def js_file?(path) 42 def js_file?(path)
34 %w(.js .es6 .js.es6).include?(File.extname(path)) && !eslintignore_matches?(path) 43 %w(.js .es6 .js.es6).include?(File.extname(path))
35 end
36
37 def eslintignore_matches?(path)
38 @_repo_path ||= @patches.first.repo.path
39 @_eslintignore_path ||= File.join(@_repo_path, '.eslintignore')
40 @_eslintignore_exists ||= File.exist?(@_eslintignore_path)
41
42 return false unless @_eslintignore_exists
43
44 @_eslintignored_files ||=
45 Dir.chdir @_repo_path do # change to the repo path where `.eslintignore` was found
46 eslintignore_content = File.readlines(@_eslintignore_path).map(&:chomp)
47 ignored_files = Globby.select(eslintignore_content)
48
49 # prefix each found file with `repo_path`, because `path` is absolute, too
50 ignored_files.map { |file| File.join(@_repo_path, file).to_s }
51 end
52
53 @_eslintignored_files.include?(path.to_s)
54 end 44 end
55 end 45 end
56end 46end