danger-swiftformat 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 1e4ff2c06c4f47af744f1ecc4900ec266670fd93c20180b0aedd39a808f3c54c
4
- data.tar.gz: 96433fecb5ba65121988850db61de14cd990d30f05146764e918766e006b7daf
3
+ metadata.gz: 4725bb4b3e493d619b7bcc38c909823aa6d014a31fe938341f8488a40690e8ce
4
+ data.tar.gz: 7ea2c85afac6d489fc255f0618e0e02002feba04e59f50df23374cab5c6e2a3b
5
5
  SHA512:
6
- metadata.gz: '093e955e3ad8c198b162e557746ab18fc572ef5d99f856d0c054db05d402a1e4f1b48d3c4f6c39b5cc88d30fdc4e4fd05cefc3cd3bd64339c06a3146546aee28'
7
- data.tar.gz: 29b8270dcc22adbd1e84c2dd128c0f5c5c4f60bd52349480cc8896087edfbc3abd1a9c0c7ad52b2a6571c5e863a3831e3b8ad4b1363410f3d448c12c5c66122b
6
+ metadata.gz: fb8be55f45b39b9b2a7f7adee5a1f4cfbfb87b029cf36a6cc2ca69a27885ce1a3c9009d9de687202e4e071dd8174f1ee623c3725570401c949add0f841ce162a
7
+ data.tar.gz: 8d78eb43d9e124cdd39b70521ac0b7583e17fa32851928cd72aeb9ab3d40bd3a6fb96536d797585e68d4ebfc8dfb657f949490502fb04e6d75dd8868419bf1a8
@@ -150,3 +150,7 @@ PercentLiteralDelimiters:
150
150
 
151
151
  Security/YAMLLoad:
152
152
  Enabled: false
153
+
154
+ Metrics/ModuleLength:
155
+ Exclude:
156
+ - "**/*_spec.rb"
@@ -1,12 +1,15 @@
1
1
  language: ruby
2
- cache:
3
- directories:
4
- - bundle
2
+ cache: bundler
3
+
4
+ before_install:
5
+ - gem update --system
6
+ - gem install bundler
5
7
 
6
8
  rvm:
7
- - 2.2.8
8
- - 2.3.5
9
- - 2.4.2
9
+ - 2.3.8
10
+ - 2.4.4
11
+ - 2.5.3
12
+ - 2.6.3
10
13
 
11
14
  script:
12
15
  - bundle exec rake spec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-swiftformat (0.4.0)
