danger-swiftformat 0.0.3 → 0.1.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
  SHA1:
3
- metadata.gz: 4c8c48bd8f7f861b6222d443bfa92df522b3808f
4
- data.tar.gz: 0a8d82cb15fc5bc6e4fd9c7d663bdc246b160680
3
+ metadata.gz: 375ea947e323e0f7e27fc180969cd1b7f0228d9f
4
+ data.tar.gz: 5266c96a6d360af8651220a7b6f29132e35505af
5
5
  SHA512:
6
- metadata.gz: 95dc50ab3b0fdea5415783920e82c231619472bcf8c07e8d9b70a97496100a8f2147b218c0db082232f36c5ed05209a21d41dab9fde5f59504abfdc20b254b2e
7
- data.tar.gz: a509022e22ab09438da6f9098c47857d1cbb7e846ed4e0b9037b6192ef3c0e31973a2fdd1a0104ed1aee910f4bdc7a6d961d72185aec3f2f2e7d8410d7bba02a
6
+ metadata.gz: 731725453eaa2221908d99a3ce79457f21e43dd233197ec72765527fb594f5b31dac3e7a71cfafc89d21688b18a7e78240e108a6eafb3d0de1d0ca88398469b0
7
+ data.tar.gz: 677b404b8451886b45e72c14623a0b63e9effc5443e015100c968e3dd07122c23792bfe2b5e63f02a31b4b191ddba40cf3633737df3d6401b60eff940b10435a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-swiftformat (0.0.3)
4
+ danger-swiftformat (0.1.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
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
@@ -1,3 +1,3 @@
1
1
  module Swiftformat
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
@@ -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
- output = Cmd.run([@path] + files + %w(--dryrun --verbose))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-swiftformat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Garrigues