danger-swiftlint 0.22.0 → 0.23.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c86940adc167f7b4863e444266b96770155c2ab8
4
- data.tar.gz: c398255b1c603ed1e979426afba4a9a4c73f3a40
2
+ SHA256:
3
+ metadata.gz: d124a22a2db51e5527b4a8032d543ed75904a0fcf01fc539686bddceaddb25c2
4
+ data.tar.gz: fbd279ea07e0ee226252862b25bb459babe781da4e7466654b4361376d72fefc
5
5
  SHA512:
6
- metadata.gz: 71f4b0e1f6e4fb1238d3934d58feefe9f1a113bcb640bc2a8f3fd6089565c73cb6f8d23e2023e0af1efdfb4fb59d996ac14cd329c5f3cccbca5e84186868ef65
7
- data.tar.gz: 18ecfda87f5bc8cc1cd3bb2670530505550b95a938d5e4c62d2566838a3c114cde4f4c6651a73a97b309402feef4ff457275484ab3a5f5f415dd86d0d7057c55
6
+ metadata.gz: 6cc159309e6692bc75cb8f55b81b5baa5fc01c8942d5b7738d3ea51b41e402cf01ffa9d4a1f0fce2b5a53210609f9d2d4e044dbbf901dec7d360922d1e0c9a6f
7
+ data.tar.gz: 372946ca17a1f473a699833c103946aec9a47b8eda7b5d400fc26547358becef01ac7c2a85536911ec7f7ecd7835071938df70c7ffc3db7faec505116c533892
@@ -7,17 +7,24 @@ class Swiftlint
7
7
  end
8
8
 
9
9
  # Runs swiftlint
10
- def run(cmd = 'lint', additional_swiftlint_args = '', options = {})
10
+ def run(cmd = 'lint', additional_swiftlint_args = '', options = {}, env = nil)
11
11
  # change pwd before run swiftlint
12
12
  Dir.chdir options.delete(:pwd) if options.key? :pwd
13
13
 
14
- # run swiftlint with provided options
15
- `#{swiftlint_path} #{cmd} #{swiftlint_arguments(options, additional_swiftlint_args)}`
14
+ # Add `env` to environment
15
+ update_env(env)
16
+ begin
17
+ # run swiftlint with provided options
18
+ `#{swiftlint_path} #{cmd} #{swiftlint_arguments(options, additional_swiftlint_args)}`
19
+ ensure
20
+ # Remove any ENV variables we might have added
21
+ restore_env()
22
+ end
16
23
  end
17
24
 
18
25
  # Shortcut for running the lint command
19
- def lint(options, additional_swiftlint_args)
20
- run('lint', additional_swiftlint_args, options)
26
+ def lint(options, additional_swiftlint_args, env = nil)
27
+ run('lint', additional_swiftlint_args, options, env)
21
28
  end
22
29
 
23
30
  # Return true if swiftlint is installed or false otherwise
@@ -58,4 +65,25 @@ class Swiftlint
58
65
  def default_swiftlint_path
59
66
  File.expand_path(File.join(File.dirname(__FILE__), 'bin', 'swiftlint'))
60
67
  end
68
+
69
+ # Adds `env` to shell environment as variables
70
+ # @param env (Hash) hash containing environment variables to add
71
+ def update_env(env)
72
+ return if !env || env.empty?
73
+ # Keep the same @original_env if we've already set it, since that would mean
74
+ # that we're adding more variables, in which case, we want to make sure to
75
+ # keep the true original when we go to restore it.
76
+ @original_env = ENV.to_h if @original_env.nil?
77
+ # Add `env` to environment
78
+ ENV.update(env)
79
+ end
80
+
81
+ # Restores shell environment to values in `@original_env`
82
+ # All environment variables not in `@original_env` will be removed
83
+ def restore_env()
84
+ if !@original_env.nil?
85
+ ENV.replace(@original_env)
86
+ @original_env = nil
87
+ end
88
+ end
61
89
  end
@@ -176,12 +176,32 @@ module Danger
176
176
  #
177
177
  # @return [Array] swiftlint issues
