aboutsummaryrefslogtreecommitdiffhomepage
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
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.).
-rw-r--r--lib/pronto/eslint.rb22
-rw-r--r--pronto-eslint.gemspec1
-rw-r--r--spec/fixtures/eslintignore.git/.eslintignore2
-rw-r--r--spec/fixtures/eslintignore.git/git/HEAD1
-rw-r--r--spec/fixtures/eslintignore.git/git/config7
-rw-r--r--spec/fixtures/eslintignore.git/git/indexbin0 -> 353 bytes
-rw-r--r--spec/fixtures/eslintignore.git/git/logs/HEAD3
-rw-r--r--spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore2
-rw-r--r--spec/fixtures/eslintignore.git/git/logs/refs/heads/master1
-rw-r--r--spec/fixtures/eslintignore.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7bin0 -> 73 bytes
-rw-r--r--spec/fixtures/eslintignore.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904bin0 -> 15 bytes
-rw-r--r--spec/fixtures/eslintignore.git/git/objects/5f/fc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53bin0 -> 185 bytes
-rw-r--r--spec/fixtures/eslintignore.git/git/objects/69/7ffd3c693fce9abcb871b9b47e2d116e6241d3bin0 -> 88 bytes
-rw-r--r--spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae82
-rw-r--r--spec/fixtures/eslintignore.git/git/objects/d8/5195b5ff74cc05d121b758f00da43018f53b6fbin0 -> 42 bytes
-rw-r--r--spec/fixtures/eslintignore.git/git/objects/ec/7b4537cbd327a580ee44b74ff02fffc74feb46bin0 -> 63 bytes
-rw-r--r--spec/fixtures/eslintignore.git/git/refs/heads/eslintignore1
-rw-r--r--spec/fixtures/eslintignore.git/git/refs/heads/master1
-rw-r--r--spec/fixtures/eslintignore.git/ignored/ignored.js5
-rw-r--r--spec/fixtures/eslintignore.git/ignored/not_ignored.js5
-rw-r--r--spec/pronto/eslint_spec.rb9
-rw-r--r--spec/spec_helper.rb14
22 files changed, 69 insertions, 7 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
diff --git a/pronto-eslint.gemspec b/pronto-eslint.gemspec
index 77da780..9ad00ec 100644
--- a/pronto-eslint.gemspec
+++ b/pronto-eslint.gemspec
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36 36
37 s.add_dependency('pronto', '~> 0.6.0') 37 s.add_dependency('pronto', '~> 0.6.0')
38 s.add_dependency('eslintrb', '~> 2.0', '>= 2.0.0') 38 s.add_dependency('eslintrb', '~> 2.0', '>= 2.0.0')
39 s.add_dependency('globby', '~> 0.1')
39 s.add_development_dependency('rake', '~> 11.0') 40 s.add_development_dependency('rake', '~> 11.0')
40 s.add_development_dependency('rspec', '~> 3.4') 41 s.add_development_dependency('rspec', '~> 3.4')
41 s.add_development_dependency('rspec-its', '~> 1.2') 42 s.add_development_dependency('rspec-its', '~> 1.2')
diff --git a/spec/fixtures/eslintignore.git/.eslintignore b/spec/fixtures/eslintignore.git/.eslintignore
new file mode 100644
index 0000000..d85195b
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/.eslintignore
@@ -0,0 +1,2 @@
1ignored/**/*.js
2!ignored/not_ignored.js
diff --git a/spec/fixtures/eslintignore.git/git/HEAD b/spec/fixtures/eslintignore.git/git/HEAD
new file mode 100644
index 0000000..fac958f
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/HEAD
@@ -0,0 +1 @@
ref: refs/heads/eslintignore
diff --git a/spec/fixtures/eslintignore.git/git/config b/spec/fixtures/eslintignore.git/git/config
new file mode 100644
index 0000000..6c9406b
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/config
@@ -0,0 +1,7 @@
1[core]
2 repositoryformatversion = 0
3 filemode = true
4 bare = false
5 logallrefupdates = true
6 ignorecase = true
7 precomposeunicode = true
diff --git a/spec/fixtures/eslintignore.git/git/index b/spec/fixtures/eslintignore.git/git/index
new file mode 100644
index 0000000..8c5575c
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/index
Binary files differ
diff --git a/spec/fixtures/eslintignore.git/git/logs/HEAD b/spec/fixtures/eslintignore.git/git/logs/HEAD
new file mode 100644
index 0000000..8750baa
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/logs/HEAD
@@ -0,0 +1,3 @@
10000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450052 +0200 commit (initial): empty init commit
2d43de0396c81608113f99f7afd00f7f363e1cae8 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450062 +0200 checkout: moving from master to eslintignore
3d43de0396c81608113f99f7afd00f7f363e1cae8 5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 Markus Doits <markus.doits@stellenticket.de> 1469450067 +0200 commit: add .eslintignore and files with errors
diff --git a/spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore b/spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore
new file mode 100644
index 0000000..3467ecc
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore
@@ -0,0 +1,2 @@
10000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450062 +0200 branch: Created from HEAD
2d43de0396c81608113f99f7afd00f7f363e1cae8 5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 Markus Doits <markus.doits@stellenticket.de> 1469450067 +0200 commit: add .eslintignore and files with errors
diff --git a/spec/fixtures/eslintignore.git/git/logs/refs/heads/master b/spec/fixtures/eslintignore.git/git/logs/refs/heads/master
new file mode 100644
index 0000000..8105749
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/logs/refs/heads/master
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits <markus.doits@stellenticket.de> 1469450052 +0200 commit (initial): empty init commit
diff --git a/spec/fixtures/eslintignore.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 b/spec/fixtures/eslintignore.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7
new file mode 100644
index 0000000..f5fbdc5
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7
Binary files differ
diff --git a/spec/fixtures/eslintignore.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 b/spec/fixtures/eslintignore.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904
new file mode 100644
index 0000000..adf6411
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904
Binary files differ
diff --git a/spec/fixtures/eslintignore.git/git/objects/5f/fc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 b/spec/fixtures/eslintignore.git/git/objects/5f/fc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53
new file mode 100644
index 0000000..832698f
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/objects/5f/fc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53
Binary files differ
diff --git a/spec/fixtures/eslintignore.git/git/objects/69/7ffd3c693fce9abcb871b9b47e2d116e6241d3 b/spec/fixtures/eslintignore.git/git/objects/69/7ffd3c693fce9abcb871b9b47e2d116e6241d3
new file mode 100644
index 0000000..c23a96f
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/objects/69/7ffd3c693fce9abcb871b9b47e2d116e6241d3
Binary files differ
diff --git a/spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae8 b/spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae8
new file mode 100644
index 0000000..e3c829c
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae8
@@ -0,0 +1,2 @@
1xK
20@]&!n=D>S mZI o#|xihi@i%ZdCqtz#cmpm:"u!څ)ib2_D֓A4Uzק,SE \ No newline at end of file
diff --git a/spec/fixtures/eslintignore.git/git/objects/d8/5195b5ff74cc05d121b758f00da43018f53b6f b/spec/fixtures/eslintignore.git/git/objects/d8/5195b5ff74cc05d121b758f00da43018f53b6f
new file mode 100644
index 0000000..ee9657e
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/objects/d8/5195b5ff74cc05d121b758f00da43018f53b6f
Binary files differ
diff --git a/spec/fixtures/eslintignore.git/git/objects/ec/7b4537cbd327a580ee44b74ff02fffc74feb46 b/spec/fixtures/eslintignore.git/git/objects/ec/7b4537cbd327a580ee44b74ff02fffc74feb46
new file mode 100644
index 0000000..9a642e0
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/objects/ec/7b4537cbd327a580ee44b74ff02fffc74feb46
Binary files differ
diff --git a/spec/fixtures/eslintignore.git/git/refs/heads/eslintignore b/spec/fixtures/eslintignore.git/git/refs/heads/eslintignore
new file mode 100644
index 0000000..d02562a
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/refs/heads/eslintignore
@@ -0,0 +1 @@
5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53
diff --git a/spec/fixtures/eslintignore.git/git/refs/heads/master b/spec/fixtures/eslintignore.git/git/refs/heads/master
new file mode 100644
index 0000000..5dcf161
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/git/refs/heads/master
@@ -0,0 +1 @@
d43de0396c81608113f99f7afd00f7f363e1cae8
diff --git a/spec/fixtures/eslintignore.git/ignored/ignored.js b/spec/fixtures/eslintignore.git/ignored/ignored.js
new file mode 100644
index 0000000..2d1b996
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/ignored/ignored.js
@@ -0,0 +1,5 @@
1function HelloWorld(name)
2{
3 if (foo) foo++;
4 alert(name);
5}
diff --git a/spec/fixtures/eslintignore.git/ignored/not_ignored.js b/spec/fixtures/eslintignore.git/ignored/not_ignored.js
new file mode 100644
index 0000000..2d1b996
--- /dev/null
+++ b/spec/fixtures/eslintignore.git/ignored/not_ignored.js
@@ -0,0 +1,5 @@
1function HelloWorld(name)
2{
3 if (foo) foo++;
4 alert(name);
5}
diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb
index 7af0aa2..1117e15 100644
--- a/spec/pronto/eslint_spec.rb
+++ b/spec/pronto/eslint_spec.rb
@@ -25,6 +25,15 @@ module Pronto
25 its(:count) { should == 9 } 25 its(:count) { should == 9 }
26 its(:'first.msg') { should == "Expected { after 'if' condition." } 26 its(:'first.msg') { should == "Expected { after 'if' condition." }
27 end 27 end
28
29 context 'repo with ignored and not ignored file, each with five warnings' do
30 include_context 'eslintignore repo'
31
32 let(:patches) { repo.diff('master') }
33
34 its(:count) { should == 5 }
35 its(:'first.msg') { should == "Use the function form of 'use strict'." }
36 end
28 end 37 end
29 end 38 end
30end 39end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 4d1ff71..5769c2d 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -2,13 +2,15 @@ require 'rspec'
2require 'rspec/its' 2require 'rspec/its'
3require 'pronto/eslint' 3require 'pronto/eslint'
4 4
5RSpec.shared_context 'test repo' do 5%w(test eslintignore).each do |repo_name|
6 let(:git) { 'spec/fixtures/test.git/git' } 6 RSpec.shared_context "#{repo_name} repo" do
7 let(:dot_git) { 'spec/fixtures/test.git/.git' } 7 let(:git) { "spec/fixtures/#{repo_name}.git/git" }
8 let(:dot_git) { "spec/fixtures/#{repo_name}.git/.git" }
8 9
9 before { FileUtils.mv(git, dot_git) } 10 before { FileUtils.mv(git, dot_git) }
10 let(:repo) { Pronto::Git::Repository.new('spec/fixtures/test.git') } 11 let(:repo) { Pronto::Git::Repository.new("spec/fixtures/#{repo_name}.git") }
11 after { FileUtils.mv(dot_git, git) } 12 after { FileUtils.mv(dot_git, git) }
13 end
12end 14end
13 15
14RSpec.configure do |config| 16RSpec.configure do |config|