]> git.immae.eu Git - github/fretlink/pronto-hlint.git/commitdiff
Implement ESLint runner
authorMindaugas Mozūras <mindaugas.mozuras@gmail.com>
Sun, 28 Feb 2016 15:50:43 +0000 (17:50 +0200)
committerMindaugas Mozūras <mindaugas.mozuras@gmail.com>
Sun, 28 Feb 2016 15:50:43 +0000 (17:50 +0200)
28 files changed:
lib/pronto/eslint.rb [new file with mode: 0644]
lib/pronto/eslint/version.rb [new file with mode: 0644]
spec/fixtures/test.git/git/HEAD [new file with mode: 0644]
spec/fixtures/test.git/git/config [new file with mode: 0644]
spec/fixtures/test.git/git/index [new file with mode: 0644]
spec/fixtures/test.git/git/logs/HEAD [new file with mode: 0644]
spec/fixtures/test.git/git/logs/refs/heads/curly [new file with mode: 0644]
spec/fixtures/test.git/git/logs/refs/heads/master [new file with mode: 0644]
spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d [new file with mode: 0644]
spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703b [new file with mode: 0644]
spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 [new file with mode: 0644]
spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0 [new file with mode: 0644]
spec/fixtures/test.git/git/refs/heads/curly [new file with mode: 0644]
spec/fixtures/test.git/git/refs/heads/master [new file with mode: 0644]
spec/fixtures/test.git/hello.js [new file with mode: 0644]
spec/pronto/eslint_spec.rb [new file with mode: 0644]