178
178
  def run_swiftlint_for_each(files, options, additional_swiftlint_args)
179
+ # Use `--use-script-input-files` flag along with `SCRIPT_INPUT_FILE_#` ENV
180
+ # variables to pass the list of files we want swiftlint to lint
181
+ options.merge!(use_script_input_files: true)
182
+
183
+ # Set environment variables:
184
+ # * SCRIPT_INPUT_FILE_COUNT equal to number of files
185
+ # * a variable in the form of SCRIPT_INPUT_FILE_# for each file
186
+ env = script_input(files)
187
+
188
+ result = swiftlint.lint(options, additional_swiftlint_args, env)
189
+ if result == ''
190
+ {}
191
+ else
192
+ JSON.parse(result).flatten
193
+ end
194
+ end
195
+
196
+ # Converts an array of files into `SCRIPT_INPUT_FILE_#` format
197
+ # for use with `--use-script-input-files`
198
+ # @return [Hash] mapping from `SCRIPT_INPUT_FILE_#` to file
199
+ # SCRIPT_INPUT_FILE_COUNT will be set to the number of files
200
+ def script_input(files)
179
201
  files
180
- .map { |file| options.merge(path: file) }
181
- .map { |full_options| swiftlint.lint(full_options, additional_swiftlint_args) }
182
- .reject { |s| s == '' }
183
- .map { |s| JSON.parse(s).flatten }
184
- .flatten
202
+ .map.with_index { |file, i| ["SCRIPT_INPUT_FILE_#{i}", file.to_s] }
203
+ .push(['SCRIPT_INPUT_FILE_COUNT', files.size.to_s])
204
+ .to_h
185
205
  end
186
206
 
187
207
  # Find swift files from the files glob
@@ -189,9 +209,6 @@ module Danger
189
209
  #
190
210
  # @return [Array] swift files
191
211
  def find_swift_files(dir_selected, files = nil, excluded_paths = [], included_paths = [])
192
- # Needs to be escaped before comparsion with escaped file paths
193
- dir_selected = Shellwords.escape(dir_selected)
194
-
195
212
  # Assign files to lint
196
213
  files = if files.nil?
197
214
  (git.modified_files - git.deleted_files) + git.added_files
@@ -202,8 +219,8 @@ module Danger
202
219
  files.
203
220
  # Ensure only swift files are selected
204
221
  select { |file| file.end_with?('.swift') }.
205
- # Make sure we don't fail when paths have spaces
206
- map { |file| Shellwords.escape(File.expand_path(file)) }.
222
+ # Convert to absolute paths
223
+ map { |file| File.expand_path(file) }.
207
224
  # Remove dups
208
225
  uniq.
209
226
  # Ensure only files in the selected directory
@@ -245,7 +262,6 @@ module Danger
245
262
  def file_exists?(paths, file)
246
263
  paths.any? do |path|
247
264
  Find.find(path)
248
- .map { |path_file| Shellwords.escape(path_file) }
249
265
  .include?(file)
250
266
  end
251
267
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DangerSwiftlint
4
- VERSION = '0.22.0'
4
+ VERSION = '0.23.0'
5
5
  SWIFTLINT_VERSION = '0.33.1'
6
6
  end
@@ -52,7 +52,7 @@ module Danger
52
52
 
53
53
  it 'specifies --force-exclude when invoking SwiftLint' do
54
54
  expect_any_instance_of(Swiftlint).to receive(:lint)
55
- .with(hash_including(force_exclude: true), '')
55
+ .with(hash_including(force_exclude: true), '', anything)
56
56
  .and_return(@swiftlint_response)
57
57
 
58
58
  @swiftlint.lint_files('spec/fixtures/*.swift')
@@ -64,7 +64,9 @@ module Danger
64
64
 
65
65
  it 'accept files as arguments' do
66
66
  expect_any_instance_of(Swiftlint).to receive(:lint)
