danger-eslint 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7662c84b8cf4e59149bf5b1db89546f206ee42d0
4
- data.tar.gz: dc030966e2fb57ced713cba5c5d48a7e2ae89845
3
+ metadata.gz: 6f1c2b1f5cc50b20e1fb7684a101fda696347842
4
+ data.tar.gz: 7ebd2562a9f5954fba18e24d9ce502d31eb642f5
5
5
  SHA512:
6
- metadata.gz: 5e1d78c20be447625d058b7eb476ae6c0bd7a354101af3a40937abb7e5ea9a601b341be5eb6ae4903325ac3cea1e3197e9ddb3e13cd433bbd9cb1e5c985cbab2
7
- data.tar.gz: 365b88444f32fd81840bcd4f1a03d6e2024e111c5e00f6c5359140cfc508ae9a5e7b0fd6ddb3e9878513dbe392bae21d7bc1282be5a8bd28a03746a382e05ab6
6
+ metadata.gz: 6dc3f8c06853abd290391b436c8551b398a3f6d07957f4977d2fbb81e1024cca4b08544e783ec00e7324979d56405134b2f6f5c9f628368d68953dd895d7b0fb
7
+ data.tar.gz: fb7132d0d87f09efeb9f5231e7a1575962939b9b4ca631fa7e31a364ae032ed63b294b7d28512f7a296cfc15d264f3ec83aa1cd770c5438ec29c7c8ff3c442ad
@@ -1,3 +1,5 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
1
3
 
2
4
  Metrics/BlockLength:
3
5
  Exclude:
@@ -4,9 +4,8 @@ cache:
4
4
  - bundle
5
5
 
6
6
  rvm:
7
- - 2.0
8
7
  - 2.1.3
9
8
  - 2.3.1
10
9
 
11
10
  script:
12
- - bundle exec rake spec
11
+ - bundle exec rake spec
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
@@ -1,3 +1,3 @@
1
1
  module Eslint
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
@@ -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
- local = './node_modules/.bin/eslint'
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| f.end_with? '.js' }
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
@@ -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
- allow(@eslint).to receive(:eslint_path).and_return('eslint')
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
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: 2018-06-28 00:00:00.000000000 Z
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