aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMindaugas Mozūras <mindaugas.mozuras@gmail.com>2016-02-28 17:50:43 +0200
committerMindaugas Mozūras <mindaugas.mozuras@gmail.com>2016-02-28 17:50:43 +0200
commit9be00a3292ddbbf280ac6d92b5b8add7f8ae9508 (patch)
tree620ee245557b1c434a3270fc969e2f013c40cea2
parentce89f9ed8a80a06d26b0618658733956d0c98f84 (diff)
downloadpronto-hlint-9be00a3292ddbbf280ac6d92b5b8add7f8ae9508.tar.gz
pronto-hlint-9be00a3292ddbbf280ac6d92b5b8add7f8ae9508.tar.zst
pronto-hlint-9be00a3292ddbbf280ac6d92b5b8add7f8ae9508.zip
Implement ESLint runner
-rw-r--r--lib/pronto/eslint.rb36
-rw-r--r--lib/pronto/eslint/version.rb5
-rw-r--r--spec/fixtures/test.git/git/HEAD1
-rw-r--r--spec/fixtures/test.git/git/config7
-rw-r--r--spec/fixtures/test.git/git/indexbin0 -> 137 bytes
-rw-r--r--spec/fixtures/test.git/git/logs/HEAD13
-rw-r--r--spec/fixtures/test.git/git/logs/refs/heads/curly2
-rw-r--r--spec/fixtures/test.git/git/logs/refs/heads/master3
-rw-r--r--spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92dbin0 -> 53 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924bin0 -> 86 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7bin0 -> 73 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703bbin0 -> 212 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8bin0 -> 57 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6bin0 -> 55 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904bin0 -> 15 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8bin0 -> 53 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741bin0 -> 154 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546bin0 -> 86 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66bin0 -> 154 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324bin0 -> 53 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3bin0 -> 46 bytes
-rw-r--r--spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f61
-rw-r--r--spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d5503
-rw-r--r--spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0bin0 -> 179 bytes
-rw-r--r--spec/fixtures/test.git/git/refs/heads/curly1
-rw-r--r--spec/fixtures/test.git/git/refs/heads/master1
-rw-r--r--spec/fixtures/test.git/hello.js5
-rw-r--r--spec/pronto/eslint_spec.rb30
28 files changed, 108 insertions, 0 deletions
diff --git a/lib/pronto/eslint.rb b/lib/pronto/eslint.rb
new file mode 100644
index 0000000..67e9229
--- /dev/null
+++ b/lib/pronto/eslint.rb
@@ -0,0 +1,36 @@
1require 'pronto'
2require 'eslintrb'
3
4module Pronto
5 class ESLint < Runner
6 def run(patches, _)
7 return [] unless patches
8
9 patches.select { |patch| patch.additions > 0 }
10 .select { |patch| js_file?(patch.new_file_full_path) }
11 .map { |patch| inspect(patch) }
12 .flatten.compact
13 end
14
15 def inspect(patch)
16 options = File.exist?('.eslintrc') ? :eslintrc : :defaults
17 offences = Eslintrb.lint(patch.new_file_full_path, options).compact
18
19 offences.map do |offence|
20 patch.added_lines.select { |line| line.new_lineno == offence['line'] }
21 .map { |line| new_message(offence, line) }
22 end
23 end
24
25 def new_message(offence, line)
26 path = line.patch.delta.new_file[:path]
27 level = :warning
28
29 Message.new(path, line, level, offence['message'])
30 end
31
32 def js_file?(path)
33 File.extname(path) == '.js'
34 end
35 end
36end
diff --git a/lib/pronto/eslint/version.rb b/lib/pronto/eslint/version.rb
new file mode 100644
index 0000000..d59d88a
--- /dev/null
+++ b/lib/pronto/eslint/version.rb
@@ -0,0 +1,5 @@
1module Pronto
2 module ESLintVersion
3 VERSION = '0.5.0'
4 end
5end
diff --git a/spec/fixtures/test.git/git/HEAD b/spec/fixtures/test.git/git/HEAD
new file mode 100644
index 0000000..c15524d
--- /dev/null
+++ b/spec/fixtures/test.git/git/HEAD
@@ -0,0 +1 @@
ref: refs/heads/curly
diff --git a/spec/fixtures/test.git/git/config b/spec/fixtures/test.git/git/config
new file mode 100644
index 0000000..6c9406b
--- /dev/null
+++ b/spec/fixtures/test.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/test.git/git/index b/spec/fixtures/test.git/git/index
new file mode 100644
index 0000000..786f76d
--- /dev/null
+++ b/spec/fixtures/test.git/git/index
Binary files differ
diff --git a/spec/fixtures/test.git/git/logs/HEAD b/spec/fixtures/test.git/git/logs/HEAD
new file mode 100644
index 0000000..7e44d13
--- /dev/null
+++ b/spec/fixtures/test.git/git/logs/HEAD
@@ -0,0 +1,13 @@
10000000000000000000000000000000000000000 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058807 +0300 commit (initial): Initial commit
2f37efccc1cef20309de28bfbdd16d0c4afb9d550 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058814 +0300 checkout: moving from master to semicolon
3f37efccc1cef20309de28bfbdd16d0c4afb9d550 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058820 +0300 commit: Remove semicolon
4f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673968 +0200 checkout: moving from semicolon to master
5f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673985 +0200 commit (amend): Initial commit
685e04b1eb1a721d42db51d49e49dfeb8255a5741 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673990 +0200 checkout: moving from master to semicolon
7f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673992 +0200 rebase: checkout master
885e04b1eb1a721d42db51d49e49dfeb8255a5741 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673992 +0200 rebase: Remove semicolon
9e438134aac40ce86789d552f1bdada6582a987f6 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673992 +0200 rebase finished: returning to refs/heads/semicolon
10e438134aac40ce86789d552f1bdada6582a987f6 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674159 +0200 checkout: moving from semicolon to master
1185e04b1eb1a721d42db51d49e49dfeb8255a5741 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674164 +0200 commit (amend): Initial commit
12931004157205727e6a47586feaed0473c6ddbd66 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674177 +0200 checkout: moving from master to curly
13931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint)
diff --git a/spec/fixtures/test.git/git/logs/refs/heads/curly b/spec/fixtures/test.git/git/logs/refs/heads/curly
new file mode 100644
index 0000000..dfb7828
--- /dev/null
+++ b/spec/fixtures/test.git/git/logs/refs/heads/curly
@@ -0,0 +1,2 @@
10000000000000000000000000000000000000000 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674177 +0200 branch: Created from HEAD
2931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint)
diff --git a/spec/fixtures/test.git/git/logs/refs/heads/master b/spec/fixtures/test.git/git/logs/refs/heads/master
new file mode 100644
index 0000000..752c737
--- /dev/null
+++ b/spec/fixtures/test.git/git/logs/refs/heads/master
@@ -0,0 +1,3 @@
10000000000000000000000000000000000000000 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058807 +0300 commit (initial): Initial commit
2f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673985 +0200 commit (amend): Initial commit
385e04b1eb1a721d42db51d49e49dfeb8255a5741 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674164 +0200 commit (amend): Initial commit
diff --git a/spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d b/spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d
new file mode 100644
index 0000000..d0554e9
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924 b/spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924
new file mode 100644
index 0000000..6fcbf2f
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 b/spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7
new file mode 100644
index 0000000..f5fbdc5
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703b b/spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703b
new file mode 100644
index 0000000..a1399be
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703b
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8 b/spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8
new file mode 100644
index 0000000..c8a6c16
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 b/spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6
new file mode 100644
index 0000000..8a65f33
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 b/spec/fixtures/test.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904
new file mode 100644
index 0000000..adf6411
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 b/spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8
new file mode 100644
index 0000000..5175450
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741 b/spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741
new file mode 100644
index 0000000..153bd31
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546 b/spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546
new file mode 100644
index 0000000..797ab27
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66 b/spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66
new file mode 100644
index 0000000..f017b1a
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324 b/spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324
new file mode 100644
index 0000000..d5f9ef5
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3 b/spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3
new file mode 100644
index 0000000..9d54c76
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3
Binary files differ
diff --git a/spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 b/spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6
new file mode 100644
index 0000000..37b8c14
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6
@@ -0,0 +1 @@
xi1FsV4j7K:YVfW[J+>Ǘ[sG_E4#BCxFI[f)^=*Kׁ`l,e"MhUW[u^Jq^8?vt8?ճ蜡qƨA.jcтRRK&u )V \ No newline at end of file
diff --git a/spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 b/spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550
new file mode 100644
index 0000000..1b07d10
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550
@@ -0,0 +1,3 @@
1xK
20aYŝ &iD:"nN% ;pv?ǗSn1 8Sf^
3ڹI=>cZ3=a,q?r9F9SZ:_x/%*cp3JDִ=-v_SM7>CH \ No newline at end of file
diff --git a/spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0 b/spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0
new file mode 100644
index 0000000..7fa950f
--- /dev/null
+++ b/spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0
Binary files differ
diff --git a/spec/fixtures/test.git/git/refs/heads/curly b/spec/fixtures/test.git/git/refs/heads/curly
new file mode 100644
index 0000000..ce18055
--- /dev/null
+++ b/spec/fixtures/test.git/git/refs/heads/curly
@@ -0,0 +1 @@
3a6237c5feacca9a37c36bec5110a1eeb9da703b
diff --git a/spec/fixtures/test.git/git/refs/heads/master b/spec/fixtures/test.git/git/refs/heads/master
new file mode 100644
index 0000000..0cccce0
--- /dev/null
+++ b/spec/fixtures/test.git/git/refs/heads/master
@@ -0,0 +1 @@
931004157205727e6a47586feaed0473c6ddbd66
diff --git a/spec/fixtures/test.git/hello.js b/spec/fixtures/test.git/hello.js
new file mode 100644
index 0000000..2d1b996
--- /dev/null
+++ b/spec/fixtures/test.git/hello.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
new file mode 100644
index 0000000..8bd0bc8
--- /dev/null
+++ b/spec/pronto/eslint_spec.rb
@@ -0,0 +1,30 @@
1require 'spec_helper'
2
3module Pronto
4 describe ESLint do
5 let(:eslint) { ESLint.new }
6
7 describe '#run' do
8 subject { eslint.run(patches, nil) }
9
10 context 'patches are nil' do
11 let(:patches) { nil }
12 it { should == [] }
13 end
14
15 context 'no patches' do
16 let(:patches) { [] }
17 it { should == [] }
18 end
19
20 context 'patches with a four warnings' do
21 include_context 'test repo'
22
23 let(:patches) { repo.diff('master') }
24
25 its(:count) { should == 4 }
26 its(:'first.msg') { should == "Expected { after 'if' condition." }
27 end
28 end
29 end
30end