From fb94b0e6df4da3026b9fb4714ee7ceab6bbfa9bc Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Mon, 25 Jul 2016 14:36:23 +0200 Subject: 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.). --- lib/pronto/eslint.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'lib') 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 @@ require 'pronto' require 'eslintrb' +require 'globby' module Pronto class ESLint < Runner @@ -30,7 +31,26 @@ module Pronto end def js_file?(path) - %w(.js .es6 .js.es6).include? File.extname(path) + %w(.js .es6 .js.es6).include?(File.extname(path)) && !eslintignore_matches?(path) + end + + def eslintignore_matches?(path) + @_repo_path ||= @patches.first.repo.path + @_eslintignore_path ||= File.join(@_repo_path, '.eslintignore') + @_eslintignore_exists ||= File.exist?(@_eslintignore_path) + + return false unless @_eslintignore_exists + + @_eslintignored_files ||= + Dir.chdir @_repo_path do # change to the repo path where `.eslintignore` was found + eslintignore_content = File.readlines(@_eslintignore_path).map(&:chomp) + ignored_files = Globby.select(eslintignore_content) + + # prefix each found file with `repo_path`, because `path` is absolute, too + ignored_files.map { |file| File.join(@_repo_path, file).to_s } + end + + @_eslintignored_files.include?(path.to_s) end end end -- cgit v1.2.3