danger-swiftlint 0.24.2 → 0.26.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 +11 -12
- data/lib/version.rb +2 -2
- data/spec/danger_plugin_spec.rb +2 -19
- data/spec/swiftlint_spec.rb +15 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a7648f0b4b4bf523d4617687df847500fcdc2f846425dfadffb7f8c768319d8
|
4
|
+
data.tar.gz: 26b3d3507b659380c23b46828be7874faf949016fd54d1366436de8ce348b518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f912b6332e39539cc16f6a09b9d7e31875409a3357db1d6e2e6160a807138bceb743a7e6580539844e45595dbd3e9932ccda66bb0bfaa5c10a2740d7997021d
|
7
|
+
data.tar.gz: 84801ec026c062c9e9f30d3bca88759cde4c73a4e70b72b0fb8f112f567585ce5468ec695c5b858919d642998047cc8b1fce8419bce8e617705fb399132595f3
|
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
|
|
@@ -354,8 +354,7 @@ module Danger
|
|
354
354
|
def git_modified_lines(file)
|
355
355
|
git_range_info_line_regex = /^@@ .+\+(?<line_number>\d+),/
|
356
356
|
git_modified_line_regex = /^\+(?!\+|\+)/
|
357
|
-
git_removed_line_regex =
|
358
|
-
git_not_removed_line_regex = /^[^-]/
|
357
|
+
git_removed_line_regex = /^\-(?!\-|\-)/
|
359
358
|
file_info = git.diff_for_file(file)
|
360
359
|
line_number = 0
|
361
360
|
lines = []
|
@@ -367,7 +366,7 @@ module Danger
|
|
367
366
|
when git_modified_line_regex
|
368
367
|
lines << line_number
|
369
368
|
end
|
370
|
-
line_number += 1 if line_number > 0
|
369
|
+
line_number += 1 if line_number > 0 && !git_removed_line_regex.match?(line)
|
371
370
|
line_number = starting_line_number if line_number == 0 && starting_line_number > 0
|
372
371
|
end
|
373
372
|
lines
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -314,24 +314,6 @@ module Danger
|
|
314
314
|
@swiftlint.lint_files
|
315
315
|
end
|
316
316
|
|
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
317
|
it 'expands specified config file to absolute path' do
|
336
318
|
allow(@swiftlint.git).to receive(:added_files).and_return([])
|
337
319
|
allow(@swiftlint.git).to receive(:modified_files).and_return([
|
@@ -419,7 +401,8 @@ module Danger
|
|
419
401
|
allow(@swiftlint.git.diff_for_file).to receive(:patch).and_return(git_diff)
|
420
402
|
modified_lines = @swiftlint.git_modified_lines("spec/fixtures/SwiftFile.swift")
|
421
403
|
expect(modified_lines).to_not be_empty
|
422
|
-
expect(modified_lines.length).to eql(
|
404
|
+
expect(modified_lines.length).to eql(24)
|
405
|
+
expect(modified_lines).to eql([15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 42])
|
423
406
|
end
|
424
407
|
|
425
408
|
it 'Get git modified files info' do
|
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.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ash Furrow
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
- Orta Therox
|
10
10
|
- Thiago Felix
|
11
11
|
- Giovanni Lodi
|
12
|
-
autorequire:
|
12
|
+
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: danger
|
@@ -165,7 +165,7 @@ homepage: https://github.com/ashfurrow/danger-ruby-swiftlint
|
|
165
165
|
licenses:
|
166
166
|
- MIT
|
167
167
|
metadata: {}
|
168
|
-
post_install_message:
|
168
|
+
post_install_message:
|
169
169
|
rdoc_options: []
|
170
170
|
require_paths:
|
171
171
|
- lib
|
@@ -180,8 +180,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
|
-
rubygems_version: 3.0.
|
184
|
-
signing_key:
|
183
|
+
rubygems_version: 3.0.2
|
184
|
+
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: A Danger plugin for linting Swift with SwiftLint.
|
187
187
|
test_files:
|