aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorMarkus Doits <markus.doits@stellenticket.de>2016-07-25 14:36:23 +0200
committerMarkus Doits <markus.doits@stellenticket.de>2016-07-25 14:51:26 +0200
commitfb94b0e6df4da3026b9fb4714ee7ceab6bbfa9bc (patch)
tree57d22b50d28eab271a8db6fe201a7f18bbe069f4 /lib
parent604e30d99fdbb7c822efe31d05a0238064220037 (diff)
downloadpronto-hlint-fb94b0e6df4da3026b9fb4714ee7ceab6bbfa9bc.tar.gz
pronto-hlint-fb94b0e6df4da3026b9fb4714ee7ceab6bbfa9bc.tar.zst
pronto-hlint-fb94b0e6df4da3026b9fb4714ee7ceab6bbfa9bc.zip
Respect `.eslintignore`
If an `.eslintignore` is present, it's patterns are now respected. See http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories for more info. Due to the file format of `.eslintignore`, the gem `globby` has to be used for those patterns (which respects negations etc.).
Diffstat (limited to 'lib')
-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