]>
git.immae.eu Git - github/fretlink/pronto-hlint.git/blob - lib/pronto/eslint_npm.rb
5 class ESLintNpm
< Runner
7 return [] unless @patches
9 @patches.select
{ |patch
| patch
.additions
> 0 }
10 .select
{ |patch
| js_file
?(patch
.new_file_full_path
) }
11 .map
{ |patch
| inspect(patch
) }
16 @_repo_path ||= @patches.first
.repo
.path
18 offences
= run_eslint(patch
)
19 clean_up_eslint_output(offences
)
23 .select
{ |line
| line
.new_lineno
== offence
['line'] }
24 .map
{ |line
| new_message(offence
, line
) }
30 def new_message(offence
, line
)
31 path
= line
.patch
.delta
.new_file
[:path]
34 Message
.new(path
, line
, level
, offence
['message'], nil, self.class)
38 %w(.js
.es6
.js
.es6
).include?(File
.extname(path
))
42 Dir
.chdir(@_repo_path) do
44 `eslint #{Shellwords.escape(patch.new_file_full_path.to_s)} -f json`
49 # rubocop:disable Metrics/LineLength
50 def clean_up_eslint_output(output
)
51 # 1. Filter out offences without a warning or error
52 # 2. Get the messages for that file
53 # 3. Ignore errors without a line number for now
55 .select
{ |offence
| offence
['errorCount'] + offence
['warningCount'] > 0 }
56 .map
{ |offence
| offence
['messages'] }
57 .flatten
.select
{ |offence
| offence
['line'] }