diff --git a/lib/pronto/eslint.rb b/lib/pronto/eslint.rb
new file mode 100644 (file)
index 0000000..67e9229
--- /dev/null
@@ -0,0 +1,36 @@
+require 'pronto'
+require 'eslintrb'
+
+module Pronto
+  class ESLint < Runner
+    def run(patches, _)
+      return [] unless patches
+
+      patches.select { |patch| patch.additions > 0 }
+        .select { |patch| js_file?(patch.new_file_full_path) }
+        .map { |patch| inspect(patch) }
+        .flatten.compact
+    end
+
+    def inspect(patch)
+      options = File.exist?('.eslintrc') ? :eslintrc : :defaults
+      offences = Eslintrb.lint(patch.new_file_full_path, options).compact
+
+      offences.map do |offence|
+        patch.added_lines.select { |line| line.new_lineno == offence['line'] }
+          .map { |line| new_message(offence, line) }
+      end
+    end
+
+    def new_message(offence, line)
+      path = line.patch.delta.new_file[:path]
+      level = :warning
+
+      Message.new(path, line, level, offence['message'])
+    end
+
+    def js_file?(path)
+      File.extname(path) == '.js'
+    end
+  end
+end
diff --git a/lib/pronto/eslint/version.rb b/lib/pronto/eslint/version.rb
new file mode 100644 (file)
index 0000000..d59d88a
--- /dev/null
@@ -0,0 +1,5 @@
+module Pronto
+  module ESLintVersion
+    VERSION = '0.5.0'
+  end
+end
diff --git a/spec/fixtures/test.git/git/HEAD b/spec/fixtures/test.git/git/HEAD
new file mode 100644 (file)
index 0000000..c15524d
--- /dev/null
@@ -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 (file)
index 0000000..6c9406b
--- /dev/null
@@ -0,0 +1,7 @@
+[core]
+       repositoryformatversion = 0
+       filemode = true
+       bare = false
+       logallrefupdates = true
+       ignorecase = true
+       precomposeunicode = true
diff --git a/spec/fixtures/test.git/git/index b/spec/fixtures/test.git/git/index
new file mode 100644 (file)
index 0000000..786f76d
Binary files /dev/null and b/spec/fixtures/test.git/git/index differ
diff --git a/spec/fixtures/test.git/git/logs/HEAD b/spec/fixtures/test.git/git/logs/HEAD
new file mode 100644 (file)
index 0000000..7e44d13
--- /dev/null
@@ -0,0 +1,13 @@
+0000000000000000000000000000000000000000 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058807 +0300    commit (initial): Initial commit
+f37efccc1cef20309de28bfbdd16d0c4afb9d550 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058814 +0300    checkout: moving from master to semicolon
+f37efccc1cef20309de28bfbdd16d0c4afb9d550 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058820 +0300    commit: Remove semicolon
+f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673968 +0200    checkout: moving from semicolon to master
+f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673985 +0200    commit (amend): Initial commit
+85e04b1eb1a721d42db51d49e49dfeb8255a5741 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673990 +0200    checkout: moving from master to semicolon
+f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673992 +0200    rebase: checkout master
+85e04b1eb1a721d42db51d49e49dfeb8255a5741 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673992 +0200    rebase: Remove semicolon
+e438134aac40ce86789d552f1bdada6582a987f6 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673992 +0200    rebase finished: returning to refs/heads/semicolon
+e438134aac40ce86789d552f1bdada6582a987f6 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674159 +0200    checkout: moving from semicolon to master
+85e04b1eb1a721d42db51d49e49dfeb8255a5741 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674164 +0200    commit (amend): Initial commit
+931004157205727e6a47586feaed0473c6ddbd66 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674177 +0200    checkout: moving from master to curly
+931004157205727e6a47586feaed0473c6ddbd66 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 (file)
index 0000000..dfb7828
--- /dev/null
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456674177 +0200    branch: Created from HEAD
+931004157205727e6a47586feaed0473c6ddbd66 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 (file)
index 0000000..752c737
--- /dev/null
@@ -0,0 +1,3 @@
+0000000000000000000000000000000000000000 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1433058807 +0300    commit (initial): Initial commit
+f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas Mozūras <mindaugas.mozuras@gmail.com> 1456673985 +0200    commit (amend): Initial commit
+85e04b1eb1a721d42db51d49e49dfeb8255a5741 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 (file)
index 0000000..d0554e9
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d 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 (file)
index 0000000..6fcbf2f
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924 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 (file)
index 0000000..f5fbdc5
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 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 (file)
index 0000000..a1399be
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703b 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 (file)
index 0000000..c8a6c16
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8 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 (file)
index 0000000..8a65f33
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 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 (file)
index 0000000..adf6411
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 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 (file)
index 0000000..5175450
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 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 (file)
index 0000000..153bd31
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741 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 (file)
index 0000000..797ab27
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546 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 (file)
index 0000000..f017b1a
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66 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 (file)
index 0000000..d5f9ef5
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324 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 (file)
index 0000000..9d54c76
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3 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 (file)
index 0000000..37b8c14
--- /dev/null
@@ -0,0 +1 @@
+x\ 1\9d\8eÍi\ 31\10FsV\15º\e\8c4\9aÑjÀ\187àK:ÐÏØY°VfWë\83[J\1dé+º¤\81Ü>\1e¼Ç\97[­s×àíG_E4\83\1cB\ 6C¶xF¾I\12\80[f\ 4ç)\9a\ 4\84^=ã*K×\81Ä`²\92l\9cÀ\16\84\92\86\86,Èe\88\ 1\88"MhUÜûW[õu^JÜïqÓ×öþù^Ç8Õ?v¬í½\ ft¹×8?\8e¹Õ³¶è\9c¡\10Àè\83qƨAÇã.ÿj\91÷\93c\86Ñ\82ÑR\9fRÛKô&uÎíÑ\16õ\vß)V\9f
\ 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 (file)
index 0000000..1b07d10
--- /dev/null
@@ -0,0 +1,3 @@
+x\ 1­ÎK
+Â0\14\85aÇYÅ\9d\vå&iÒ\ 4D\9c:è"n\1e­\81¦\81\9aNº%×á¾\f\88;pvø\ 6\97\9cS\ 5Áù©n1\82\9d¼ \17\ 2\1a«8¢SfÐÎË^\a
+Ú¹ÉI\e­\14=£½>Ê\ 6cZ\ 3í3=a,ÇûµµqÉ?ër9öF·9SZ:_ò\15x/%*cp\803JDÖ´=¨ñ\1f-v_SM´À7Ê>»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 (file)
index 0000000..7fa950f
Binary files /dev/null and b/spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0 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 (file)
index 0000000..ce18055
--- /dev/null
@@ -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 (file)
index 0000000..0cccce0
--- /dev/null
@@ -0,0 +1 @@
+931004157205727e6a47586feaed0473c6ddbd66
diff --git a/spec/fixtures/test.git/hello.js b/spec/fixtures/test.git/hello.js
new file mode 100644 (file)
index 0000000..2d1b996
--- /dev/null
@@ -0,0 +1,5 @@
+function HelloWorld(name)
+{
+    if (foo) foo++;
+    alert(name);
+}
diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb
new file mode 100644 (file)
index 0000000..8bd0bc8
--- /dev/null
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+module Pronto
+  describe ESLint do
+    let(:eslint) { ESLint.new }
+
+    describe '#run' do
+      subject { eslint.run(patches, nil) }
+
+      context 'patches are nil' do
+        let(:patches) { nil }
+        it { should == [] }
+      end
+
+      context 'no patches' do
+        let(:patches) { [] }
+        it { should == [] }
+      end
+
+      context 'patches with a four warnings' do
+        include_context 'test repo'
+
+        let(:patches) { repo.diff('master') }
+
+        its(:count) { should == 4 }
+        its(:'first.msg') { should == "Expected { after 'if' condition." }
+      end
+    end
+  end
+end