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.).
require 'pronto'
require 'eslintrb'
+require 'globby'
module Pronto
class ESLint < Runner
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
s.add_dependency('pronto', '~> 0.6.0')
s.add_dependency('eslintrb', '~> 2.0', '>= 2.0.0')
+ s.add_dependency('globby', '~> 0.1')
s.add_development_dependency('rake', '~> 11.0')
s.add_development_dependency('rspec', '~> 3.4')
s.add_development_dependency('rspec-its', '~> 1.2')
--- /dev/null
+ignored/**/*.js
+!ignored/not_ignored.js
--- /dev/null
+ref: refs/heads/eslintignore
--- /dev/null
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+ precomposeunicode = true
--- /dev/null
+0000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450052 +0200 commit (initial): empty init commit
+d43de0396c81608113f99f7afd00f7f363e1cae8 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450062 +0200 checkout: moving from master to eslintignore
+d43de0396c81608113f99f7afd00f7f363e1cae8 5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 Markus Doits <markus.doits@stellenticket.de> 1469450067 +0200 commit: add .eslintignore and files with errors
--- /dev/null
+0000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450062 +0200 branch: Created from HEAD
+d43de0396c81608113f99f7afd00f7f363e1cae8 5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 Markus Doits <markus.doits@stellenticket.de> 1469450067 +0200 commit: add .eslintignore and files with errors
--- /dev/null
+0000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450052 +0200 commit (initial): empty init commit
--- /dev/null
+x\ 1¥\8fK
+Â0\10@]ç\14³\17Ê\18&!\ 1\11\17n=D>S\fmZI¦\vo¯Ö#¸|\9b÷xiµ\bh´\aiÌ@Ñi\93\93%\9d¢åè\ 3ZdCqtÙzíÜ\18\99É#©°Écmp\ fmÚ:ÜÖ"\1dÎu§!\7féÚ\85ç\99\17)ib\192_àDÖ\93A4\1a\8e¨\11UÚëÂÿz\14ק¼ ,\9f\95\9fS½\ 1\85ïEµ
\ No newline at end of file
--- /dev/null
+5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53
--- /dev/null
+d43de0396c81608113f99f7afd00f7f363e1cae8
--- /dev/null
+function HelloWorld(name)
+{
+ if (foo) foo++;
+ alert(name);
+}
--- /dev/null
+function HelloWorld(name)
+{
+ if (foo) foo++;
+ alert(name);
+}
its(:count) { should == 9 }
its(:'first.msg') { should == "Expected { after 'if' condition." }
end
+
+ context 'repo with ignored and not ignored file, each with five warnings' do
+ include_context 'eslintignore repo'
+
+ let(:patches) { repo.diff('master') }
+
+ its(:count) { should == 5 }
+ its(:'first.msg') { should == "Use the function form of 'use strict'." }
+ end
end
end
end
require 'rspec/its'
require 'pronto/eslint'
-RSpec.shared_context 'test repo' do
- let(:git) { 'spec/fixtures/test.git/git' }
- let(:dot_git) { 'spec/fixtures/test.git/.git' }
+%w(test eslintignore).each do |repo_name|
+ RSpec.shared_context "#{repo_name} repo" do
+ let(:git) { "spec/fixtures/#{repo_name}.git/git" }
+ let(:dot_git) { "spec/fixtures/#{repo_name}.git/.git" }
- before { FileUtils.mv(git, dot_git) }
- let(:repo) { Pronto::Git::Repository.new('spec/fixtures/test.git') }
- after { FileUtils.mv(dot_git, git) }
+ before { FileUtils.mv(git, dot_git) }
+ let(:repo) { Pronto::Git::Repository.new("spec/fixtures/#{repo_name}.git") }
+ after { FileUtils.mv(dot_git, git) }
+ end
end
RSpec.configure do |config|