]>
git.immae.eu Git - github/fretlink/pronto-hlint.git/blob - lib/pronto/eslint.rb
8 return [] unless @patches
10 @patches.select
{ |patch
| patch
.additions
> 0 }
11 .select
{ |patch
| js_file
?(patch
.new_file_full_path
) }
12 .map
{ |patch
| inspect(patch
) }
17 options
= File
.exist
?('.eslintrc') ? :eslintrc : :defaults
18 offences
= Eslintrb
.lint(patch
.new_file_full_path
, options
).compact
20 offences
.map
do |offence
|
21 patch
.added_lines
.select
{ |line
| line
.new_lineno
== offence
['line'] }
22 .map
{ |line
| new_message(offence
, line
) }
26 def new_message(offence
, line
)
27 path
= line
.patch
.delta
.new_file
[:path]
30 Message
.new(path
, line
, level
, offence
['message'], nil, self.class)
34 %w(.js
.es6
.js
.es6
).include?(File
.extname(path
)) && !eslintignore_matches
?(path
)
37 def eslintignore_matches
?(path
)
38 @_repo_path ||= @patches.first
.repo
.path
39 @_eslintignore_path ||= File
.join(@_repo_path, '.eslintignore')
40 @_eslintignore_exists ||= File
.exist
?(@_eslintignore_path)
42 return false unless @_eslintignore_exists
44 @_eslintignored_files ||=
45 Dir
.chdir
@_repo_path do # change to the repo path where `.eslintignore` was found
46 eslintignore_content
= File
.readlines(@_eslintignore_path).map(&:chomp)
47 ignored_files
= Globby
.select(eslintignore_content
)
49 # prefix each found file with `repo_path`, because `path` is absolute, too
50 ignored_files
.map
{ |file
| File
.join(@_repo_path, file
).to_s
}
53 @_eslintignored_files.include?(path
.to_s
)