aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/pronto
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 /lib/pronto
parentce89f9ed8a80a06d26b0618658733956d0c98f84 (diff)
downloadpronto-hlint-9be00a3292ddbbf280ac6d92b5b8add7f8ae9508.tar.gz
pronto-hlint-9be00a3292ddbbf280ac6d92b5b8add7f8ae9508.tar.zst
pronto-hlint-9be00a3292ddbbf280ac6d92b5b8add7f8ae9508.zip
Implement ESLint runner
Diffstat (limited to 'lib/pronto')
-rw-r--r--lib/pronto/eslint.rb36
-rw-r--r--lib/pronto/eslint/version.rb5
2 files changed, 41 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