danger-swiftformat 0.7.0 → 0.8.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/.github/workflows/ruby.yml +26 -0
- data/.rubocop.yml +2 -1
- data/Gemfile.lock +51 -47
- data/README.md +13 -1
- data/lib/swiftformat/gem_version.rb +1 -1
- data/lib/swiftformat/plugin.rb +8 -3
- data/lib/swiftformat/swiftformat.rb +11 -5
- data/spec/fixtures/0_GoodFile.swift +8 -0
- data/spec/fixtures/1_BadFile.swift +7 -0
- data/spec/fixtures/2_GoodFile.swift +8 -0
- data/spec/fixtures/swiftformat_output.txt +3 -10
- data/spec/fixtures/swiftformat_output_with_errors.txt +7 -10
- data/spec/spec_helper.rb +2 -2
- data/spec/swiftformat/plugin_spec.rb +30 -6
- data/spec/swiftformat/swiftformat_spec.rb +15 -16
- metadata +13 -7
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 988d028ab6f8530bdbd0aac2e2db2b0cc7f1ec0176bf6ed4e91551acf10550fd
|
|
4
|
+
data.tar.gz: d1f276c732588da77f9028f723a4420b873e6ec1354afac91e6422ea55b757f6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e49d217585203fb321a0b25501ed39e6f7a891101d7ed625abfbc833a9a093599880cde86a680530f6e2a1807962dadb2fa2fdbb18304faf3b6d1342f745ca33
|
|
7
|
+
data.tar.gz: d3d444466a38ecef5b339e2e04e1a22ffce3015d3629ea5df375165f7c8aa34d39364246361303b348c766221f06659db8fc5087ea00a154e3838c9244b68b66
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
ruby-version: ['2.6', '2.7']
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v2
|
|
19
|
+
- name: Set up Ruby
|
|
20
|
+
uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
23
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
24
|
+
|
|
25
|
+
- name: Run tests
|
|
26
|
+
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
danger-swiftformat (0.
|
|
4
|
+
danger-swiftformat (0.8.0)
|
|
5
5
|
danger-plugin-api (~> 1.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -9,41 +9,41 @@ GEM
|
|
|
9
9
|
specs:
|
|
10
10
|
addressable (2.7.0)
|
|
11
11
|
public_suffix (>= 2.0.2, < 5.0)
|
|
12
|
-
ast (2.4.
|
|
12
|
+
ast (2.4.2)
|
|
13
13
|
claide (1.0.3)
|
|
14
14
|
claide-plugins (0.9.2)
|
|
15
15
|
cork
|
|
16
16
|
nap
|
|
17
17
|
open4 (~> 1.3)
|
|
18
|
-
coderay (1.1.
|
|
18
|
+
coderay (1.1.3)
|
|
19
19
|
colored2 (3.1.2)
|
|
20
20
|
cork (0.3.0)
|
|
21
21
|
colored2 (~> 3.1)
|
|
22
|
-
danger (
|
|
22
|
+
danger (8.2.2)
|
|
23
23
|
claide (~> 1.0)
|
|
24
24
|
claide-plugins (>= 0.9.2)
|
|
25
25
|
colored2 (~> 3.1)
|
|
26
26
|
cork (~> 0.1)
|
|
27
|
-
faraday (
|
|
27
|
+
faraday (>= 0.9.0, < 2.0)
|
|
28
28
|
faraday-http-cache (~> 2.0)
|
|
29
|
-
git (~> 1.
|
|
30
|
-
kramdown (~> 2.
|
|
29
|
+
git (~> 1.7)
|
|
30
|
+
kramdown (~> 2.3)
|
|
31
31
|
kramdown-parser-gfm (~> 1.0)
|
|
32
32
|
no_proxy_fix
|
|
33
33
|
octokit (~> 4.7)
|
|
34
34
|
terminal-table (~> 1)
|
|
35
35
|
danger-plugin-api (1.0.0)
|
|
36
36
|
danger (> 2.0)
|
|
37
|
-
diff-lcs (1.
|
|
37
|
+
diff-lcs (1.4.4)
|
|
38
38
|
faraday (0.15.4)
|
|
39
39
|
multipart-post (>= 1.2, < 3)
|
|
40
|
-
faraday-http-cache (2.
|
|
41
|
-
faraday (
|
|
42
|
-
ffi (1.
|
|
40
|
+
faraday-http-cache (2.2.0)
|
|
41
|
+
faraday (>= 0.8)
|
|
42
|
+
ffi (1.14.2)
|
|
43
43
|
formatador (0.2.5)
|
|
44
|
-
git (1.
|
|
44
|
+
git (1.8.1)
|
|
45
45
|
rchardet (~> 1.8)
|
|
46
|
-
guard (2.16.
|
|
46
|
+
guard (2.16.2)
|
|
47
47
|
formatador (>= 0.2.4)
|
|
48
48
|
listen (>= 2.7, < 4.0)
|
|
49
49
|
lumberjack (>= 1.0.12, < 2.0)
|
|
@@ -57,15 +57,15 @@ GEM
|
|
|
57
57
|
guard (~> 2.1)
|
|
58
58
|
guard-compat (~> 1.1)
|
|
59
59
|
rspec (>= 2.99.0, < 4.0)
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
kramdown (2.3.0)
|
|
61
|
+
rexml
|
|
62
62
|
kramdown-parser-gfm (1.1.0)
|
|
63
63
|
kramdown (~> 2.0)
|
|
64
|
-
listen (3.
|
|
64
|
+
listen (3.4.1)
|
|
65
65
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
66
66
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
67
|
-
lumberjack (1.2.
|
|
68
|
-
method_source (0.
|
|
67
|
+
lumberjack (1.2.8)
|
|
68
|
+
method_source (1.0.0)
|
|
69
69
|
multipart-post (2.1.1)
|
|
70
70
|
nap (1.1.0)
|
|
71
71
|
nenv (0.3.0)
|
|
@@ -73,55 +73,59 @@ GEM
|
|
|
73
73
|
notiffany (0.1.3)
|
|
74
74
|
nenv (~> 0.1)
|
|
75
75
|
shellany (~> 0.0)
|
|
76
|
-
octokit (4.
|
|
76
|
+
octokit (4.20.0)
|
|
77
77
|
faraday (>= 0.9)
|
|
78
78
|
sawyer (~> 0.8.0, >= 0.5.3)
|
|
79
79
|
open4 (1.3.4)
|
|
80
|
-
parallel (1.
|
|
81
|
-
parser (
|
|
82
|
-
ast (~> 2.4.
|
|
83
|
-
pry (0.
|
|
84
|
-
coderay (~> 1.1
|
|
85
|
-
method_source (~>
|
|
86
|
-
public_suffix (4.0.
|
|
80
|
+
parallel (1.20.1)
|
|
81
|
+
parser (3.0.0.0)
|
|
82
|
+
ast (~> 2.4.1)
|
|
83
|
+
pry (0.13.1)
|
|
84
|
+
coderay (~> 1.1)
|
|
85
|
+
method_source (~> 1.0)
|
|
86
|
+
public_suffix (4.0.6)
|
|
87
87
|
rainbow (3.0.0)
|
|
88
88
|
rake (12.3.3)
|
|
89
|
-
rb-fsevent (0.10.
|
|
89
|
+
rb-fsevent (0.10.4)
|
|
90
90
|
rb-inotify (0.10.1)
|
|
91
91
|
ffi (~> 1.0)
|
|
92
92
|
rchardet (1.8.0)
|
|
93
|
+
regexp_parser (2.0.3)
|
|
93
94
|
rexml (3.2.4)
|
|
94
|
-
rspec (3.
|
|
95
|
-
rspec-core (~> 3.
|
|
96
|
-
rspec-expectations (~> 3.
|
|
97
|
-
rspec-mocks (~> 3.
|
|
98
|
-
rspec-core (3.
|
|
99
|
-
rspec-support (~> 3.
|
|
100
|
-
rspec-expectations (3.
|
|
95
|
+
rspec (3.10.0)
|
|
96
|
+
rspec-core (~> 3.10.0)
|
|
97
|
+
rspec-expectations (~> 3.10.0)
|
|
98
|
+
rspec-mocks (~> 3.10.0)
|
|
99
|
+
rspec-core (3.10.1)
|
|
100
|
+
rspec-support (~> 3.10.0)
|
|
101
|
+
rspec-expectations (3.10.1)
|
|
101
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
102
|
-
rspec-support (~> 3.
|
|
103
|
-
rspec-mocks (3.
|
|
103
|
+
rspec-support (~> 3.10.0)
|
|
104
|
+
rspec-mocks (3.10.1)
|
|
104
105
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
105
|
-
rspec-support (~> 3.
|
|
106
|
-
rspec-support (3.
|
|
107
|
-
rubocop (0.
|
|
108
|
-
jaro_winkler (~> 1.5.1)
|
|
106
|
+
rspec-support (~> 3.10.0)
|
|
107
|
+
rspec-support (3.10.1)
|
|
108
|
+
rubocop (0.93.1)
|
|
109
109
|
parallel (~> 1.10)
|
|
110
|
-
parser (>= 2.7.
|
|
110
|
+
parser (>= 2.7.1.5)
|
|
111
111
|
rainbow (>= 2.2.2, < 4.0)
|
|
112
|
+
regexp_parser (>= 1.8)
|
|
112
113
|
rexml
|
|
114
|
+
rubocop-ast (>= 0.6.0)
|
|
113
115
|
ruby-progressbar (~> 1.7)
|
|
114
|
-
unicode-display_width (>= 1.4.0, <
|
|
115
|
-
|
|
116
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
117
|
+
rubocop-ast (1.4.0)
|
|
118
|
+
parser (>= 2.7.1.5)
|
|
119
|
+
ruby-progressbar (1.11.0)
|
|
116
120
|
sawyer (0.8.2)
|
|
117
121
|
addressable (>= 2.3.5)
|
|
118
122
|
faraday (> 0.8, < 2.0)
|
|
119
123
|
shellany (0.0.1)
|
|
120
124
|
terminal-table (1.8.0)
|
|
121
125
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
122
|
-
thor (1.0
|
|
123
|
-
unicode-display_width (1.
|
|
124
|
-
yard (0.9.
|
|
126
|
+
thor (1.1.0)
|
|
127
|
+
unicode-display_width (1.7.0)
|
|
128
|
+
yard (0.9.26)
|
|
125
129
|
|
|
126
130
|
PLATFORMS
|
|
127
131
|
ruby
|
|
@@ -140,4 +144,4 @@ DEPENDENCIES
|
|
|
140
144
|
yard (~> 0.9)
|
|
141
145
|
|
|
142
146
|
BUNDLED WITH
|
|
143
|
-
2.
|
|
147
|
+
2.2.6
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# danger-swiftformat [](https://rubygems.org/gems/danger-swiftformat)
|
|
2
2
|
|
|
3
3
|
A [Danger] plugin to check Swift formatting using [SwiftFormat].
|
|
4
4
|
|
|
@@ -38,12 +38,24 @@ You can specify the `swiftformat` binary using the `binary_path` parameter:
|
|
|
38
38
|
swiftformat.binary_path = "/path/to/swiftformat"
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
You can specify the Swift version of your project using the `swiftversion` parametter:
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
swiftformat.swiftversion = "5"
|
|
45
|
+
```
|
|
46
|
+
|
|
41
47
|
You can specify additional `swiftformat` arguments using the `additional_args` parameter:
|
|
42
48
|
|
|
43
49
|
```ruby
|
|
44
50
|
swiftformat.additional_args = "--indent tab --self insert"
|
|
45
51
|
```
|
|
46
52
|
|
|
53
|
+
You can specify additional message (e.g. how to fix format issue) for danger comment using the `additional_message` parameter:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
swiftformat.additional_message = "your additional message for contributor"
|
|
57
|
+
```
|
|
58
|
+
|
|
47
59
|
By default, `danger-swiftformat` will run on any modified or created file ending in `.swift`. If you'd like to exclude
|
|
48
60
|
certain directories or files such as `Pods`, you can use the `exclude` parameter:
|
|
49
61
|
|
data/lib/swiftformat/plugin.rb
CHANGED
|
@@ -26,9 +26,14 @@ module Danger
|
|
|
26
26
|
|
|
27
27
|
# An array of file and directory paths to exclude
|
|
28
28
|
#
|
|
29
|
-
# @return [Array<String]
|
|
29
|
+
# @return [Array<String>]
|
|
30
30
|
attr_accessor :exclude
|
|
31
31
|
|
|
32
|
+
# The project Swift version
|
|
33
|
+
#
|
|
34
|
+
# @return [String]
|
|
35
|
+
attr_accessor :swiftversion
|
|
36
|
+
|
|
32
37
|
# Runs swiftformat
|
|
33
38
|
#
|
|
34
39
|
# @param [Boolean] fail_on_error
|
|
@@ -46,7 +51,7 @@ module Danger
|
|
|
46
51
|
return if swift_files.empty?
|
|
47
52
|
|
|
48
53
|
# Run swiftformat
|
|
49
|
-
results = swiftformat.check_format(swift_files, additional_args)
|
|
54
|
+
results = swiftformat.check_format(swift_files, additional_args, swiftversion)
|
|
50
55
|
|
|
51
56
|
# Stop processing if the errors array is empty
|
|
52
57
|
return if results[:errors].empty?
|
|
@@ -56,7 +61,7 @@ module Danger
|
|
|
56
61
|
message << "| File | Rules |\n"
|
|
57
62
|
message << "| ---- | ----- |\n"
|
|
58
63
|
results[:errors].each do |error|
|
|
59
|
-
message << "| #{error[:file].gsub(Dir.pwd
|
|
64
|
+
message << "| #{error[:file].gsub("#{Dir.pwd}/", '')} | #{error[:rules].join(', ')} |\n"
|
|
60
65
|
end
|
|
61
66
|
|
|
62
67
|
unless additional_message.nil?
|
|
@@ -10,10 +10,16 @@ module Danger
|
|
|
10
10
|
Cmd.run([@path, "--version"])
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def check_format(files, additional_args = "")
|
|
13
|
+
def check_format(files, additional_args = "", swiftversion = "")
|
|
14
14
|
cmd = [@path] + files
|
|
15
15
|
cmd << additional_args.split unless additional_args.nil? || additional_args.empty?
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
unless swiftversion.empty?
|
|
18
|
+
cmd << "--swiftversion"
|
|
19
|
+
cmd << swiftversion
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
cmd << %w(--lint --lenient)
|
|
17
23
|
stdout, stderr, status = Cmd.run(cmd.flatten)
|
|
18
24
|
|
|
19
25
|
output = stdout.empty? ? stderr : stdout
|
|
@@ -41,7 +47,7 @@ module Danger
|
|
|
41
47
|
}
|
|
42
48
|
end
|
|
43
49
|
|
|
44
|
-
ERRORS_REGEX = /
|
|
50
|
+
ERRORS_REGEX = /(.*:\d+:\d+): ((warning|error):.*)$/.freeze
|
|
45
51
|
|
|
46
52
|
def errors(output)
|
|
47
53
|
errors = []
|
|
@@ -49,7 +55,7 @@ module Danger
|
|
|
49
55
|
next if match.count < 2
|
|
50
56
|
|
|
51
57
|
errors << {
|
|
52
|
-
file: match[0],
|
|
58
|
+
file: match[0].sub("#{Dir.pwd}/", ""),
|
|
53
59
|
rules: match[1].split(",").map(&:strip)
|
|
54
60
|
}
|
|
55
61
|
end
|
|
@@ -62,7 +68,7 @@ module Danger
|
|
|
62
68
|
if RUNTIME_REGEX.match(output)
|
|
63
69
|
RUNTIME_REGEX.match(output)[1]
|
|
64
70
|
else
|
|
65
|
-
logger = Logger.new(
|
|
71
|
+
logger = Logger.new($stderr)
|
|
66
72
|
logger.error("Invalid run_time output: #{output}")
|
|
67
73
|
"-1"
|
|
68
74
|
end
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
Running SwiftFormat...
|
|
2
|
-
(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Formatting /Users/garriguv/FileWithErrors.swift
|
|
6
|
-
-- no changes
|
|
7
|
-
Formatting /Users/garriguv/OtherFile.swift
|
|
8
|
-
-- no changes
|
|
9
|
-
|
|
10
|
-
SwiftFormat completed in 0.08s.
|
|
11
|
-
0/3 files would have been formatted.
|
|
2
|
+
(lint mode - no files will be changed.)
|
|
3
|
+
SwiftFormat completed in 0.01s.
|
|
4
|
+
0/2 files require formatting.
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
Running SwiftFormat...
|
|
2
|
-
(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
SwiftFormat completed in 0.08s.
|
|
11
|
-
1/3 files would have been formatted.
|
|
2
|
+
(lint mode - no files will be changed.)
|
|
3
|
+
spec/fixtures/1_BadFile.swift:3:1: warning: (spaceAroundOperators) Add or remove space around operators or delimiters.
|
|
4
|
+
spec/fixtures/1_BadFile.swift:4:1: warning: (spaceInsideParens) Remove space inside parentheses.
|
|
5
|
+
spec/fixtures/1_BadFile.swift:5:1: warning: (indent) Indent code in accordance with the scope level.
|
|
6
|
+
SwiftFormat completed in 0.02s.
|
|
7
|
+
Source input did not pass lint check.
|
|
8
|
+
1/3 files require formatting.
|
data/spec/spec_helper.rb
CHANGED
|
@@ -42,7 +42,7 @@ module Danger
|
|
|
42
42
|
allow(@sut.git).to receive(:renamed_files).and_return([{}])
|
|
43
43
|
allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
|
|
44
44
|
allow_any_instance_of(SwiftFormat).to receive(:check_format)
|
|
45
|
-
.with(%w(Added.swift Modified.swift), additional_args)
|
|
45
|
+
.with(%w(Added.swift Modified.swift), additional_args, nil)
|
|
46
46
|
.and_return(success_output)
|
|
47
47
|
|
|
48
48
|
@sut.additional_args = additional_args
|
|
@@ -55,6 +55,30 @@ module Danger
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
context "with swiftversion" do
|
|
59
|
+
let(:swiftversion) { "5" }
|
|
60
|
+
let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } }
|
|
61
|
+
|
|
62
|
+
it "should pass the additional flag to swiftformat" do
|
|
63
|
+
allow(@sut.git).to receive(:added_files).and_return(["Added.swift"])
|
|
64
|
+
allow(@sut.git).to receive(:modified_files).and_return(["Modified.swift"])
|
|
65
|
+
allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
|
|
66
|
+
allow(@sut.git).to receive(:renamed_files).and_return([{}])
|
|
67
|
+
allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
|
|
68
|
+
allow_any_instance_of(SwiftFormat).to receive(:check_format)
|
|
69
|
+
.with(%w(Added.swift Modified.swift), nil, swiftversion)
|
|
70
|
+
.and_return(success_output)
|
|
71
|
+
|
|
72
|
+
@sut.swiftversion = swiftversion
|
|
73
|
+
|
|
74
|
+
@sut.check_format(fail_on_error: true)
|
|
75
|
+
|
|
76
|
+
status = @sut.status_report
|
|
77
|
+
expect(status[:errors]).to be_empty
|
|
78
|
+
expect(status[:markdowns]).to be_empty
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
58
82
|
context "with additional_message" do
|
|
59
83
|
let(:additional_message) { "I'm the additional message." }
|
|
60
84
|
let(:error_output) { { errors: [{ file: "Modified.swift", rules: %w(firstRule secondRule) }], stats: { run_time: "0.16s" } } }
|
|
@@ -65,7 +89,7 @@ module Danger
|
|
|
65
89
|
allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
|
|
66
90
|
allow(@sut.git).to receive(:renamed_files).and_return([{}])
|
|
67
91
|
allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
|
|
68
|
-
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil).and_return(error_output)
|
|
92
|
+
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil, nil).and_return(error_output)
|
|
69
93
|
@sut.additional_message = additional_message
|
|
70
94
|
@sut.check_format(fail_on_error: true)
|
|
71
95
|
|
|
@@ -86,7 +110,7 @@ module Danger
|
|
|
86
110
|
allow(@sut.git).to receive(:renamed_files).and_return([{}])
|
|
87
111
|
allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
|
|
88
112
|
allow_any_instance_of(SwiftFormat).to receive(:check_format)
|
|
89
|
-
.with(%w(Added.swift), nil)
|
|
113
|
+
.with(%w(Added.swift), nil, nil)
|
|
90
114
|
.and_return(success_output)
|
|
91
115
|
|
|
92
116
|
@sut.exclude = exclude
|
|
@@ -110,7 +134,7 @@ module Danger
|
|
|
110
134
|
allow(@sut.git).to receive(:renamed_files).and_return([{ before: "ModifiedBefore.swift", after: "ModifiedAfter.swift" }])
|
|
111
135
|
allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
|
|
112
136
|
allow_any_instance_of(SwiftFormat).to receive(:check_format)
|
|
113
|
-
.with(%w(Added.swift ModifiedAfter.swift), additional_args)
|
|
137
|
+
.with(%w(Added.swift ModifiedAfter.swift), additional_args, nil)
|
|
114
138
|
.and_return(success_output)
|
|
115
139
|
|
|
116
140
|
@sut.additional_args = additional_args
|
|
@@ -156,7 +180,7 @@ module Danger
|
|
|
156
180
|
|
|
157
181
|
context "when swiftformat does not find any errors" do
|
|
158
182
|
before do
|
|
159
|
-
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil).and_return(success_output)
|
|
183
|
+
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil, nil).and_return(success_output)
|
|
160
184
|
end
|
|
161
185
|
|
|
162
186
|
it "should not do anything" do
|
|
@@ -170,7 +194,7 @@ module Danger
|
|
|
170
194
|
|
|
171
195
|
context "when swiftformat finds errors" do
|
|
172
196
|
before do
|
|
173
|
-
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil).and_return(error_output)
|
|
197
|
+
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil, nil).and_return(error_output)
|
|
174
198
|
end
|
|
175
199
|
|
|
176
200
|
it "should output some markdown and error if fail_on_error is true" do
|
|
@@ -36,7 +36,7 @@ RSpec.describe Danger::SwiftFormat do
|
|
|
36
36
|
it "should run swiftformat on the specified files" do
|
|
37
37
|
files = %w(/path/to/file.swift /path/to/directory/)
|
|
38
38
|
expect(@cmd).to receive(:run)
|
|
39
|
-
.with(%w(swiftformat /path/to/file.swift /path/to/directory/ --
|
|
39
|
+
.with(%w(swiftformat /path/to/file.swift /path/to/directory/ --lint --lenient))
|
|
40
40
|
.and_return(fixture("swiftformat_output.txt"))
|
|
41
41
|
|
|
42
42
|
@sut.check_format(files)
|
|
@@ -44,18 +44,17 @@ RSpec.describe Danger::SwiftFormat do
|
|
|
44
44
|
|
|
45
45
|
it "should return a formatted output including rules when there are errors" do
|
|
46
46
|
expect(@cmd).to receive(:run)
|
|
47
|
-
.with(%w(swiftformat . --
|
|
47
|
+
.with(%w(swiftformat . --lint --lenient))
|
|
48
48
|
.and_return(fixture("swiftformat_output_with_errors.txt"))
|
|
49
49
|
|
|
50
50
|
output = {
|
|
51
51
|
errors: [
|
|
52
|
-
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
52
|
+
{ file: "spec/fixtures/1_BadFile.swift:3:1", rules: ["warning: (spaceAroundOperators) Add or remove space around operators or delimiters."] },
|
|
53
|
+
{ file: "spec/fixtures/1_BadFile.swift:4:1", rules: ["warning: (spaceInsideParens) Remove space inside parentheses."] },
|
|
54
|
+
{ file: "spec/fixtures/1_BadFile.swift:5:1", rules: ["warning: (indent) Indent code in accordance with the scope level."] }
|
|
56
55
|
],
|
|
57
56
|
stats: {
|
|
58
|
-
run_time: "0.
|
|
57
|
+
run_time: "0.02"
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
expect(@sut.check_format(%w(.))).to eq(output)
|
|
@@ -63,13 +62,13 @@ RSpec.describe Danger::SwiftFormat do
|
|
|
63
62
|
|
|
64
63
|
it "should also return a formatted output if there were no errors" do
|
|
65
64
|
expect(@cmd).to receive(:run)
|
|
66
|
-
.with(%w(swiftformat . --
|
|
65
|
+
.with(%w(swiftformat . --lint --lenient))
|
|
67
66
|
.and_return(fixture("swiftformat_output.txt"))
|
|
68
67
|
|
|
69
68
|
output = {
|
|
70
69
|
errors: [],
|
|
71
70
|
stats: {
|
|
72
|
-
run_time: "0.
|
|
71
|
+
run_time: "0.01"
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
|
|
@@ -78,7 +77,7 @@ RSpec.describe Danger::SwiftFormat do
|
|
|
78
77
|
|
|
79
78
|
it "should raise an error if the output is empty" do
|
|
80
79
|
expect(@cmd).to receive(:run)
|
|
81
|
-
.with(%w(swiftformat . --
|
|
80
|
+
.with(%w(swiftformat . --lint --lenient))
|
|
82
81
|
.and_return("")
|
|
83
82
|
|
|
84
83
|
expect { @sut.check_format(%w(.)) }.to raise_error("Error running SwiftFormat: Empty output.")
|
|
@@ -86,13 +85,13 @@ RSpec.describe Danger::SwiftFormat do
|
|
|
86
85
|
|
|
87
86
|
it "should support nil additional command line arguments" do
|
|
88
87
|
expect(@cmd).to receive(:run)
|
|
89
|
-
.with(%w(swiftformat . --
|
|
88
|
+
.with(%w(swiftformat . --lint --lenient))
|
|
90
89
|
.and_return(fixture("swiftformat_output.txt"))
|
|
91
90
|
|
|
92
91
|
output = {
|
|
93
92
|
errors: [],
|
|
94
93
|
stats: {
|
|
95
|
-
run_time: "0.
|
|
94
|
+
run_time: "0.01"
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
|
|
@@ -101,22 +100,22 @@ RSpec.describe Danger::SwiftFormat do
|
|
|
101
100
|
|
|
102
101
|
it "should support additional command line arguments" do
|
|
103
102
|
expect(@cmd).to receive(:run)
|
|
104
|
-
.with(%w(swiftformat . --self insert --indent tab --
|
|
103
|
+
.with(%w(swiftformat . --self insert --indent tab --swiftversion 5 --lint --lenient))
|
|
105
104
|
.and_return(fixture("swiftformat_output.txt"))
|
|
106
105
|
|
|
107
106
|
output = {
|
|
108
107
|
errors: [],
|
|
109
108
|
stats: {
|
|
110
|
-
run_time: "0.
|
|
109
|
+
run_time: "0.01"
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
expect(@sut.check_format(%w(.), "--self insert --indent tab")).to eq(output)
|
|
113
|
+
expect(@sut.check_format(%w(.), "--self insert --indent tab", "5")).to eq(output)
|
|
115
114
|
end
|
|
116
115
|
|
|
117
116
|
it "should not crash if the output is invalid" do
|
|
118
117
|
expect(@cmd).to receive(:run)
|
|
119
|
-
.with(%w(swiftformat . --self insert --indent tab --
|
|
118
|
+
.with(%w(swiftformat . --self insert --indent tab --lint --lenient))
|
|
120
119
|
.and_return(fixture("swiftformat_output_bad.txt"))
|
|
121
120
|
|
|
122
121
|
output = {
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: danger-swiftformat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vincent Garrigues
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: danger-plugin-api
|
|
@@ -157,9 +157,9 @@ executables: []
|
|
|
157
157
|
extensions: []
|
|
158
158
|
extra_rdoc_files: []
|
|
159
159
|
files:
|
|
160
|
+
- ".github/workflows/ruby.yml"
|
|
160
161
|
- ".gitignore"
|
|
161
162
|
- ".rubocop.yml"
|
|
162
|
-
- ".travis.yml"
|
|
163
163
|
- Gemfile
|
|
164
164
|
- Gemfile.lock
|
|
165
165
|
- Guardfile
|
|
@@ -174,6 +174,9 @@ files:
|
|
|
174
174
|
- lib/swiftformat/plugin.rb
|
|
175
175
|
- lib/swiftformat/swiftformat.rb
|
|
176
176
|
- scripts/release.sh
|
|
177
|
+
- spec/fixtures/0_GoodFile.swift
|
|
178
|
+
- spec/fixtures/1_BadFile.swift
|
|
179
|
+
- spec/fixtures/2_GoodFile.swift
|
|
177
180
|
- spec/fixtures/swiftformat_output.txt
|
|
178
181
|
- spec/fixtures/swiftformat_output_bad.txt
|
|
179
182
|
- spec/fixtures/swiftformat_output_with_errors.txt
|
|
@@ -185,7 +188,7 @@ licenses:
|
|
|
185
188
|
- MIT
|
|
186
189
|
metadata:
|
|
187
190
|
github_repo: ssh://github.com/garriguv/danger-ruby-swiftformat
|
|
188
|
-
post_install_message:
|
|
191
|
+
post_install_message:
|
|
189
192
|
rdoc_options: []
|
|
190
193
|
require_paths:
|
|
191
194
|
- lib
|
|
@@ -200,11 +203,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
200
203
|
- !ruby/object:Gem::Version
|
|
201
204
|
version: '0'
|
|
202
205
|
requirements: []
|
|
203
|
-
rubygems_version: 3.
|
|
204
|
-
signing_key:
|
|
206
|
+
rubygems_version: 3.1.4
|
|
207
|
+
signing_key:
|
|
205
208
|
specification_version: 4
|
|
206
209
|
summary: A danger plugin for checking Swift formatting using SwiftFormat.
|
|
207
210
|
test_files:
|
|
211
|
+
- spec/fixtures/0_GoodFile.swift
|
|
212
|
+
- spec/fixtures/1_BadFile.swift
|
|
213
|
+
- spec/fixtures/2_GoodFile.swift
|
|
208
214
|
- spec/fixtures/swiftformat_output.txt
|
|
209
215
|
- spec/fixtures/swiftformat_output_bad.txt
|
|
210
216
|
- spec/fixtures/swiftformat_output_with_errors.txt
|