danger-eslint 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.travis.yml +1 -2
- data/README.md +12 -0
- data/lib/eslint/gem_version.rb +1 -1
- data/lib/eslint/plugin.rb +18 -3
- data/spec/eslint_spec.rb +37 -1
- data/spec/fixtures/bin/dummy_eslint +0 -0
- data/spec/fixtures/bin/somewhere_eslint +0 -0
- data/spec/fixtures/javascript/error.es6 +1 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f1c2b1f5cc50b20e1fb7684a101fda696347842
|
4
|
+
data.tar.gz: 7ebd2562a9f5954fba18e24d9ce502d31eb642f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc3f8c06853abd290391b436c8551b398a3f6d07957f4977d2fbb81e1024cca4b08544e783ec00e7324979d56405134b2f6f5c9f628368d68953dd895d7b0fb
|
7
|
+
data.tar.gz: fb7132d0d87f09efeb9f5231e7a1575962939b9b4ca631fa7e31a364ae032ed63b294b7d28512f7a296cfc15d264f3ec83aa1cd770c5438ec29c7c8ff3c442ad
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,18 @@ If you want to lint only new/modified files. You can achieve that with setting t
|
|
30
30
|
eslint.filtering = true
|
31
31
|
eslint.lint
|
32
32
|
|
33
|
+
If you want to lint files with specified extension, you can set extensions to the `target_extensions` parameter.
|
34
|
+
The default value is `['.js']`. In the case of the example below, the value will be `['.js', '.es6']`.
|
35
|
+
|
36
|
+
eslint.target_extensions += %W(.es6)
|
37
|
+
eslint.lint
|
38
|
+
|
39
|
+
If you want to specify eslint's bin file, you can set a bin path to the `bin_path` parameter.
|
40
|
+
|
41
|
+
eslint.bin_path = "/hoge/node_modules/.bin/eslint"
|
42
|
+
eslint.lint
|
43
|
+
|
44
|
+
|
33
45
|
## Development
|
34
46
|
|
35
47
|
1. Clone this repo
|
data/lib/eslint/gem_version.rb
CHANGED
data/lib/eslint/plugin.rb
CHANGED
@@ -13,6 +13,8 @@ module Danger
|
|
13
13
|
# @see leonhartX/danger-eslint
|
14
14
|
# @tags lint, javaxctipt
|
15
15
|
class DangerEslint < Plugin
|
16
|
+
DEFAULT_BIN_PATH = './node_modules/.bin/eslint'
|
17
|
+
|
16
18
|
# An path to eslint's config file
|
17
19
|
# @return [String]
|
18
20
|
attr_accessor :config_file
|
@@ -26,6 +28,20 @@ module Danger
|
|
26
28
|
# @return [Boolean]
|
27
29
|
attr_accessor :filtering
|
28
30
|
|
31
|
+
# A path of eslint's bin
|
32
|
+
attr_writer :bin_path
|
33
|
+
def bin_path
|
34
|
+
@bin_path ||= DEFAULT_BIN_PATH
|
35
|
+
end
|
36
|
+
|
37
|
+
# Specified extentions of target file
|
38
|
+
# Default is [".js"]
|
39
|
+
# @return [Array]
|
40
|
+
attr_writer :target_extensions
|
41
|
+
def target_extensions
|
42
|
+
@target_extensions ||= %W(.js)
|
43
|
+
end
|
44
|
+
|
29
45
|
# Lints javascript files.
|
30
46
|
# Generates `errors` and `warnings` due to eslint's config.
|
31
47
|
# Will try to send inline comment if supported(Github)
|
@@ -45,8 +61,7 @@ module Danger
|
|
45
61
|
#
|
46
62
|
# return [String]
|
47
63
|
def eslint_path
|
48
|
-
|
49
|
-
File.exist?(local) ? local : find_executable('eslint')
|
64
|
+
File.exist?(bin_path) ? bin_path : find_executable('eslint')
|
50
65
|
end
|
51
66
|
|
52
67
|
# Get lint result regards the filtering option
|
@@ -57,7 +72,7 @@ module Danger
|
|
57
72
|
raise 'eslint is not installed' unless bin
|
58
73
|
return run_lint(bin, '.') unless filtering
|
59
74
|
((git.modified_files - git.deleted_files) + git.added_files)
|
60
|
-
.select { |f|
|
75
|
+
.select { |f| target_extensions.include?(File.extname(f)) }
|
61
76
|
.map { |f| f.gsub("#{Dir.pwd}/", '') }
|
62
77
|
.map { |f| run_lint(bin, f).first }
|
63
78
|
end
|
data/spec/eslint_spec.rb
CHANGED
@@ -16,7 +16,7 @@ module Danger
|
|
16
16
|
allow(@eslint.git).to receive(:deleted_files).and_return([])
|
17
17
|
allow(@eslint.git).to receive(:added_files).and_return([])
|
18
18
|
allow(@eslint.git).to receive(:modified_files).and_return([])
|
19
|
-
|
19
|
+
stub_const("Danger::DangerEslint::DEFAULT_BIN_PATH", 'spec/fixtures/bin/dummy_eslint')
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'does not make an empty message' do
|
@@ -81,6 +81,27 @@ module Danger
|
|
81
81
|
expect(@eslint.status_report[:warnings].length).to be(0)
|
82
82
|
end
|
83
83
|
|
84
|
+
it 'lint files with specified extention by target_extensions' do
|
85
|
+
allow(@eslint).to receive(:run_lint)
|
86
|
+
.with(anything, /error.[js|es6]/).and_return(@error_result)
|
87
|
+
allow(@eslint.git).to receive(:modified_files)
|
88
|
+
.and_return([
|
89
|
+
'spec/fixtures/javascript/error.es6',
|
90
|
+
'spec/fixtures/javascript/error.js'
|
91
|
+
])
|
92
|
+
|
93
|
+
@eslint.target_extensions += %W(.es6)
|
94
|
+
@eslint.filtering = true
|
95
|
+
@eslint.lint
|
96
|
+
|
97
|
+
errors = @eslint.status_report[:errors]
|
98
|
+
expect(errors.length).to be(2)
|
99
|
+
errors.each do |error|
|
100
|
+
expect(error).to eq('Parsing error: Unexpected token ;')
|
101
|
+
end
|
102
|
+
expect(@eslint.status_report[:warnings].length).to be(0)
|
103
|
+
end
|
104
|
+
|
84
105
|
it 'do not print anything if no violations' do
|
85
106
|
allow(@eslint.git).to receive(:modified_files)
|
86
107
|
.and_return(['spec/fixtures/javascript/empty.js'])
|
@@ -132,6 +153,21 @@ module Danger
|
|
132
153
|
expect(@eslint.status_report[:errors].length).to be(1)
|
133
154
|
expect(@eslint.status_report[:warnings].length).to be(2)
|
134
155
|
end
|
156
|
+
|
157
|
+
it 'can specify eslint bin file' do
|
158
|
+
bin_file = 'spec/fixtures/bin/somewhere_eslint'
|
159
|
+
expect(@eslint).to receive(:run_lint)
|
160
|
+
.with(bin_file, /error.js/).and_return(@error_result)
|
161
|
+
allow(@eslint.git).to receive(:modified_files)
|
162
|
+
.and_return(['spec/fixtures/javascript/error.js'])
|
163
|
+
|
164
|
+
@eslint.bin_path = bin_file
|
165
|
+
@eslint.filtering = true
|
166
|
+
@eslint.lint
|
167
|
+
error = @eslint.status_report[:errors].first
|
168
|
+
expect(error).to eq('Parsing error: Unexpected token ;')
|
169
|
+
expect(@eslint.status_report[:warnings].length).to be(0)
|
170
|
+
end
|
135
171
|
end
|
136
172
|
end
|
137
173
|
end
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
var a = ;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-eslint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- leonhartX
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -174,9 +174,12 @@ files:
|
|
174
174
|
- lib/eslint/gem_version.rb
|
175
175
|
- lib/eslint/plugin.rb
|
176
176
|
- spec/eslint_spec.rb
|
177
|
+
- spec/fixtures/bin/dummy_eslint
|
178
|
+
- spec/fixtures/bin/somewhere_eslint
|
177
179
|
- spec/fixtures/config/.eslintignore
|
178
180
|
- spec/fixtures/config/.eslintrc.json
|
179
181
|
- spec/fixtures/javascript/empty.js
|
182
|
+
- spec/fixtures/javascript/error.es6
|
180
183
|
- spec/fixtures/javascript/error.js
|
181
184
|
- spec/fixtures/javascript/ignored.js
|
182
185
|
- spec/fixtures/javascript/warning.js
|
@@ -207,15 +210,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
210
|
version: '0'
|
208
211
|
requirements: []
|
209
212
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.5.2
|
213
|
+
rubygems_version: 2.5.2.3
|
211
214
|
signing_key:
|
212
215
|
specification_version: 4
|
213
216
|
summary: A Danger plugin for linting javascript with eslint.
|
214
217
|
test_files:
|
215
218
|
- spec/eslint_spec.rb
|
219
|
+
- spec/fixtures/bin/dummy_eslint
|
220
|
+
- spec/fixtures/bin/somewhere_eslint
|
216
221
|
- spec/fixtures/config/.eslintignore
|
217
222
|
- spec/fixtures/config/.eslintrc.json
|
218
223
|
- spec/fixtures/javascript/empty.js
|
224
|
+
- spec/fixtures/javascript/error.es6
|
219
225
|
- spec/fixtures/javascript/error.js
|
220
226
|
- spec/fixtures/javascript/ignored.js
|
221
227
|
- spec/fixtures/javascript/warning.js
|