danger-swiftformat 0.0.3 → 0.1.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/Gemfile.lock +1 -1
- data/README.md +6 -0
- data/lib/swiftformat/gem_version.rb +1 -1
- data/lib/swiftformat/plugin.rb +6 -1
- data/lib/swiftformat/swiftformat.rb +5 -2
- data/spec/swiftformat/plugin_spec.rb +26 -3
- data/spec/swiftformat/swiftformat_spec.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 375ea947e323e0f7e27fc180969cd1b7f0228d9f
|
4
|
+
data.tar.gz: 5266c96a6d360af8651220a7b6f29132e35505af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 731725453eaa2221908d99a3ce79457f21e43dd233197ec72765527fb594f5b31dac3e7a71cfafc89d21688b18a7e78240e108a6eafb3d0de1d0ca88398469b0
|
7
|
+
data.tar.gz: 677b404b8451886b45e72c14623a0b63e9effc5443e015100c968e3dd07122c23792bfe2b5e63f02a31b4b191ddba40cf3633737df3d6401b60eff940b10435a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,12 @@ You can specify the `swiftformat` binary using the `binary_path` parameter:
|
|
34
34
|
swiftformat.binary_path = "/path/to/swiftformat"
|
35
35
|
```
|
36
36
|
|
37
|
+
You can specify additional `swiftformat` arguments using the `additional_swiftformat_args` parameter:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
swiftformat.additional_swiftformat_args = "--indent tab --self insert"
|
41
|
+
```
|
42
|
+
|
37
43
|
## Development
|
38
44
|
|
39
45
|
1. Clone this repo
|
data/lib/swiftformat/plugin.rb
CHANGED
@@ -14,6 +14,11 @@ module Danger
|
|
14
14
|
# @return [String]
|
15
15
|
attr_accessor :binary_path
|
16
16
|
|
17
|
+
# Additional swiftformat command line arguments
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
attr_accessor :additional_swiftformat_args
|
21
|
+
|
17
22
|
# Runs swiftformat
|
18
23
|
#
|
19
24
|
# @param [Boolean] fail_on_error
|
@@ -31,7 +36,7 @@ module Danger
|
|
31
36
|
return if swift_files.empty?
|
32
37
|
|
33
38
|
# Run swiftformat
|
34
|
-
results = swiftformat.check_format(swift_files)
|
39
|
+
results = swiftformat.check_format(swift_files, additional_swiftformat_args)
|
35
40
|
|
36
41
|
# Stop processing if the errors array is empty
|
37
42
|
return if results[:errors].empty?
|
@@ -8,8 +8,11 @@ module Danger
|
|
8
8
|
Cmd.run([@path, "--version"])
|
9
9
|
end
|
10
10
|
|
11
|
-
def check_format(files)
|
12
|
-
|
11
|
+
def check_format(files, additional_args = "")
|
12
|
+
cmd = [@path] + files
|
13
|
+
cmd << additional_args.split unless additional_args.empty?
|
14
|
+
cmd << %w(--dryrun --verbose)
|
15
|
+
output = Cmd.run(cmd.flatten)
|
13
16
|
raise "error running swiftformat: empty output" if output.empty?
|
14
17
|
process(output)
|
15
18
|
end
|
@@ -31,13 +31,36 @@ module Danger
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
context "with additional_swiftformat_args" do
|
35
|
+
let(:additional_swiftformat_args) { "--indent tab --self insert" }
|
36
|
+
let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } }
|
37
|
+
|
38
|
+
it "should pass the additional flags to swiftformat" do
|
39
|
+
allow(@sut.git).to receive(:added_files).and_return(["Added.swift"])
|
40
|
+
allow(@sut.git).to receive(:modified_files).and_return(["Modified.swift"])
|
41
|
+
allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
|
42
|
+
allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
|
43
|
+
allow_any_instance_of(SwiftFormat).to receive(:check_format)
|
44
|
+
.with(%w(Added.swift Modified.swift), additional_swiftformat_args)
|
45
|
+
.and_return(success_output)
|
46
|
+
|
47
|
+
@sut.additional_swiftformat_args = additional_swiftformat_args
|
48
|
+
|
49
|
+
@sut.check_format(fail_on_error: true)
|
50
|
+
|
51
|
+
status = @sut.status_report
|
52
|
+
expect(status[:errors]).to be_empty
|
53
|
+
expect(status[:markdowns]).to be_empty
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
34
57
|
describe "#check_format" do
|
35
58
|
let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } }
|
36
59
|
let(:error_output) { { errors: [{ file: "Modified.swift", rules: %w(firstRule secondRule) }], stats: { run_time: "0.16s" } } }
|
37
60
|
|
38
|
-
|
39
61
|
context "when there are no swift files to check" do
|
40
62
|
before do
|
63
|
+
allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
|
41
64
|
allow(@sut.git).to receive(:added_files).and_return(["Added.m"])
|
42
65
|
allow(@sut.git).to receive(:modified_files).and_return(["Modified.m"])
|
43
66
|
allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.m"])
|
@@ -62,7 +85,7 @@ module Danger
|
|
62
85
|
|
63
86
|
context "when swiftformat does not find any errors" do
|
64
87
|
before do
|
65
|
-
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift)).and_return(success_output)
|
88
|
+
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil).and_return(success_output)
|
66
89
|
end
|
67
90
|
|
68
91
|
it "should not do anything" do
|
@@ -76,7 +99,7 @@ module Danger
|
|
76
99
|
|
77
100
|
context "when swiftformat finds errors" do
|
78
101
|
before do
|
79
|
-
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift)).and_return(error_output)
|
102
|
+
allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil).and_return(error_output)
|
80
103
|
end
|
81
104
|
|
82
105
|
it "should output some markdown and error if fail_on_error is true" do
|
@@ -83,5 +83,20 @@ RSpec.describe Danger::SwiftFormat do
|
|
83
83
|
|
84
84
|
expect { @sut.check_format(%w(.)) }.to raise_error("error running swiftformat: empty output")
|
85
85
|
end
|
86
|
+
|
87
|
+
it "should support additional command line arguments" do
|
88
|
+
expect(@cmd).to receive(:run)
|
89
|
+
.with(%w(swiftformat . --self insert --indent tab --dryrun --verbose))
|
90
|
+
.and_return(fixture("swiftformat_output.txt"))
|
91
|
+
|
92
|
+
output = {
|
93
|
+
errors: [],
|
94
|
+
stats: {
|
95
|
+
run_time: "0.08"
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
expect(@sut.check_format(%w(.), "--self insert --indent tab")).to eq(output)
|
100
|
+
end
|
86
101
|
end
|
87
102
|
end
|