From: Mindaugas Mozūras Date: Sun, 28 Feb 2016 15:50:43 +0000 (+0200) Subject: Implement ESLint runner X-Git-Tag: v0.1.0~57 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=9be00a3292ddbbf280ac6d92b5b8add7f8ae9508;p=github%2Ffretlink%2Fpronto-hlint.git Implement ESLint runner --- 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 @@ +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 index 0000000..d59d88a --- /dev/null +++ b/lib/pronto/eslint/version.rb @@ -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 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 @@ +[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 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 index 0000000..7e44d13 --- /dev/null +++ b/spec/fixtures/test.git/git/logs/HEAD @@ -0,0 +1,13 @@ +0000000000000000000000000000000000000000 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas MozÅ«ras 1433058807 +0300 commit (initial): Initial commit +f37efccc1cef20309de28bfbdd16d0c4afb9d550 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas MozÅ«ras 1433058814 +0300 checkout: moving from master to semicolon +f37efccc1cef20309de28bfbdd16d0c4afb9d550 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas MozÅ«ras 1433058820 +0300 commit: Remove semicolon +f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas MozÅ«ras 1456673968 +0200 checkout: moving from semicolon to master +f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456673985 +0200 commit (amend): Initial commit +85e04b1eb1a721d42db51d49e49dfeb8255a5741 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas MozÅ«ras 1456673990 +0200 checkout: moving from master to semicolon +f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456673992 +0200 rebase: checkout master +85e04b1eb1a721d42db51d49e49dfeb8255a5741 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas MozÅ«ras 1456673992 +0200 rebase: Remove semicolon +e438134aac40ce86789d552f1bdada6582a987f6 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas MozÅ«ras 1456673992 +0200 rebase finished: returning to refs/heads/semicolon +e438134aac40ce86789d552f1bdada6582a987f6 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456674159 +0200 checkout: moving from semicolon to master +85e04b1eb1a721d42db51d49e49dfeb8255a5741 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 1456674164 +0200 commit (amend): Initial commit +931004157205727e6a47586feaed0473c6ddbd66 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 1456674177 +0200 checkout: moving from master to curly +931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas MozÅ«ras 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 @@ +0000000000000000000000000000000000000000 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 1456674177 +0200 branch: Created from HEAD +931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas MozÅ«ras 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 @@ +0000000000000000000000000000000000000000 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas MozÅ«ras 1433058807 +0300 commit (initial): Initial commit +f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456673985 +0200 commit (amend): Initial commit +85e04b1eb1a721d42db51d49e49dfeb8255a5741 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 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 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 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 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 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 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 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 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 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 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 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 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 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 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 index 0000000..37b8c14 --- /dev/null +++ b/spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 @@ -0,0 +1 @@ +xŽÍi1FsVºŒ4šÑjÀ7àK:ÐÏØY°VfWëƒ[Jé+º¤Ü>¼Ç—[­s×àíG_E4ƒ#áBC¶xF¾I€[fç)š„^=ã*KׁÄ`²’lœÀ„’††,Èeˆˆ"MhUÜûW[õu^JÜïqÓ×öþù^Ç8Õ?v¬í½t¹×8?Ž¹Õ³¶èœ¡ÀèƒqƨAÇã.ÿj‘÷“c†Ñ‚ÑRŸRÛKô&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 @@ +x­ÎK +Â0…aÇYŝ å&iÒDœ:è"n­¦šNº%×á¾ ˆ;pvø?ǗœSÁù©n1‚¼ «8¢SfÐÎË^ +Ú¹ÉI­=£½>ÊcZí3=a,ÇûµµqÉ?ër9öF·9SZ:_òx/%*cp€3JDÖ´=¨ñ-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 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 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 @@ +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 index 0000000..8bd0bc8 --- /dev/null +++ b/spec/pronto/eslint_spec.rb @@ -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