aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/pronto
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pronto')
-rw-r--r--lib/pronto/eslint.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/pronto/eslint.rb b/lib/pronto/eslint.rb
index 498df63..990081e 100644
--- a/lib/pronto/eslint.rb
+++ b/lib/pronto/eslint.rb
@@ -1,5 +1,6 @@
1require 'pronto' 1require 'pronto'
2require 'eslintrb' 2require 'eslintrb'
3require 'globby'
3 4
4module Pronto 5module Pronto
5 class ESLint < Runner 6 class ESLint < Runner
@@ -30,7 +31,26 @@ module Pronto
30 end 31 end
31 32
32 def js_file?(path) 33 def js_file?(path)
33 %w(.js .es6 .js.es6).include? File.extname(path) 34 %w(.js .es6 .js.es6).include?(File.extname(path)) && !eslintignore_matches?(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)
34 end 54 end
35 end 55 end
36end 56end