67
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
67
+ .with(anything, '',
68
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
69
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift') })
68
70
  .and_return(@swiftlint_response)
69
71
 
70
72
  @swiftlint.lint_files('spec/fixtures/*.swift')
@@ -74,10 +76,50 @@ module Danger
74
76
  expect(output).to include('SwiftFile.swift | 13 | Force casts should be avoided. (force_cast)')
75
77
  end
76
78
 
79
+ it 'uses --use-script-input-files' do
80
+ expect_any_instance_of(Swiftlint).to receive(:lint)
81
+ .with(hash_including(use_script_input_files: true), '',
82
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
83
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift') })
84
+ .and_return(@swiftlint_response)
85
+
86
+ @swiftlint.lint_files('spec/fixtures/*.swift')
87
+
88
+ output = @swiftlint.status_report[:markdowns].first.to_s
89
+ expect(output).to include('SwiftLint found issues')
90
+ expect(output).to include('SwiftFile.swift | 13 | Force casts should be avoided. (force_cast)')
91
+ end
92
+
93
+ it 'doesn\'t use --path' do
94
+ expect_any_instance_of(Swiftlint).to receive(:lint)
95
+ .with(hash_excluding(:path), '', anything)
96
+ .and_return(@swiftlint_response)
97
+
98
+ @swiftlint.lint_files('spec/fixtures/*.swift')
99
+
100
+ output = @swiftlint.status_report[:markdowns].first.to_s
101
+ expect(output).to include('SwiftLint found issues')
102
+ expect(output).to include('SwiftFile.swift | 13 | Force casts should be avoided. (force_cast)')
103
+ end
104
+
105
+ it 'accept a list of files as arguments' do
106
+ expect_any_instance_of(Swiftlint).to receive(:lint)
107
+ .with(anything, '',
108
+ { 'SCRIPT_INPUT_FILE_COUNT' => '2',
109
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift'),
110
+ 'SCRIPT_INPUT_FILE_1' => a_string_ending_with('spec/fixtures/some_dir/SwiftFile.swift') })
111
+ .and_return(@swiftlint_response)
112
+
113
+ @swiftlint.lint_files(['spec/fixtures/*.swift', 'spec/fixtures/some_dir/*.swift'])
114
+
115
+ output = @swiftlint.status_report[:markdowns].first.to_s
116
+ expect(output).to include('SwiftLint found issues')
117
+ expect(output).to include('SwiftFile.swift | 13 | Force casts should be avoided. (force_cast)')
118
+ end
119
+
77
120
  it 'sets maxium number of violations' do
78
121
  swiftlint_response = '[{ "rule_id" : "force_cast", "reason" : "Force casts should be avoided.", "character" : 19, "file" : "/Users/me/this_repo/spec//fixtures/SwiftFile.swift", "severity" : "Error", "type" : "Force Cast", "line" : 13 }, { "rule_id" : "force_cast", "reason" : "Force casts should be avoided.", "character" : 19, "file" : "/Users/me/this_repo/spec//fixtures/SwiftFile.swift", "severity" : "Error", "type" : "Force Cast", "line" : 14 }]'
79
122
  expect_any_instance_of(Swiftlint).to receive(:lint)
80
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
81
123
  .and_return(swiftlint_response)
82
124
 
83
125
  @swiftlint.max_num_violations = 1
@@ -92,7 +134,7 @@ module Danger
92
134
 
93
135
  it 'accepts additional cli arguments' do
94
136
  expect_any_instance_of(Swiftlint).to receive(:lint)
95
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '--lenient')
137
+ .with(anything, '--lenient', anything)
96
138
  .and_return(@swiftlint_response)
97
139
 
98
140
  @swiftlint.lint_files('spec/fixtures/*.swift', additional_swiftlint_args: '--lenient')
@@ -102,7 +144,9 @@ module Danger
102
144
  allow(@swiftlint.git).to receive(:modified_files).and_return(['spec/fixtures/SwiftFile.swift'])
103
145
  allow(@swiftlint.git).to receive(:added_files).and_return([])
104
146
  allow_any_instance_of(Swiftlint).to receive(:lint)
105
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
147
+ .with(anything, '',
148
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
149
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift') })
106
150
  .and_return(@swiftlint_response)
107
151
 
108
152
  @swiftlint.lint_files
@@ -115,7 +159,7 @@ module Danger
115
159
  @swiftlint.directory = 'spec/fixtures/some_dir'
116
160
 
117
161
  allow_any_instance_of(Swiftlint).to receive(:lint)
118
- .with(hash_including(pwd: File.expand_path(@swiftlint.directory)), '')
162
+ .with(hash_including(pwd: File.expand_path(@swiftlint.directory)), '', anything)
119
163
  .and_return(@swiftlint_response)
120
164
 
121
165
  @swiftlint.lint_files(['spec/fixtures/some_dir/SwiftFile.swift'])
@@ -126,7 +170,7 @@ module Danger
126
170
 
127
171
  it 'uses escaped pwd when directory is not set' do
128
172
  allow_any_instance_of(Swiftlint).to receive(:lint)
129
- .with(hash_including(pwd: File.expand_path('.')), '')
173
+ .with(hash_including(pwd: File.expand_path('.')), '', anything)
130
174
  .and_return(@swiftlint_response)
131
175
 
132
176
  @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'])
@@ -145,7 +189,9 @@ module Danger
145
189
  ])
