]> git.immae.eu Git - github/fretlink/pronto-hlint.git/commitdiff
added ability to set config opts to eslint (#9)
authorbbsteventill <still3@bloomberg.net>
Sat, 31 Mar 2018 17:01:17 +0000 (13:01 -0400)
committerMarkus Doits <doits@users.noreply.github.com>
Sat, 31 Mar 2018 17:01:17 +0000 (19:01 +0200)
* added ability to set config opts to eslint

* add spec for eslint command line

README.md
lib/pronto/eslint_npm.rb
lib/pronto/eslint_npm/version.rb
spec/pronto/eslint_spec.rb

index f5b0d5e71366c466df985685bbfd6d97dd6992fc..508080ba720f20329ca05eacec31cb14b48b9ecb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ Following options are available:
 | ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- |
 | eslint_executable | ESLint executable to call.                                                               | `eslint` (calls `eslint` in `PATH`) |
 | files_to_lint     | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.js|\.es6)$`                     |
+| cmd_line_opts     | Command line options to pass to eslint when running                                      | ''                                  |
 
 Example configuration to call custom eslint executable and only lint files ending with `.my_custom_extension`:
 
@@ -41,4 +42,5 @@ Example configuration to call custom eslint executable and only lint files endin
 # .pronto_eslint_npm.yml
 eslint_executable: '/my/custom/node/path/.bin/eslint'
 files_to_lint: '\.my_custom_extension$'
+cmd_line_opts: '--ext .html,.js,.es6'
 ```
index 63a215b2c8dda131ca89eef51e971ccc59de21ba..6a9c00c9b66b8a3c650bc955ff9399fdd2764ca3 100644 (file)
@@ -6,9 +6,9 @@ require 'shellwords'
 module Pronto
   class ESLintNpm < Runner
     CONFIG_FILE = '.pronto_eslint_npm.yml'.freeze
-    CONFIG_KEYS = %w[eslint_executable files_to_lint].freeze
+    CONFIG_KEYS = %w[eslint_executable files_to_lint cmd_line_opts].freeze
 
-    attr_writer :eslint_executable
+    attr_writer :eslint_executable, :cmd_line_opts
 
     def eslint_executable
       @eslint_executable || 'eslint'
@@ -18,6 +18,10 @@ module Pronto
       @files_to_lint || /(\.js|\.es6)$/
     end
 
+    def cmd_line_opts
+      @cmd_line_opts || ''
+    end
+
     def files_to_lint=(regexp)
       @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp)
     end
@@ -84,7 +88,7 @@ module Pronto
     end
 
     def eslint_command_line(path)
-      "#{eslint_executable} #{Shellwords.escape(path)} -f json"
+      "#{eslint_executable} #{cmd_line_opts} #{Shellwords.escape(path)} -f json"
     end
 
     def clean_up_eslint_output(output)
index 2d3f9d86ff337ece529ccb70d60f0d7c07089bc8..1fc96c9790ad28cd2aae6eb8c7c444433d6c86fd 100644 (file)
@@ -2,6 +2,6 @@
 
 module Pronto
   module ESLintNpmVersion
-    VERSION = '0.9.0'.freeze
+    VERSION = '0.9.1'.freeze
   end
 end
index a00a05b519656393d6bb898916491e6832bc1e5b..0924f30177dec26d75a5d626f5462f175f924ff5 100644 (file)
@@ -57,6 +57,15 @@ module Pronto
           end
         end
 
+        context(
+          'with cmd_line_opts to include .html',
+          config: { 'cmd_line_opts' => '--ext .html' }
+        ) do
+          it 'returns correct number of errors' do
+            expect(run.count).to eql 5
+          end
+        end
+
         context(
           'with different eslint executable',
           config: { 'eslint_executable' => './custom_eslint.sh' }
@@ -139,6 +148,16 @@ module Pronto
           expect(eslint_command_line).not_to include(path)
         end
       end
+      
+      context(
+        'with some command line options',
+        config: { 'cmd_line_opts' => '--my command --line opts' }
+      ) do
+        it 'includes the custom command line options' do
+          eslint.read_config
+          expect(eslint_command_line).to include('--my command --line opts')
+        end
+      end
     end
   end
 end