From 9be00a3292ddbbf280ac6d92b5b8add7f8ae9508 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mindaugas=20Moz=C5=ABras?= Date: Sun, 28 Feb 2016 17:50:43 +0200 Subject: [PATCH] Implement ESLint runner --- lib/pronto/eslint.rb | 36 ++++++++++++++++++ lib/pronto/eslint/version.rb | 5 +++ spec/fixtures/test.git/git/HEAD | 1 + spec/fixtures/test.git/git/config | 7 ++++ spec/fixtures/test.git/git/index | Bin 0 -> 137 bytes spec/fixtures/test.git/git/logs/HEAD | 13 +++++++ .../test.git/git/logs/refs/heads/curly | 2 + .../test.git/git/logs/refs/heads/master | 3 ++ .../06/745b4cc11f505bdd1ecc84a744c3802729f92d | Bin 0 -> 53 bytes .../22/2c064befc5a4f3192526863ce449c81bb74924 | Bin 0 -> 86 bytes .../2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 | Bin 0 -> 73 bytes .../3a/6237c5feacca9a37c36bec5110a1eeb9da703b | Bin 0 -> 212 bytes .../3a/efa89bfb08a4697dc441eed97005eb304364d8 | Bin 0 -> 57 bytes .../45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 | Bin 0 -> 55 bytes .../4b/825dc642cb6eb9a060e54bf8d69288fbee4904 | Bin 0 -> 15 bytes .../76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 | Bin 0 -> 53 bytes .../85/e04b1eb1a721d42db51d49e49dfeb8255a5741 | Bin 0 -> 154 bytes .../92/35e9c88c2051d6949febe22fc942365a0b2546 | Bin 0 -> 86 bytes .../93/1004157205727e6a47586feaed0473c6ddbd66 | Bin 0 -> 154 bytes .../9f/c2abdd0895100b5876bc346dad6bbfb39e9324 | Bin 0 -> 53 bytes .../d0/80b4f440e8a87be90677df855a139a36bd2dc3 | Bin 0 -> 46 bytes .../e4/38134aac40ce86789d552f1bdada6582a987f6 | 1 + .../f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 | 3 ++ .../f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0 | Bin 0 -> 179 bytes spec/fixtures/test.git/git/refs/heads/curly | 1 + spec/fixtures/test.git/git/refs/heads/master | 1 + spec/fixtures/test.git/hello.js | 5 +++ spec/pronto/eslint_spec.rb | 30 +++++++++++++++ 28 files changed, 108 insertions(+) create mode 100644 lib/pronto/eslint.rb create mode 100644 lib/pronto/eslint/version.rb create mode 100644 spec/fixtures/test.git/git/HEAD create mode 100644 spec/fixtures/test.git/git/config create mode 100644 spec/fixtures/test.git/git/index create mode 100644 spec/fixtures/test.git/git/logs/HEAD create mode 100644 spec/fixtures/test.git/git/logs/refs/heads/curly create mode 100644 spec/fixtures/test.git/git/logs/refs/heads/master create mode 100644 spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d create mode 100644 spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924 create mode 100644 spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 create mode 100644 spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703b create mode 100644 spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8 create mode 100644 spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 create mode 100644 spec/fixtures/test.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 create mode 100644 spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 create mode 100644 spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741 create mode 100644 spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546 create mode 100644 spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66 create mode 100644 spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324 create mode 100644 spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3 create mode 100644 spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 create mode 100644 spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 create mode 100644 spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0 create mode 100644 spec/fixtures/test.git/git/refs/heads/curly create mode 100644 spec/fixtures/test.git/git/refs/heads/master create mode 100644 spec/fixtures/test.git/hello.js create mode 100644 spec/pronto/eslint_spec.rb 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 0000000000000000000000000000000000000000..786f76dc80f82a380371913e187b8b4b4c2dcc37 GIT binary patch literal 137 zcmZ?q402{*U|<4b#<0tx-9VZFMl&)nurTFkZ)IR;TmqE-3X~E7VrO0HnQ8wv&P|J& z7rkxi-X{VIRvF(JI5JXma`N@EiWwL}f?QpJ>LeKq6%4r8N}_!Z$_GT>l{?e2+~shC ey5>*a+t)bHUwVB#IlTDRzh+~rceDIE-v9t)D=ftT literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..d0554e96026bda7ff3ffc69bd06079053c1fd054 GIT binary patch literal 53 zcmV-50LuS(0V^p=O;s>9V=y!@Ff%bx$Vkn}$=Ay&X3&+Mnf7nv+_b29(c6~peIlS> LmGK<_KI9O&VAL6p literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..6fcbf2f7db2d52af7c9df9cba2fba724b1e44cad GIT binary patch literal 86 zcmV-c0IC0Y0V^p=O;s>AW-v4`Ff%bx&`T}O$;>M$N@lpwu;q)xixt%`*~;&?MhVX{ s+pBvRswg8hCnsMotC+#+{fgPYIhJJB9&vnkvw-!rfpf|Y0O0K*RWlGL`2YX_ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f5fbdc534df59a48a106d6141541e9cee9d560bf GIT binary patch literal 73 zcmV-P0Ji^l0ZYosPf{>5XGkl}OD@UG&r|S7&B@6R&o9bJ(a1~8P1WS8=28HH%rpg! fwETQc1t6iVZ4DMn%tjXt)21F z>aHjOUG!sE1ckMW0|n-pLr{3OwN$vKo${;J))y~=> OC`YfgC-nm?y=Qk@Cue>D literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c8a6c16275df9bc71f35509f94473b6cb4621375 GIT binary patch literal 57 zcmV-90LK4#0ZYosPf{>3XGkl}OD@UG&r|S7&B@6R&o9bJ(a1~8P1WS8=28HH#GKTk P5{QU3S1lI+0dWz8CUqLo literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..8a65f33c983c9c005043fcd445004bb32fdaca4e GIT binary patch literal 55 zcmV-70LcG%0ZYosPf{>3V@NB_OD@UG&r|S7&B@6R&o9bJ(a1~8P1WS8=28HH#GKTk N5~xTm7Xa^$5lHeF8t?!B literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..adf64119a33d7621aeeaa505d30adb58afaa5559 GIT binary patch literal 15 Wcmb9V=y!@Ff%bx$Vkn}$=Ay&W^h$>7Sa8Y)YANA(O)m`{XbvK LTfPhcI5H8YJ@pq& literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..153bd31eff7fae260b2279d49c2b5cd862dd8922 GIT binary patch literal 154 zcmV;L0A>Gp0iDi43d0}}h2gF}#q0|~$I&Q+(rp(xgs~9unx(L)P#Z0MAhOAW-v4`Ff%bx&`T}O$;>M$N@lpwu;q)xixt%`*~;&?MhVX{ s+pBvRswg8hCnsMotC+!6(OE?IM^a1kmqmZQy!ZcnF>m=Y0LykEe;KPL{Qv*} literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f017b1abca864b94489a33c0f741a42b6699a2b2 GIT binary patch literal 154 zcmV;L0A>Gp0iDiE3c@fHg<;28Mdm`ec{TwNrw+P^n@4M)X&|PPZpn4HF9YHRoE`qb z$MGfS)F@}{)M|{>&Yq(S0gP1)z$r6o=Y`Y(gLZCq!bU5&B)GRnsdP$Pz9V=y!@Ff%bx$Vkn}$=Ay&X0Up{V)k#2C7HEH9N*n6V0~@i LoN@yIO{o!lE{_&h literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..9d54c76c6171d65662bee597e2350c3535a30a57 GIT binary patch literal 46 zcmV+}0MY+=0ZYosPf{>3W~k;;00O0=(wx*{B`XC87c5kqnwtp}F#;>7<*MZZ06*gk EkfyZ}r~m)} literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..7fa950f576bc1b30e63f259cc848b038806a612e GIT binary patch literal 179 zcmV;k08IaQ0j||eecnqOhy1fHmu+oyx@Mg29hH2Pz0n#5 h=M>0&>w{?89#{THOI$dY7t1H-iORjq;tQT5Si)MfR1g3F literal 0 HcmV?d00001 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 -- 2.41.0