146
190
 
147
191
  expect_any_instance_of(Swiftlint).to receive(:lint)
148
- .with(hash_including(path: File.expand_path('spec/fixtures/some_dir/SwiftFile.swift')), '')
192
+ .with(anything, '',
193
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
194
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/some_dir/SwiftFile.swift') })
149
195
  .once
150
196
  .and_return(@swiftlint_response)
151
197
 
@@ -179,7 +225,9 @@ module Danger
179
225
  ])
180
226
 
181
227
  expect_any_instance_of(Swiftlint).to receive(:lint)
182
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
228
+ .with(anything, '',
229
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
230
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift') })
183
231
  .once
184
232
  .and_return(@swiftlint_response)
185
233
 
@@ -195,7 +243,9 @@ module Danger
195
243
  ])
196
244
 
197
245
  expect_any_instance_of(Swiftlint).to receive(:lint)
198
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
246
+ .with(anything, '',
247
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
248
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift') })
199
249
  .once
200
250
  .and_return(@swiftlint_response)
201
251
 
@@ -203,6 +253,25 @@ module Danger
203
253
  @swiftlint.lint_files
204
254
  end
205
255
 
256
+ it 'lints multiple files in the included paths' do
257
+ allow(@swiftlint.git).to receive(:added_files).and_return([])
258
+ allow(@swiftlint.git).to receive(:modified_files).and_return([
259
+ 'spec/fixtures/SwiftFile.swift',
260
+ 'spec/fixtures/some_dir/SwiftFile.swift'
261
+ ])
262
+
263
+ expect_any_instance_of(Swiftlint).to receive(:lint)
264
+ .with(anything, '',
265
+ { 'SCRIPT_INPUT_FILE_COUNT' => '2',
266
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift'),
267
+ 'SCRIPT_INPUT_FILE_1' => a_string_ending_with('spec/fixtures/some_dir/SwiftFile.swift') })
268
+ .once
269
+ .and_return(@swiftlint_response)
270
+
271
+ @swiftlint.config_file = 'spec/fixtures/multi_include.yml'
272
+ @swiftlint.lint_files
273
+ end
274
+
206
275
  it 'does not crash when excluded is nil' do
207
276
  allow(@swiftlint.git).to receive(:added_files).and_return([])
208
277
  allow(@swiftlint.git).to receive(:modified_files).and_return([
@@ -210,7 +279,6 @@ module Danger
210
279
  ])
211
280
 
212
281
  expect_any_instance_of(Swiftlint).to receive(:lint)
213
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
214
282
  .once
215
283
  .and_return(@swiftlint_response)
216
284
 
@@ -225,7 +293,6 @@ module Danger
225
293
  ])
226
294
 
227
295
  expect_any_instance_of(Swiftlint).to receive(:lint)
228
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
229
296
  .once
230
297
  .and_return(@swiftlint_response)
231
298
 
@@ -240,7 +307,7 @@ module Danger
240
307
  ])
241
308
 
