aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorbbsteventill <still3@bloomberg.net>2018-03-31 13:01:17 -0400
committerMarkus Doits <doits@users.noreply.github.com>2018-03-31 19:01:17 +0200
commit12df00b5e5ac8287afad0f2d52aa0f35a6e8a2ee (patch)
tree4e261ede9bd5e6f254aca842b3826b68eddaf1bf
parentf411af6f829477af0bdca765eb5cc3d40c104294 (diff)
downloadpronto-hlint-12df00b5e5ac8287afad0f2d52aa0f35a6e8a2ee.tar.gz
pronto-hlint-12df00b5e5ac8287afad0f2d52aa0f35a6e8a2ee.tar.zst
pronto-hlint-12df00b5e5ac8287afad0f2d52aa0f35a6e8a2ee.zip
added ability to set config opts to eslint (#9)
* added ability to set config opts to eslint * add spec for eslint command line
-rw-r--r--README.md2
-rw-r--r--lib/pronto/eslint_npm.rb10
-rw-r--r--lib/pronto/eslint_npm/version.rb2
-rw-r--r--spec/pronto/eslint_spec.rb19
4 files changed, 29 insertions, 4 deletions
diff --git a/README.md b/README.md
index f5b0d5e..508080b 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ Following options are available:
34| ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- | 34| ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- |
35| eslint_executable | ESLint executable to call. | `eslint` (calls `eslint` in `PATH`) | 35| eslint_executable | ESLint executable to call. | `eslint` (calls `eslint` in `PATH`) |
36| files_to_lint | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.js|\.es6)$` | 36| files_to_lint | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.js|\.es6)$` |
37| cmd_line_opts | Command line options to pass to eslint when running | '' |
37 38
38Example configuration to call custom eslint executable and only lint files ending with `.my_custom_extension`: 39Example configuration to call custom eslint executable and only lint files ending with `.my_custom_extension`:
39 40
@@ -41,4 +42,5 @@ Example configuration to call custom eslint executable and only lint files endin
41# .pronto_eslint_npm.yml 42# .pronto_eslint_npm.yml
42eslint_executable: '/my/custom/node/path/.bin/eslint' 43eslint_executable: '/my/custom/node/path/.bin/eslint'
43files_to_lint: '\.my_custom_extension$' 44files_to_lint: '\.my_custom_extension$'
45cmd_line_opts: '--ext .html,.js,.es6'
44``` 46```
diff --git a/lib/pronto/eslint_npm.rb b/lib/pronto/eslint_npm.rb
index 63a215b..6a9c00c 100644
--- a/lib/pronto/eslint_npm.rb
+++ b/lib/pronto/eslint_npm.rb
@@ -6,9 +6,9 @@ require 'shellwords'
6module Pronto 6module Pronto
7 class ESLintNpm < Runner 7 class ESLintNpm < Runner
8 CONFIG_FILE = '.pronto_eslint_npm.yml'.freeze 8 CONFIG_FILE = '.pronto_eslint_npm.yml'.freeze
9 CONFIG_KEYS = %w[eslint_executable files_to_lint].freeze 9 CONFIG_KEYS = %w[eslint_executable files_to_lint cmd_line_opts].freeze
10 10
11 attr_writer :eslint_executable 11 attr_writer :eslint_executable, :cmd_line_opts
12 12
13 def eslint_executable 13 def eslint_executable
14 @eslint_executable || 'eslint' 14 @eslint_executable || 'eslint'
@@ -18,6 +18,10 @@ module Pronto
18 @files_to_lint || /(\.js|\.es6)$/ 18 @files_to_lint || /(\.js|\.es6)$/
19 end 19 end
20 20
21 def cmd_line_opts
22 @cmd_line_opts || ''
23 end
24
21 def files_to_lint=(regexp) 25 def files_to_lint=(regexp)
22 @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp) 26 @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp)
23 end 27 end
@@ -84,7 +88,7 @@ module Pronto
84 end 88 end
85 89
86 def eslint_command_line(path) 90 def eslint_command_line(path)
87 "#{eslint_executable} #{Shellwords.escape(path)} -f json" 91 "#{eslint_executable} #{cmd_line_opts} #{Shellwords.escape(path)} -f json"
88 end 92 end
89 93
90 def clean_up_eslint_output(output) 94 def clean_up_eslint_output(output)
diff --git a/lib/pronto/eslint_npm/version.rb b/lib/pronto/eslint_npm/version.rb
index 2d3f9d8..1fc96c9 100644
--- a/lib/pronto/eslint_npm/version.rb
+++ b/lib/pronto/eslint_npm/version.rb
@@ -2,6 +2,6 @@
2 2
3module Pronto 3module Pronto
4 module ESLintNpmVersion 4 module ESLintNpmVersion
5 VERSION = '0.9.0'.freeze 5 VERSION = '0.9.1'.freeze
6 end 6 end
7end 7end
diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb
index a00a05b..0924f30 100644
--- a/spec/pronto/eslint_spec.rb
+++ b/spec/pronto/eslint_spec.rb
@@ -58,6 +58,15 @@ module Pronto
58 end 58 end
59 59
60 context( 60 context(
61 'with cmd_line_opts to include .html',
62 config: { 'cmd_line_opts' => '--ext .html' }
63 ) do
64 it 'returns correct number of errors' do
65 expect(run.count).to eql 5
66 end
67 end
68
69 context(
61 'with different eslint executable', 70 'with different eslint executable',
62 config: { 'eslint_executable' => './custom_eslint.sh' } 71 config: { 'eslint_executable' => './custom_eslint.sh' }
63 ) do 72 ) do
@@ -139,6 +148,16 @@ module Pronto
139 expect(eslint_command_line).not_to include(path) 148 expect(eslint_command_line).not_to include(path)
140 end 149 end
141 end 150 end
151
152 context(
153 'with some command line options',
154 config: { 'cmd_line_opts' => '--my command --line opts' }
155 ) do
156 it 'includes the custom command line options' do
157 eslint.read_config
158 expect(eslint_command_line).to include('--my command --line opts')
159 end
160 end
142 end 161 end
143 end 162 end
144end 163end