]>
git.immae.eu Git - github/fretlink/pronto-hlint.git/blob - lib/pronto/eslint_npm.rb
5 class ESLintNpm
< Runner
7 attr_writer
:eslint_executable, :files_to_lint
10 @eslint_executable || 'eslint'.freeze
14 @files_to_lint || /(\.js|\.es6)$/
19 return [] unless @patches
22 .select
{ |patch
| patch
.additions
> 0 }
23 .select
{ |patch
| js_file
?(patch
.new_file_full_path
) }
24 .map
{ |patch
| inspect(patch
) }
31 @_repo_path ||= @patches.first
.repo
.path
33 offences
= run_eslint(patch
)
34 clean_up_eslint_output(offences
)
38 .select
{ |line
| line
.new_lineno
== offence
['line'] }
39 .map
{ |line
| new_message(offence
, line
) }
43 def new_message(offence
, line
)
44 path
= line
.patch
.delta
.new_file
[:path]
47 Message
.new(path
, line
, level
, offence
['message'], nil, self.class)
51 self.class.files_to_lint
=~ path
.to_s
55 Dir
.chdir(@_repo_path) do
56 escaped_file_path
= Shellwords
.escape(patch
.new_file_full_path
.to_s
)
58 `#{self.class.eslint_executable} #{escaped_file_path} -f json`
63 def clean_up_eslint_output(output
)
64 # 1. Filter out offences without a warning or error
65 # 2. Get the messages for that file
66 # 3. Ignore errors without a line number for now
68 .select
{ |offence
| offence
['errorCount'] + offence
['warningCount'] > 0 }
69 .map
{ |offence
| offence
['messages'] }
70 .flatten
.select
{ |offence
| offence
['line'] }