From 295096252547f3abb76788fbadf0ce059e74f2cc Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Mon, 25 Jul 2016 16:03:07 +0200 Subject: Use system eslint instead of eslintrb This makes sure `eslint` works as expected, e.g. the config used is respected and full feature set is present. One has to make sure `eslint` is properly installed, though. --- lib/pronto/eslint.rb | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/pronto/eslint.rb b/lib/pronto/eslint.rb index 990081e..fa4261d 100644 --- a/lib/pronto/eslint.rb +++ b/lib/pronto/eslint.rb @@ -1,6 +1,4 @@ require 'pronto' -require 'eslintrb' -require 'globby' module Pronto class ESLint < Runner @@ -14,8 +12,19 @@ module Pronto end def inspect(patch) - options = File.exist?('.eslintrc') ? :eslintrc : :defaults - offences = Eslintrb.lint(patch.new_file_full_path, options).compact + @_repo_path ||= @patches.first.repo.path + + offences = + Dir.chdir(@_repo_path) do + JSON.parse(`eslint #{patch.new_file_full_path} -f json`) + end + + offences = + offences + .select { |offence| offence['errorCount'] > 0 || offence['warningCount'] > 0 } # no warning or error, no problem + .map { |offence| offence['messages'] } # get error messages for that file + .flatten + .select { |offence| offence['line'] } # for now ignore errors without a line number offences.map do |offence| patch.added_lines.select { |line| line.new_lineno == offence['line'] } @@ -31,26 +40,7 @@ module Pronto end def js_file?(path) - %w(.js .es6 .js.es6).include?(File.extname(path)) && !eslintignore_matches?(path) - end - - def eslintignore_matches?(path) - @_repo_path ||= @patches.first.repo.path - @_eslintignore_path ||= File.join(@_repo_path, '.eslintignore') - @_eslintignore_exists ||= File.exist?(@_eslintignore_path) - - return false unless @_eslintignore_exists - - @_eslintignored_files ||= - Dir.chdir @_repo_path do # change to the repo path where `.eslintignore` was found - eslintignore_content = File.readlines(@_eslintignore_path).map(&:chomp) - ignored_files = Globby.select(eslintignore_content) - - # prefix each found file with `repo_path`, because `path` is absolute, too - ignored_files.map { |file| File.join(@_repo_path, file).to_s } - end - - @_eslintignored_files.include?(path.to_s) + %w(.js .es6 .js.es6).include?(File.extname(path)) end end end -- cgit v1.2.3