danger-swiftlint 0.24.5 → 0.28.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 +4 -4
- data/ext/swiftlint/swiftlint.rb +10 -3
- data/lib/danger_plugin.rb +16 -14
- data/lib/version.rb +2 -2
- data/spec/danger_plugin_spec.rb +30 -19
- data/spec/swiftlint_spec.rb +15 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed42295ae38914afa20f0e0cb218bab68041937b967bdeac37a44d68b020d062
|
4
|
+
data.tar.gz: 8d4df36e091935dc287809571ce41317ae155bfebff4ffe2d6432b9c6b637bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d8b6d7f3091dc5019148a2342575ab00ebc7160cab39c91205b26daeeba08c2d44015a87eb2a6758989e4b4520d2411b2bdbd0259211e36d1cebe08f0a71eb
|
7
|
+
data.tar.gz: 501f8cf1841ce33ae57dedbe1b3bc5c2723ecde16a7398893c67e3e0a3731da31aa54acea6f9491f42f9985c40ff19856465eaf93744e08447c4a57f27cee56c
|
data/ext/swiftlint/swiftlint.rb
CHANGED
@@ -8,14 +8,21 @@ class Swiftlint
|
|
8
8
|
|
9
9
|
# Runs swiftlint
|
10
10
|
def run(cmd = 'lint', additional_swiftlint_args = '', options = {}, env = nil)
|
11
|
-
# change pwd before
|
12
|
-
|
11
|
+
# allow for temporary change to pwd before running swiftlint
|
12
|
+
pwd = options.delete(:pwd)
|
13
|
+
command = "#{swiftlint_path} #{cmd} #{swiftlint_arguments(options, additional_swiftlint_args)}"
|
13
14
|
|
14
15
|
# Add `env` to environment
|
15
16
|
update_env(env)
|
16
17
|
begin
|
17
18
|
# run swiftlint with provided options
|
18
|
-
|
19
|
+
if pwd
|
20
|
+
Dir.chdir(pwd) do
|
21
|
+
`#{command}`
|
22
|
+
end
|
23
|
+
else
|
24
|
+
`#{command}`
|
25
|
+
end
|
19
26
|
ensure
|
20
27
|
# Remove any ENV variables we might have added
|
21
28
|
restore_env()
|
data/lib/danger_plugin.rb
CHANGED
@@ -46,7 +46,7 @@ module Danger
|
|
46
46
|
|
47
47
|
# Errors found
|
48
48
|
attr_accessor :errors
|
49
|
-
|
49
|
+
|
50
50
|
# All issues found
|
51
51
|
attr_accessor :issues
|
52
52
|
|
@@ -67,12 +67,12 @@ module Danger
|
|
67
67
|
# Fails if swiftlint isn't installed
|
68
68
|
raise 'swiftlint is not installed' unless swiftlint.installed?
|
69
69
|
|
70
|
-
config_file_path =
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
config_file_path = config_file
|
71
|
+
if config_file_path
|
72
|
+
log "Using config file: #{config_file_path}"
|
73
|
+
else
|
74
|
+
log 'Config file was not specified.'
|
75
|
+
end
|
76
76
|
|
77
77
|
dir_selected = directory ? File.expand_path(directory) : Dir.pwd
|
78
78
|
log "Swiftlint will be run from #{dir_selected}"
|
@@ -124,7 +124,7 @@ module Danger
|
|
124
124
|
issues = issues.take(@max_num_violations)
|
125
125
|
end
|
126
126
|
log "Received from Swiftlint: #{issues}"
|
127
|
-
|
127
|
+
|
128
128
|
# filter out any unwanted violations with the passed in select_block
|
129
129
|
if select_block && !no_comment
|
130
130
|
issues = issues.select { |issue| select_block.call(issue) }
|
@@ -133,7 +133,7 @@ module Danger
|
|
133
133
|
# Filter warnings and errors
|
134
134
|
@warnings = issues.select { |issue| issue['severity'] == 'Warning' }
|
135
135
|
@errors = issues.select { |issue| issue['severity'] == 'Error' }
|
136
|
-
|
136
|
+
|
137
137
|
# Early exit so we don't comment
|
138
138
|
return if no_comment
|
139
139
|
|
@@ -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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
data/spec/danger_plugin_spec.rb
CHANGED
@@ -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)
|
@@ -314,29 +340,12 @@ module Danger
|
|
314
340
|
@swiftlint.lint_files
|
315
341
|
end
|
316
342
|
|
317
|
-
it 'expands default config file (if present) to absolute path' do
|
318
|
-
allow(@swiftlint.git).to receive(:added_files).and_return([])
|
319
|
-
allow(@swiftlint.git).to receive(:modified_files).and_return([
|
320
|
-
'spec/fixtures/SwiftFile.swift'
|
321
|
-
])
|
322
|
-
expect(File).to receive(:file?).and_return(true)
|
323
|
-
expect(File).to receive(:exist?).and_return(true)
|
324
|
-
expect(File).to receive(:open).and_return(StringIO.new)
|
325
|
-
expect(YAML).to receive(:safe_load).and_return({})
|
326
|
-
|
327
|
-
expect_any_instance_of(Swiftlint).to receive(:lint)
|
328
|
-
.with(hash_including(config: File.expand_path('.swiftlint.yml')), '', anything)
|
329
|
-
.once
|
330
|
-
.and_return(@swiftlint_response)
|
331
|
-
|
332
|
-
@swiftlint.lint_files
|
333
|
-
end
|
334
|
-
|
335
343
|
it 'expands specified config file to absolute path' do
|
336
344
|
allow(@swiftlint.git).to receive(:added_files).and_return([])
|
337
345
|
allow(@swiftlint.git).to receive(:modified_files).and_return([
|
338
346
|
'spec/fixtures/SwiftFile.swift'
|
339
347
|
])
|
348
|
+
allow(@swiftlint.git).to receive(:renamed_files).and_return([])
|
340
349
|
|
341
350
|
expect_any_instance_of(Swiftlint).to receive(:lint)
|
342
351
|
.with(hash_including(config: 'spec/fixtures/some_config.yml'), '', anything)
|
@@ -360,6 +369,7 @@ module Danger
|
|
360
369
|
allow(@swiftlint.git).to receive(:deleted_files).and_return([
|
361
370
|
'spec/fixtures/DeletedFile.swift'
|
362
371
|
])
|
372
|
+
allow(@swiftlint.git).to receive(:renamed_files).and_return([])
|
363
373
|
|
364
374
|
expect_any_instance_of(Swiftlint).to receive(:lint)
|
365
375
|
.with(anything, '',
|
@@ -596,6 +606,7 @@ module Danger
|
|
596
606
|
'spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift',
|
597
607
|
'spec/fixtures/excluded_dir/SwiftFile WithEscaped+CharactersThatShouldNotBeIncluded.swift'
|
598
608
|
])
|
609
|
+
allow(@swiftlint.git).to receive(:renamed_files).and_return([])
|
599
610
|
|
600
611
|
expect_any_instance_of(Swiftlint).to receive(:lint)
|
601
612
|
.once
|
data/spec/swiftlint_spec.rb
CHANGED
@@ -25,9 +25,23 @@ describe Swiftlint do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
it 'changes directory when a pwd option is specified' do
|
29
|
+
expect(Dir).to receive(:chdir) do |*args, &block|
|
30
|
+
expect(args).to match_array([Dir.pwd])
|
31
|
+
expect(block).not_to be_nil
|
32
|
+
end
|
33
|
+
swiftlint.run('lint', '', pwd: Dir.pwd)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does not change directory when no pwd option is specified' do
|
37
|
+
allow(swiftlint).to receive(:`)
|
38
|
+
expect(Dir).not_to receive(:chdir)
|
39
|
+
swiftlint.run('lint', '')
|
40
|
+
end
|
41
|
+
|
28
42
|
it 'runs lint by default with options being optional' do
|
29
43
|
expect(swiftlint).to receive(:`).with(including('swiftlint lint'))
|
30
|
-
swiftlint.run
|
44
|
+
swiftlint.run('lint', '')
|
31
45
|
end
|
32
46
|
|
33
47
|
it 'runs accepting symbolized options' do
|
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.
|
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:
|
15
|
+
date: 2021-09-07 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: danger
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.2.20
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: A Danger plugin for linting Swift with SwiftLint.
|