danger-swiftlint 0.27.0 → 0.28.0

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
  SHA256:
3
- metadata.gz: 4a979dbfbd991937d41dad406c1dd157e2110af61cf3854cdf6cf16da24b4c01
4
- data.tar.gz: d1f7c58afd46ed7202b33e11f59e56f00c5f50e8ffc1a37254695c87bcda6b3a
3
+ metadata.gz: ed42295ae38914afa20f0e0cb218bab68041937b967bdeac37a44d68b020d062
4
+ data.tar.gz: 8d4df36e091935dc287809571ce41317ae155bfebff4ffe2d6432b9c6b637bc6
5
5
  SHA512:
6
- metadata.gz: 0753bc62476184adb833077774cf266e5c2fec07931edb4cb3b633ae960d3454200172fcf1cb9720ea6cecdde6df3d33faa726afba03e73122401a274dd57d1a
7
- data.tar.gz: 2e46137121434ea0ae42ec6c27b7f345e20ec65ae65494670b45764a70db87284d41e3a78f7b52942dd22a25fd2d9993623df729408a9b4381dec385f1e9b68e
6
+ metadata.gz: 29d8b6d7f3091dc5019148a2342575ab00ebc7160cab39c91205b26daeeba08c2d44015a87eb2a6758989e4b4520d2411b2bdbd0259211e36d1cebe08f0a71eb
7
+ data.tar.gz: 501f8cf1841ce33ae57dedbe1b3bc5c2723ecde16a7398893c67e3e0a3731da31aa54acea6f9491f42f9985c40ff19856465eaf93744e08447c4a57f27cee56c
data/lib/danger_plugin.rb CHANGED
@@ -210,11 +210,13 @@ module Danger
210
210
  # @return [Array] swift files
211
211
  def find_swift_files(dir_selected, files = nil, excluded_paths = [], included_paths = [])
212
212
  # Assign files to lint
213
- files = if files.nil?
214
- (git.modified_files - git.deleted_files) + git.added_files
215
- else
216
- Dir.glob(files)
217
- end
213
+ if files.nil?
214
+ renamed_files_hash = git.renamed_files.map { |rename| [rename[:before], rename[:after]] }.to_h
215
+ post_rename_modified_files = git.modified_files.map { |modified_file| renamed_files_hash[modified_file] || modified_file }
216
+ files = (post_rename_modified_files - git.deleted_files) + git.added_files
217
+ else
218
+ files = Dir.glob(files)
219
+ end
218
220
  # Filter files to lint
219
221
  excluded_paths_list = Find.find(*excluded_paths).to_a
220
222
  included_paths_list = Find.find(*included_paths).to_a
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DangerSwiftlint
4
- VERSION = '0.27.0'
4
+ VERSION = '0.28.0'
5
5
  SWIFTLINT_VERSION = '0.43.1'
6
6
  end
@@ -143,6 +143,7 @@ module Danger
143
143
  it 'uses git diff when files are not provided' do
144
144
  allow(@swiftlint.git).to receive(:modified_files).and_return(['spec/fixtures/SwiftFile.swift'])
145
145
  allow(@swiftlint.git).to receive(:added_files).and_return([])
146
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
146
147
  allow_any_instance_of(Swiftlint).to receive(:lint)
147
148
  .with(anything, '',
148
149
  { 'SCRIPT_INPUT_FILE_COUNT' => '1',
@@ -187,6 +188,7 @@ module Danger
187
188
  'spec/fixtures/some_dir/SwiftFile.swift',
188
189
  'spec/fixtures/SwiftFile.swift'
189
190
  ])
191
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
190
192
 
191
193
  expect_any_instance_of(Swiftlint).to receive(:lint)