4
+ danger-swiftformat (0.5.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
@@ -19,7 +19,7 @@ GEM
19
19
  colored2 (3.1.2)
20
20
  cork (0.3.0)
21
21
  colored2 (~> 3.1)
22
- danger (5.11.0)
22
+ danger (6.0.6)
23
23
  claide (~> 1.0)
24
24
  claide-plugins (>= 0.9.2)
25
25
  colored2 (~> 3.1)
@@ -27,7 +27,8 @@ GEM
27
27
  faraday (~> 0.9)
28
28
  faraday-http-cache (~> 1.0)
29
29
  git (~> 1.5)
30
- kramdown (~> 1.5)
30
+ kramdown (~> 2.0)
31
+ kramdown-parser-gfm (~> 1.0)
31
32
  no_proxy_fix
32
33
  octokit (~> 4.7)
33
34
  terminal-table (~> 1)
@@ -38,10 +39,10 @@ GEM
38
39
  multipart-post (>= 1.2, < 3)
39
40
  faraday-http-cache (1.3.1)
40
41
  faraday (~> 0.8)
41
- ffi (1.9.25)
42
+ ffi (1.10.0)
42
43
  formatador (0.2.5)
43
44
  git (1.5.0)
44
- guard (2.14.2)
45
+ guard (2.15.0)
45
46
  formatador (>= 0.2.4)
46
47
  listen (>= 2.7, < 4.0)
47
48
  lumberjack (>= 1.0.12, < 2.0)
@@ -55,14 +56,16 @@ GEM
55
56
  guard (~> 2.1)
56
57
  guard-compat (~> 1.1)
57
58
  rspec (>= 2.99.0, < 4.0)
58
- jaro_winkler (1.5.1)
59
- kramdown (1.17.0)
59
+ jaro_winkler (1.5.2)
60
+ kramdown (2.1.0)
61
+ kramdown-parser-gfm (1.0.1)
62
+ kramdown (~> 2.0)
60
63
  listen (3.1.5)
61
64
  rb-fsevent (~> 0.9, >= 0.9.4)
62
65
  rb-inotify (~> 0.9, >= 0.9.7)
63
66
  ruby_dep (~> 1.2)
64
67
  lumberjack (1.0.13)
65
- method_source (0.9.0)
68
+ method_source (0.9.2)
66
69
  multipart-post (2.0.0)
67
70
  nap (1.1.0)
68
71
  nenv (0.3.0)
@@ -70,43 +73,43 @@ GEM
70
73
  notiffany (0.1.1)
71
74
  nenv (~> 0.1)
72
75
  shellany (~> 0.0)
73
- octokit (4.13.0)
76
+ octokit (4.14.0)
74
77
  sawyer (~> 0.8.0, >= 0.5.3)
75
78
  open4 (1.3.4)
76
- parallel (1.12.1)
77
- parser (2.5.1.2)
79
+ parallel (1.17.0)
80
+ parser (2.6.2.1)
78
81
  ast (~> 2.4.0)
79
- powerpack (0.1.2)
80
- pry (0.11.3)
82
+ pry (0.12.2)
81
83
  coderay (~> 1.1.0)
82
84
  method_source (~> 0.9.0)
85
+ psych (3.1.0)
83
86
  public_suffix (3.0.3)
84
87
  rainbow (3.0.0)
85
- rake (12.3.1)
88
+ rake (12.3.2)
86
89
  rb-fsevent (0.10.3)
87
- rb-inotify (0.9.10)
88
- ffi (>= 0.5.0, < 2)
90
+ rb-inotify (0.10.0)
91
+ ffi (~> 1.0)
89
92
  rspec (3.8.0)
90
93
  rspec-core (~> 3.8.0)
91
94
  rspec-expectations (~> 3.8.0)
92
95
  rspec-mocks (~> 3.8.0)
93
96
  rspec-core (3.8.0)
94
97
  rspec-support (~> 3.8.0)
95
- rspec-expectations (3.8.1)
98
+ rspec-expectations (3.8.3)
96
99
  diff-lcs (>= 1.2.0, < 2.0)
97
100
  rspec-support (~> 3.8.0)
98
101
  rspec-mocks (3.8.0)
99
102
  diff-lcs (>= 1.2.0, < 2.0)
100
103
  rspec-support (~> 3.8.0)
101
104
  rspec-support (3.8.0)
102
- rubocop (0.59.0)
105
+ rubocop (0.67.2)
103
106
  jaro_winkler (~> 1.5.1)
104
107
  parallel (~> 1.10)
105
108
  parser (>= 2.5, != 2.5.1.1)
106
- powerpack (~> 0.1)
109
+ psych (>= 3.1.0)
107
110
  rainbow (>= 2.2.2, < 4.0)
108
111
  ruby-progressbar (~> 1.7)
109
- unicode-display_width (~> 1.0, >= 1.0.1)
112
+ unicode-display_width (>= 1.4.0, < 1.6)
110
113
  ruby-progressbar (1.10.0)
111
114
  ruby_dep (1.5.0)
112
115
  sawyer (0.8.1)
@@ -115,9 +118,9 @@ GEM
115
118
  shellany (0.0.1)
116
119
  terminal-table (1.8.0)
117
120
  unicode-display_width (~> 1.1, >= 1.1.1)
118
- thor (0.20.0)
119
- unicode-display_width (1.4.0)
120
- yard (0.9.16)
121
+ thor (0.20.3)
122
+ unicode-display_width (1.5.0)
123
+ yard (0.9.19)
121
124
 
122
125
  PLATFORMS
123
126
  ruby
data/README.md CHANGED
@@ -8,7 +8,7 @@ This plugin is heavily inspired by [danger-swiftlint].
8
8
 
9
9
  Add this line to your Gemfile:
10
10
 
11
- require 'danger-swiftformat'
11
+ gem 'danger-swiftformat'
12
12
 
13
13
  [SwiftFormat] also needs to be installed before you run Danger.
14
14
 
@@ -22,6 +22,8 @@ swiftformat.check_format
22
22
 
23
23
  By default, danger-swiftformat will check added and modified files.
24
24
 
25
+ ## Options and parameters
26
+
25
27
  If you want errors to fail Danger, you can use the `fail_on_error` option:
26
28
 
27
29
  ```ruby
@@ -40,6 +42,16 @@ You can specify additional `swiftformat` arguments using the `additional_args` p
40
42
  swiftformat.additional_args = "--indent tab --self insert"
41
43
  ```
42
44
 
45
+ By default, `danger-swiftformat` will run on any modified or created file ending in `.swift`. If you'd like to exclude
46
+ certain directories or files such as `Pods`, you can use the `exclude` parameter:
47
+
48
+ ```ruby
49
+ swiftformat.exclude = %w(Pods/** Carthage/** Sources/Nope.swift **/*_autogenerated.swift)
50
+ ```
51
+
52
+ The `exclude` option takes an array of glob patterns; you can find additional documentation on the patterns
53
+ [here](https://ruby-doc.org/core-2.6.3/File.html#method-c-fnmatch).
54
+
43
55
  ## Development
44
56
 
45
57
  1. Clone this repo
@@ -1,3 +1,3 @@
1
1
  module Swiftformat
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -19,6 +19,16 @@ module Danger
19
19
  # @return [String]
20
20
  attr_accessor :additional_args
21
21
 
22
+ # Additional message to be appended the report
23
+ #
24
+ # @return [String]
25
+ attr_accessor :additional_message
26
+
27
+ # An array of file and directory paths to exclude
28
+ #
29
+ # @return [Array<String]
30
+ attr_accessor :exclude
31
+
22
32
  # Runs swiftformat
23
33
  #
24
34
  # @param [Boolean] fail_on_error
@@ -48,6 +58,11 @@ module Danger
48
58
  results[:errors].each do |error|
49
59
  message << "| #{error[:file].gsub(Dir.pwd + '/', '')} | #{error[:rules].join(', ')} |\n"
50
60
  end
61
+
62
+ unless additional_message.nil?
63
+ message << "\n" << additional_message
64
+ end
65
+
51
66
  markdown message
52
67
 
53
68
  if fail_on_error
@@ -61,8 +76,11 @@ module Danger
61
76
  def find_swift_files
62
77
  files = (git.modified_files - git.deleted_files) + git.added_files
63
78
 
79
+ @exclude = %w() if @exclude.nil?
80
+
64
81
  files
65
82
  .select { |file| file.end_with?(".swift") }
83
+ .reject { |file| @exclude.any? { |glob| File.fnmatch(glob, file) } }
66
84
  .uniq
67
85
  .sort
68
86
  end
@@ -41,7 +41,7 @@ module Danger
41
41
  }
42
42
  end
43
43
 
44
- ERRORS_REGEX = /rules applied:(.*)\n.*updated (.*)$/
44
+ ERRORS_REGEX = /rules applied:(.*)\n.*updated (.*)$/.freeze
45
45
 
46
46
  def errors(output)
47
47
  errors = []
@@ -56,7 +56,7 @@ module Danger
56
56
  errors
57
57
  end
58
58
 
59
- RUNTIME_REGEX = /.*swiftformat completed.*(.+\..+)s/
59
+ RUNTIME_REGEX = /.*swiftformat completed.*(.+\..+)s/.freeze
60
60
 
61
61
  def run_time(output)
62
62
  if RUNTIME_REGEX.match(output)
@@ -54,6 +54,48 @@ module Danger
54
54
  end
55
55
  end
56
56
 
57
+ context "with additional_message" do
58
+ let(:additional_message) { "I'm the additional message." }
59
+ let(:error_output) { { errors: [{ file: "Modified.swift", rules: %w(firstRule secondRule) }], stats: { run_time: "0.16s" } } }
60
+
61
+ it "should include the additional message in the report" do
62
+ allow(@sut.git).to receive(:added_files).and_return(["Added.swift"])
63
+ allow(@sut.git).to receive(:modified_files).and_return(["Modified.swift"])
64
+ allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
65
+ allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
66
+ allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil).and_return(error_output)
67
+ @sut.additional_message = additional_message
68
+ @sut.check_format(fail_on_error: true)
69
+
70
+ status = @sut.status_report
71
+ markdown = status[:markdowns].first.message
72
+ expect(markdown).to include(additional_message)
73
+ end
74
+ end
75
+
76
+ context "with exclude" do
77
+ let(:exclude) { %w(**/Modified.swift Pods/** Carthage/** **/*_autogenerated.swift) }
78
+ let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } }
79
+
80
+ it "should filter the files passed to swiftformat" do
81
+ allow(@sut.git).to receive(:added_files).and_return(%w(Added.swift Pods/Test.swift Carthage/SQLite.swift Sources/Module/JSONParsing_autogenerated.swift))
82
+ allow(@sut.git).to receive(:modified_files).and_return(["Source/Modified.swift"])
83
+ allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
84
+ allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
85
+ allow_any_instance_of(SwiftFormat).to receive(:check_format)
86
+ .with(%w(Added.swift), nil)
87
+ .and_return(success_output)
88
+
89
+ @sut.exclude = exclude
90
+
91
+ @sut.check_format(fail_on_error: true)
92
+
93
+ status = @sut.status_report
94
+ expect(status[:errors]).to be_empty
95
+ expect(status[:markdowns]).to be_empty
96
+ end
97
+ end
98
+
57
99
  describe "#check_format" do
58
100
  let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } }
59
101
  let(:error_output) { { errors: [{ file: "Modified.swift", rules: %w(firstRule secondRule) }], stats: { run_time: "0.16s" } } }
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.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Garrigues
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-04 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  requirements: []
201
- rubygems_version: 3.0.1
201
+ rubygems_version: 3.0.3
202
202
  signing_key:
203
203
  specification_version: 4
204
204
  summary: A danger plugin for checking Swift formatting using SwiftFormat.