242
309
  expect_any_instance_of(Swiftlint).to receive(:lint)
243
- .with(hash_including(config: nil), '')
310
+ .with(hash_including(config: nil), '', anything)
244
311
  .once
245
312
  .and_return(@swiftlint_response)
246
313
 
@@ -258,7 +325,7 @@ module Danger
258
325
  expect(YAML).to receive(:safe_load).and_return({})
259
326
 
260
327
  expect_any_instance_of(Swiftlint).to receive(:lint)
261
- .with(hash_including(config: File.expand_path('.swiftlint.yml')), '')
328
+ .with(hash_including(config: File.expand_path('.swiftlint.yml')), '', anything)
262
329
  .once
263
330
  .and_return(@swiftlint_response)
264
331
 
@@ -272,7 +339,7 @@ module Danger
272
339
  ])
273
340
 
274
341
  expect_any_instance_of(Swiftlint).to receive(:lint)
275
- .with(hash_including(config: 'spec/fixtures/some_config.yml'), '')
342
+ .with(hash_including(config: 'spec/fixtures/some_config.yml'), '', anything)
276
343
  .once
277
344
  .and_return(@swiftlint_response)
278
345
 
@@ -295,7 +362,9 @@ module Danger
295
362
  ])
296
363
 
297
364
  expect_any_instance_of(Swiftlint).to receive(:lint)
298
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
365
+ .with(anything, '',
366
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
367
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift') })
299
368
  .once
300
369
  .and_return(@swiftlint_response)
301
370
 
@@ -304,7 +373,6 @@ module Danger
304
373
 
305
374
  it 'generates errors/warnings instead of markdown when use inline mode' do
306
375
  allow_any_instance_of(Swiftlint).to receive(:lint)
307
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
308
376
  .and_return(@swiftlint_response)
309
377
 
310
378
  @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: true, additional_swiftlint_args: '')
@@ -316,7 +384,6 @@ module Danger
316
384
 
317
385
  it 'renders rule_id and file:line indicators in inline mode' do
318
386
  allow_any_instance_of(Swiftlint).to receive(:lint)
319
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
320
387
  .and_return(@swiftlint_response)
321
388
 
322
389
  @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: true, additional_swiftlint_args: '')
@@ -327,7 +394,6 @@ module Danger
327
394
 
328
395
  it 'generate errors in inline_mode when fail_on_error' do
329
396
  allow_any_instance_of(Swiftlint).to receive(:lint)
330
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
331
397
  .and_return(@swiftlint_response)
332
398
 
333
399
  @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: true, fail_on_error: true, additional_swiftlint_args: '')
@@ -338,7 +404,6 @@ module Danger
338
404
 
339
405
  it 'generate only warnings in inline_mode when fail_on_error is false' do
340
406
  allow_any_instance_of(Swiftlint).to receive(:lint)
341
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
342
407
  .and_return(@swiftlint_response)
343
408
 
344
409
  @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: true, fail_on_error: false, additional_swiftlint_args: '')
@@ -395,7 +460,9 @@ module Danger
395
460
  violations_json[1][:file] = File.expand_path('spec/fixtures/SwiftFile.swift')
396
461
  swiftlint_violations_response= violations_json.to_json
397
462
  allow_any_instance_of(Swiftlint).to receive(:lint)
398
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
463
+ .with(anything, '',
464
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
465
+ 'SCRIPT_INPUT_FILE_0' => a_string_ending_with('spec/fixtures/SwiftFile.swift') })
399
466
  .and_return(swiftlint_violations_response)
400
467
 
401
468
  @swiftlint.filter_issues_in_diff = true
@@ -408,7 +475,6 @@ module Danger
408
475
  context '#strict' do
409
476
  before(:each) do
410
477
  allow_any_instance_of(Swiftlint).to receive(:lint)
411
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
412
478
  .and_return(swiftlint_response)
413
479
  end
414
480
 
@@ -472,7 +538,7 @@ module Danger
472
538
 
473
539
  it 'does not create comments' do
474
540
  allow_any_instance_of(Swiftlint).to receive(:lint)
