5 class ESLintNpm
< Runner
6 CONFIG_FILE
= '.pronto_eslint_npm.yml'.freeze
7 CONFIG_KEYS
= %w(eslint_executable files_to_lint
).freeze
9 attr_writer
:eslint_executable
12 @eslint_executable || 'eslint'.freeze
16 @files_to_lint || /(\.js|\.es6)$/
19 def files_to_lint
=(regexp
)
20 @files_to_lint = regexp
.is_a
?(Regexp
) && regexp
|| Regexp
.new(regexp
)
24 config_file
= File
.join(repo_path
, CONFIG_FILE
)
25 return unless File
.exist
?(config_file
)
26 config
= YAML
.load_file(config_file
)
28 CONFIG_KEYS
.each
do |config_key
|
29 next unless config
[config_key
]
30 send("#{config_key}=", config
[config_key
])
35 return [] if !
@patches || @patches.count
.zero
?
40 .select
{ |patch
| patch
.additions
> 0 }
41 .select
{ |patch
| js_file
?(patch
.new_file_full_path
) }
42 .map
{ |patch
| inspect(patch
) }
49 @_repo_path ||= @patches.first
.repo
.path
53 offences
= run_eslint(patch
)
54 clean_up_eslint_output(offences
)
58 .select
{ |line
| line
.new_lineno
== offence
['line'] }
59 .map
{ |line
| new_message(offence
, line
) }
63 def new_message(offence
, line
)
64 path
= line
.patch
.delta
.new_file
[:path]
67 Message
.new(path
, line
, level
, offence
['message'], nil, self.class)
71 files_to_lint
=~ path
.to_s
75 Dir
.chdir(repo_path
) do
76 escaped_file_path
= Shellwords
.escape(patch
.new_file_full_path
.to_s
)
78 `#{eslint_executable} #{escaped_file_path} -f json`
83 def clean_up_eslint_output(output
)
84 # 1. Filter out offences without a warning or error
85 # 2. Get the messages for that file
86 # 3. Ignore errors without a line number for now
88 .select
{ |offence
| offence
['errorCount'] + offence
['warningCount'] > 0 }
89 .map
{ |offence
| offence
['messages'] }
90 .flatten
.select
{ |offence
| offence
['line'] }