192
194
  .with(anything, '',
@@ -212,10 +214,29 @@ module Danger
212
214
  # JSON object.
213
215
 
214
216
  allow_any_instance_of(Swiftlint).to receive(:lint).and_return('')
217
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
215
218
 
216
219
  expect { @swiftlint.lint_files }.not_to raise_error
217
220
  end
218
221
 
222
+ it 'crashes if renamed_files is not configured properly' do
223
+ allow(@swiftlint.git).to receive(:modified_files).and_return([
224
+ 'spec/fixtures/SwiftFileThatWasRenamedToSomethingElse.swift'
225
+ ])
226
+ expect { @swiftlint.lint_files }.to raise_error(NoMethodError)
227
+ end
228
+
229
+ it 'does not crash if a modified file was renamed' do
230
+ allow(@swiftlint.git).to receive(:modified_files).and_return([
231
+ 'spec/fixtures/SwiftFileThatWasRenamedToSomethingElse.swift'
232
+ ])
233
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([
234
+ { before: 'spec/fixtures/SwiftFileThatWasRenamedToSomethingElse.swift',
235
+ after: 'spec/fixtures/SwiftFile.swift' }
236
+ ])
237
+ expect { @swiftlint.lint_files }.not_to raise_error
238
+ end
239
+
219
240
  it 'does not lint files in the excluded paths' do
220
241
  allow(@swiftlint.git).to receive(:added_files).and_return([])
221
242
  allow(@swiftlint.git).to receive(:modified_files).and_return([
@@ -223,7 +244,7 @@ module Danger
223
244
  'spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift',
224
245
  'spec/fixtures/excluded_dir/SwiftFile WithEscaped+CharactersThatShouldNotBeIncluded.swift'
225
246
  ])
226
-
247
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
227
248
  expect_any_instance_of(Swiftlint).to receive(:lint)
228
249
  .with(anything, '',
229
250
  { 'SCRIPT_INPUT_FILE_COUNT' => '1',
@@ -241,6 +262,7 @@ module Danger
241
262
  'spec/fixtures/SwiftFile.swift',
242
263
  'spec/fixtures/some_dir/SwiftFile.swift'
243
264
  ])
265
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
244
266
 
245
267
  expect_any_instance_of(Swiftlint).to receive(:lint)
246
268
  .with(anything, '',
@@ -259,6 +281,7 @@ module Danger
259
281
  'spec/fixtures/SwiftFile.swift',
260
282
  'spec/fixtures/some_dir/SwiftFile.swift'
261
283
  ])
284
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
262
285
 
263
286
  expect_any_instance_of(Swiftlint).to receive(:lint)
264
287
  .with(anything, '',
@@ -277,6 +300,7 @@ module Danger
277
300
  allow(@swiftlint.git).to receive(:modified_files).and_return([
278
301
  'spec/fixtures/SwiftFile.swift'
279
302
  ])
303
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
280
304
 
281
305
  expect_any_instance_of(Swiftlint).to receive(:lint)
282
306
  .once
@@ -291,6 +315,7 @@ module Danger
291
315
  allow(@swiftlint.git).to receive(:modified_files).and_return([
292
316
  'spec/fixtures/SwiftFile.swift'
293
317
  ])
318
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
294
319
 
295
320
  expect_any_instance_of(Swiftlint).to receive(:lint)
296
321
  .once
@@ -305,6 +330,7 @@ module Danger
305
330
  allow(@swiftlint.git).to receive(:modified_files).and_return([
306
331
  'spec/fixtures/SwiftFile.swift'
307
332
  ])
333
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
308
334
 
309
335
  expect_any_instance_of(Swiftlint).to receive(:lint)
310
336
  .with(hash_including(config: nil), '', anything)
@@ -319,6 +345,7 @@ module Danger
319
345
  allow(@swiftlint.git).to receive(:modified_files).and_return([
320
346
  'spec/fixtures/SwiftFile.swift'
321
347
  ])
348
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
322
349
 
323
350
  expect_any_instance_of(Swiftlint).to receive(:lint)
324
351
  .with(hash_including(config: 'spec/fixtures/some_config.yml'), '', anything)
@@ -342,6 +369,7 @@ module Danger
342
369
  allow(@swiftlint.git).to receive(:deleted_files).and_return([
343
370
  'spec/fixtures/DeletedFile.swift'
344
371
  ])
372
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
345
373
 
346
374
  expect_any_instance_of(Swiftlint).to receive(:lint)
347
375
  .with(anything, '',
@@ -578,6 +606,7 @@ module Danger
578
606
  'spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift',
579
607
  'spec/fixtures/excluded_dir/SwiftFile WithEscaped+CharactersThatShouldNotBeIncluded.swift'
580
608
  ])
609
+ allow(@swiftlint.git).to receive(:renamed_files).and_return([])
581
610
 
582
611
  expect_any_instance_of(Swiftlint).to receive(:lint)
583
612
  .once
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.27.0
4
+ version: 0.28.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: 2021-08-23 00:00:00.000000000 Z
15
+ date: 2021-09-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: danger