]> git.immae.eu Git - github/fretlink/pronto-hlint.git/commitdiff
Use system eslint instead of eslintrb
authorMarkus Doits <markus.doits@stellenticket.de>
Mon, 25 Jul 2016 14:03:07 +0000 (16:03 +0200)
committerMarkus Doits <markus.doits@stellenticket.de>
Mon, 25 Jul 2016 14:03:07 +0000 (16:03 +0200)
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
pronto-eslint.gemspec
spec/fixtures/eslintignore.git/.eslintrc [new file with mode: 0644]
spec/fixtures/test.git/.eslintrc [new file with mode: 0644]
spec/fixtures/test.git/hello.js
spec/pronto/eslint_spec.rb

index 990081e5c2d72785623b2051efb6eb9e138d8a95..fa4261d184108e137830a7f993d4aea67e79b4cd 100644 (file)
@@ -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
index 9ad00ecf31c586af9f1938cb38514415215d4168..d6590ecf2e75d9c073567923325944139c9e624d 100644 (file)
@@ -35,8 +35,6 @@ Gem::Specification.new do |s|
   s.require_paths = ['lib']
 
   s.add_dependency('pronto', '~> 0.6.0')
-  s.add_dependency('eslintrb', '~> 2.0', '>= 2.0.0')
-  s.add_dependency('globby', '~> 0.1')
   s.add_development_dependency('rake', '~> 11.0')
   s.add_development_dependency('rspec', '~> 3.4')
   s.add_development_dependency('rspec-its', '~> 1.2')
diff --git a/spec/fixtures/eslintignore.git/.eslintrc b/spec/fixtures/eslintignore.git/.eslintrc
new file mode 100644 (file)
index 0000000..f94ba96
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "env": {
+        "browser": true,
+        "es6": true
+    },
+    "extends": "eslint:recommended"
+}
diff --git a/spec/fixtures/test.git/.eslintrc b/spec/fixtures/test.git/.eslintrc
new file mode 100644 (file)
index 0000000..f94ba96
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "env": {
+        "browser": true,
+        "es6": true
+    },
+    "extends": "eslint:recommended"
+}
index 2d1b9966feb19d665a9e5bb6a5bde410203a68f7..6ad633db432a49be5b32435821d33a839db70d38 100644 (file)
@@ -3,3 +3,5 @@ function HelloWorld(name)
     if (foo) foo++;
     alert(name);
 }
+
+function Empty() {}
index 1117e15f1ed4372a9f565e7efd61e0e22ab1cc11..27f57d170983c7561e68918d2a21f36b9cba7f36 100644 (file)
@@ -17,22 +17,22 @@ module Pronto
         it { should == [] }
       end
 
-      context 'patches with a four and a five warnings' do
+      context 'patches with a one and a four warnings' do
         include_context 'test repo'
 
         let(:patches) { repo.diff('master') }
 
-        its(:count) { should == 9 }
-        its(:'first.msg') { should == "Expected { after 'if' condition." }
+        its(:count) { should == 5 }
+        its(:'first.msg') { should == "'foo' is not defined." }
       end
 
-      context 'repo with ignored and not ignored file, each with five warnings' do
+      context 'repo with ignored and not ignored file, each with three warnings' do
         include_context 'eslintignore repo'
 
         let(:patches) { repo.diff('master') }
 
-        its(:count) { should == 5 }
-        its(:'first.msg') { should == "Use the function form of 'use strict'." }
+        its(:count) { should == 3 }
+        its(:'first.msg') { should == "'HelloWorld' is defined but never used" }
       end
     end
   end