475
- .with(hash_including(pwd: File.expand_path('.')), '')
541
+ .with(hash_including(pwd: File.expand_path('.')), '', anything)
476
542
  .and_return(@swiftlint_multiviolation_response)
477
543
 
478
544
  @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], inline_mode: true, no_comment: true)
@@ -484,7 +550,7 @@ module Danger
484
550
 
485
551
  it 'does not filter with max_violations' do
486
552
  allow_any_instance_of(Swiftlint).to receive(:lint)
487
- .with(hash_including(pwd: File.expand_path('.')), '')
553
+ .with(hash_including(pwd: File.expand_path('.')), '', anything)
488
554
  .and_return(@swiftlint_multiviolation_response)
489
555
 
490
556
  @swiftlint.max_num_violations = 1
@@ -495,7 +561,7 @@ module Danger
495
561
 
496
562
  it 'does not filter with select_block' do
497
563
  allow_any_instance_of(Swiftlint).to receive(:lint)
498
- .with(hash_including(pwd: File.expand_path('.')), '')
564
+ .with(hash_including(pwd: File.expand_path('.')), '', anything)
499
565
  .and_return(@swiftlint_multiviolation_response)
500
566
 
501
567
  @swiftlint.max_num_violations = 1
@@ -508,7 +574,7 @@ module Danger
508
574
 
509
575
  it 'correctly sets issues, warnings, and errors accessors' do
510
576
  allow_any_instance_of(Swiftlint).to receive(:lint)
511
- .with(hash_including(pwd: File.expand_path('.')), '')
577
+ .with(hash_including(pwd: File.expand_path('.')), '', anything)
512
578
  .and_return(@swiftlint_multiviolation_response)
513
579
 
514
580
  @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], no_comment: true)
@@ -531,7 +597,6 @@ module Danger
531
597
  ])
532
598
 
533
599
  expect_any_instance_of(Swiftlint).to receive(:lint)
534
- .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
535
600
  .once
536
601
  .and_return(@swiftlint_response)
537
602
 
@@ -557,7 +622,7 @@ module Danger
557
622
 
558
623
  it 'filters violations based on select block' do
559
624
  allow_any_instance_of(Swiftlint).to receive(:lint)
560
- .with(hash_including(pwd: File.expand_path('.')), '')
625
+ .with(hash_including(pwd: File.expand_path('.')), '', anything)
561
626
  .and_return(@swiftlint_multiviolation_response)
562
627
 
563
628
  @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], inline_mode: true) { |violation|
@@ -569,7 +634,7 @@ module Danger
569
634
 
570
635
  it 'filters nothing out if not passed a select block' do
571
636
  allow_any_instance_of(Swiftlint).to receive(:lint)
572
- .with(hash_including(pwd: File.expand_path('.')), '')
637
+ .with(hash_including(pwd: File.expand_path('.')), '', anything)
573
638
  .and_return(@swiftlint_multiviolation_response)
574
639
 
575
640
  @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], inline_mode: true)
@@ -40,4 +40,19 @@ describe Swiftlint do
40
40
  cache_path: '/path',
41
41
  enable_all_rules: true)
42
42
  end
43
+
44
+ it 'runs accepting options with env' do
45
+ cmd = 'swiftlint lint --no-use-stdin'
46
+ expect(swiftlint).to receive(:`).with(including(cmd))
47
+ expect(swiftlint).to receive(:update_env).with(
48
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
49
+ 'SCRIPT_INPUT_FILE_0' => 'File.swift' })
50
+ expect(swiftlint).to receive(:restore_env)
51
+
52
+ swiftlint.run('lint',
53
+ '',
54
+ { use_stdin: false },
55
+ { 'SCRIPT_INPUT_FILE_COUNT' => '1',
56
+ 'SCRIPT_INPUT_FILE_0' => 'File.swift' })
57
+ end
43
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-swiftlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash Furrow
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2019-07-12 00:00:00.000000000 Z
15
+ date: 2019-07-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: danger
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubyforge_project:
184
- rubygems_version: 2.6.13
184
+ rubygems_version: 2.7.10
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: A Danger plugin for linting Swift with SwiftLint.