danger-swiftformat 0.4.0 → 0.8.1

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: b79df1cd49dbf9b086b132f91292f0db8e0bae4cc7118feaa865a1353df10b80
4
+ data.tar.gz: 747b28dda4e5917274519b6205fabeaa0ff33f674bbf906387e8d188f6b55de9
5
5
  SHA512:
6
- metadata.gz: '093e955e3ad8c198b162e557746ab18fc572ef5d99f856d0c054db05d402a1e4f1b48d3c4f6c39b5cc88d30fdc4e4fd05cefc3cd3bd64339c06a3146546aee28'
7
- data.tar.gz: 29b8270dcc22adbd1e84c2dd128c0f5c5c4f60bd52349480cc8896087edfbc3abd1a9c0c7ad52b2a6571c5e863a3831e3b8ad4b1363410f3d448c12c5c66122b
6
+ metadata.gz: 10a5bec311017e59fae92cf9144a5f2a199993c5e6ad0dc0f60f6634fbdb3868633a8ed2ee99d45a5d61ce414c1fd5e6f431c3b736cecd61d94043a63143497c
7
+ data.tar.gz: 16e57a203cf81103dc0aca649e61fc4d14d9e758f73fef76d8c3f48e07f0509809a345e2523d1d3556122ae92ee0fc8cd486924accac25cbad8c83e585b92976
@@ -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
@@ -3,7 +3,8 @@
3
3
  # If you don't like these settings, just delete this file :)
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.2
6
+ TargetRubyVersion: 2.4
7
+ NewCops: enable
7
8
 
8
9
  Style/StringLiterals:
9
10
  EnforcedStyle: double_quotes
@@ -13,20 +14,16 @@ Style/StringLiterals:
13
14
  Style/ClassCheck:
14
15
  EnforcedStyle: kind_of?
15
16
 
16
- # It's better to be more explicit about the type
17
- Style/BracesAroundHashParameters:
18
- Enabled: false
19
-
20
17
  # specs sometimes have useless assignments, which is fine
21
18
  Lint/UselessAssignment:
22
19
  Exclude:
23
20
  - '**/spec/**/*'
24
21
 
25
22
  # We could potentially enable the 2 below:
26
- Layout/IndentHash:
23
+ Layout/FirstHashElementIndentation:
27
24
  Enabled: false
28
25
 
29
- Layout/AlignHash:
26
+ Layout/HashAlignment:
30
27
  Enabled: false
31
28
 
32
29
  # HoundCI doesn't like this rule
@@ -37,6 +34,18 @@ Layout/DotPosition:
37
34
  Style/DoubleNegation:
38
35
  Enabled: false
39
36
 
37
+ Style/FrozenStringLiteralComment:
38
+ Enabled: false
39
+
40
+ Style/HashEachMethods:
41
+ Enabled: false
42
+
43
+ Style/HashTransformKeys:
44
+ Enabled: true
45
+
46
+ Style/HashTransformValues:
47
+ Enabled: true
48
+
40
49
  # Cop supports --auto-correct.
41
50
  Lint/UnusedBlockArgument:
42
51
  Enabled: false
@@ -130,7 +139,7 @@ Style/MixinGrouping:
130
139
  Naming/FileName:
131
140
  Enabled: false
132
141
 
133
- Layout/IndentHeredoc:
142
+ Layout/HeredocIndentation:
134
143
  Enabled: false
135
144
 
136
145
  Style/SpecialGlobalVars:
@@ -150,3 +159,7 @@ PercentLiteralDelimiters:
150
159
 
151
160
  Security/YAMLLoad:
152
161
  Enabled: false
162
+
163
+ Metrics/ModuleLength:
164
+ Exclude:
165
+ - "**/*_spec.rb"
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in danger-swiftformat.gemspec
4
4
  gemspec
5
+ gem "faraday", "0.15.4"
@@ -1,47 +1,49 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-swiftformat (0.4.0)
4
+ danger-swiftformat (0.8.1)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.5.2)
11
- public_suffix (>= 2.0.2, < 4.0)
12
- ast (2.4.0)
13
- claide (1.0.2)
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.2)
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.2)
18
+ coderay (1.1.3)
19
19
  colored2 (3.1.2)
20
20
  cork (0.3.0)
21
21
  colored2 (~> 3.1)
22
- danger (5.11.0)
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 (~> 0.9)
28
- faraday-http-cache (~> 1.0)
29
- git (~> 1.5)
30
- kramdown (~> 1.5)
27
+ faraday (>= 0.9.0, < 2.0)
28
+ faraday-http-cache (~> 2.0)
29
+ git (~> 1.7)
30
+ kramdown (~> 2.3)
31
+ kramdown-parser-gfm (~> 1.0)
31
32
  no_proxy_fix
32
33
  octokit (~> 4.7)
33
34
  terminal-table (~> 1)
34
35
  danger-plugin-api (1.0.0)
35
36
  danger (> 2.0)
36
- diff-lcs (1.3)
37
+ diff-lcs (1.4.4)
37
38
  faraday (0.15.4)
38
39
  multipart-post (>= 1.2, < 3)
39
- faraday-http-cache (1.3.1)
40
- faraday (~> 0.8)
41
- ffi (1.9.25)
40
+ faraday-http-cache (2.2.0)
41
+ faraday (>= 0.8)
42
+ ffi (1.14.2)
42
43
  formatador (0.2.5)
43
- git (1.5.0)
44
- guard (2.14.2)
44
+ git (1.8.1)
45
+ rchardet (~> 1.8)
46
+ guard (2.16.2)
45
47
  formatador (>= 0.2.4)
46
48
  listen (>= 2.7, < 4.0)
47
49
  lumberjack (>= 1.0.12, < 2.0)
@@ -55,76 +57,83 @@ GEM
55
57
  guard (~> 2.1)
56
58
  guard-compat (~> 1.1)
57
59
  rspec (>= 2.99.0, < 4.0)
58
- jaro_winkler (1.5.1)
59
- kramdown (1.17.0)
60
- listen (3.1.5)
61
- rb-fsevent (~> 0.9, >= 0.9.4)
62
- rb-inotify (~> 0.9, >= 0.9.7)
63
- ruby_dep (~> 1.2)
64
- lumberjack (1.0.13)
65
- method_source (0.9.0)
66
- multipart-post (2.0.0)
60
+ kramdown (2.3.0)
61
+ rexml
62
+ kramdown-parser-gfm (1.1.0)
63
+ kramdown (~> 2.0)
64
+ listen (3.4.1)
65
+ rb-fsevent (~> 0.10, >= 0.10.3)
66
+ rb-inotify (~> 0.9, >= 0.9.10)
67
+ lumberjack (1.2.8)
68
+ method_source (1.0.0)
69
+ multipart-post (2.1.1)
67
70
  nap (1.1.0)
68
71
  nenv (0.3.0)
69
72
  no_proxy_fix (0.1.2)
70
- notiffany (0.1.1)
73
+ notiffany (0.1.3)
71
74
  nenv (~> 0.1)
72
75
  shellany (~> 0.0)
73
- octokit (4.13.0)
76
+ octokit (4.20.0)
77
+ faraday (>= 0.9)
74
78
  sawyer (~> 0.8.0, >= 0.5.3)
75
79
  open4 (1.3.4)
76
- parallel (1.12.1)
77
- parser (2.5.1.2)
78
- ast (~> 2.4.0)
79
- powerpack (0.1.2)
80
- pry (0.11.3)
81
- coderay (~> 1.1.0)
82
- method_source (~> 0.9.0)
83
- public_suffix (3.0.3)
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)
84
87
  rainbow (3.0.0)
85
- rake (12.3.1)
86
- rb-fsevent (0.10.3)
87
- rb-inotify (0.9.10)
88
- ffi (>= 0.5.0, < 2)
89
- rspec (3.8.0)
90
- rspec-core (~> 3.8.0)
91
- rspec-expectations (~> 3.8.0)
92
- rspec-mocks (~> 3.8.0)
93
- rspec-core (3.8.0)
94
- rspec-support (~> 3.8.0)
95
- rspec-expectations (3.8.1)
88
+ rake (12.3.3)
89
+ rb-fsevent (0.10.4)
90
+ rb-inotify (0.10.1)
91
+ ffi (~> 1.0)
92
+ rchardet (1.8.0)
93
+ regexp_parser (2.0.3)
94
+ rexml (3.2.4)
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)
96
102
  diff-lcs (>= 1.2.0, < 2.0)
97
- rspec-support (~> 3.8.0)
98
- rspec-mocks (3.8.0)
103
+ rspec-support (~> 3.10.0)
104
+ rspec-mocks (3.10.1)
99
105
  diff-lcs (>= 1.2.0, < 2.0)
100
- rspec-support (~> 3.8.0)
101
- rspec-support (3.8.0)
102
- rubocop (0.59.0)
103
- jaro_winkler (~> 1.5.1)
106
+ rspec-support (~> 3.10.0)
107
+ rspec-support (3.10.1)
108
+ rubocop (0.93.1)
104
109
  parallel (~> 1.10)
105
- parser (>= 2.5, != 2.5.1.1)
106
- powerpack (~> 0.1)
110
+ parser (>= 2.7.1.5)
107
111
  rainbow (>= 2.2.2, < 4.0)
112
+ regexp_parser (>= 1.8)
113
+ rexml
114
+ rubocop-ast (>= 0.6.0)
108
115
  ruby-progressbar (~> 1.7)
109
- unicode-display_width (~> 1.0, >= 1.0.1)
110
- ruby-progressbar (1.10.0)
111
- ruby_dep (1.5.0)
112
- sawyer (0.8.1)
113
- addressable (>= 2.3.5, < 2.6)
114
- faraday (~> 0.8, < 1.0)
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)
120
+ sawyer (0.8.2)
121
+ addressable (>= 2.3.5)
122
+ faraday (> 0.8, < 2.0)
115
123
  shellany (0.0.1)
116
124
  terminal-table (1.8.0)
117
125
  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)
126
+ thor (1.1.0)
127
+ unicode-display_width (1.7.0)
128
+ yard (0.9.26)
121
129
 
122
130
  PLATFORMS
123
131
  ruby
124
132
 
125
133
  DEPENDENCIES
126
- bundler (~> 1.16)
134
+ bundler (~> 2.1)
127
135
  danger-swiftformat!
136
+ faraday (= 0.15.4)
128
137
  guard (~> 2.14)
129
138
  guard-rspec (~> 4.7)
130
139
  listen (~> 3.1)
@@ -135,4 +144,4 @@ DEPENDENCIES
135
144
  yard (~> 0.9)
136
145
 
137
146
  BUNDLED WITH
138
- 1.17.2
147
+ 2.2.6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # danger-swiftformat [![Build Status](https://travis-ci.org/garriguv/danger-ruby-swiftformat.svg?branch=master)](https://travis-ci.org/garriguv/danger-ruby-swiftformat) [![Gem Version](https://badge.fury.io/rb/danger-swiftformat.svg)](https://rubygems.org/gems/danger-swiftformat)
1
+ # danger-swiftformat [![Gem Version](https://badge.fury.io/rb/danger-swiftformat.svg)](https://rubygems.org/gems/danger-swiftformat)
2
2
 
3
3
  A [Danger] plugin to check Swift formatting using [SwiftFormat].
4
4
 
@@ -8,7 +8,9 @@ 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
+ ```ruby
12
+ gem 'danger-swiftformat'
13
+ ```
12
14
 
13
15
  [SwiftFormat] also needs to be installed before you run Danger.
14
16
 
@@ -22,6 +24,8 @@ swiftformat.check_format
22
24
 
23
25
  By default, danger-swiftformat will check added and modified files.
24
26
 
27
+ ## Options and parameters
28
+
25
29
  If you want errors to fail Danger, you can use the `fail_on_error` option:
26
30
 
27
31
  ```ruby
@@ -34,12 +38,34 @@ You can specify the `swiftformat` binary using the `binary_path` parameter:
34
38
  swiftformat.binary_path = "/path/to/swiftformat"
35
39
  ```
36
40
 
41
+ You can specify the Swift version of your project using the `swiftversion` parametter:
42
+
43
+ ```ruby
44
+ swiftformat.swiftversion = "5"
45
+ ```
46
+
37
47
  You can specify additional `swiftformat` arguments using the `additional_args` parameter:
38
48
 
39
49
  ```ruby
40
50
  swiftformat.additional_args = "--indent tab --self insert"
41
51
  ```
42
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
+
59
+ By default, `danger-swiftformat` will run on any modified or created file ending in `.swift`. If you'd like to exclude
60
+ certain directories or files such as `Pods`, you can use the `exclude` parameter:
61
+
62
+ ```ruby
63
+ swiftformat.exclude = %w(Pods/** Carthage/** Sources/Nope.swift **/*_autogenerated.swift)
64
+ ```
65
+
66
+ The `exclude` option takes an array of glob patterns; you can find additional documentation on the patterns
67
+ [here](https://ruby-doc.org/core-2.6.3/File.html#method-c-fnmatch).
68
+
43
69
  ## Development
44
70
 
45
71
  1. Clone this repo
@@ -48,6 +74,16 @@ swiftformat.additional_args = "--indent tab --self insert"
48
74
  4. Use `bundle exec guard` to automatically have tests run as you make changes.
49
75
  5. Make your changes.
50
76
 
77
+ ## Releasing a new version
78
+
79
+ Use the release.sh script:
80
+
81
+ ```shell
82
+ ./scripts/release.sh
83
+ ```
84
+
85
+ Then bump the gem to the next patch version.
86
+
51
87
  [Danger]: https://danger.systems/ruby/
52
88
  [SwiftFormat]: https://github.com/nicklockwood/SwiftFormat
53
89
  [danger-swiftlint]: https://github.com/ashfurrow/danger-ruby-swiftlint
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{A danger plugin for checking Swift formatting using SwiftFormat.}
13
13
  spec.homepage = 'https://github.com/garriguv/danger-swiftformat'
14
14
  spec.license = 'MIT'
15
+ spec.metadata = { "github_repo" => "ssh://github.com/garriguv/danger-ruby-swiftformat" }
15
16
 
16
17
  spec.files = `git ls-files`.split($/)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -21,7 +22,7 @@ Gem::Specification.new do |spec|
21
22
  spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
23
 
23
24
  # General ruby development
24
- spec.add_development_dependency 'bundler', '~> 1.16'
25
+ spec.add_development_dependency 'bundler', '~> 2.1'
25
26
  spec.add_development_dependency 'rake', '~> 12.3'
26
27
 
27
28
  # Testing support
@@ -1,3 +1,3 @@
1
1
  module Swiftformat
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.8.1".freeze
3
3
  end
@@ -19,6 +19,21 @@ 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
+
32
+ # The project Swift version
33
+ #
34
+ # @return [String]
35
+ attr_accessor :swiftversion
36
+
22
37
  # Runs swiftformat
23
38
  #
24
39
  # @param [Boolean] fail_on_error
@@ -36,7 +51,7 @@ module Danger
36
51
  return if swift_files.empty?
37
52
 
38
53
  # Run swiftformat
39
- results = swiftformat.check_format(swift_files, additional_args)
54
+ results = swiftformat.check_format(swift_files, additional_args, swiftversion)
40
55
 
41
56
  # Stop processing if the errors array is empty
42
57
  return if results[:errors].empty?
@@ -46,8 +61,13 @@ module Danger
46
61
  message << "| File | Rules |\n"
47
62
  message << "| ---- | ----- |\n"
48
63
  results[:errors].each do |error|
49
- message << "| #{error[:file].gsub(Dir.pwd + '/', '')} | #{error[:rules].join(', ')} |\n"
64
+ message << "| #{error[:file].gsub("#{Dir.pwd}/", '')} | #{error[:rules].join(', ')} |\n"
65
+ end
66
+
67
+ unless additional_message.nil?
68
+ message << "\n" << additional_message
50
69
  end
70
+
51
71
  markdown message
52
72
 
53
73
  if fail_on_error
@@ -59,10 +79,18 @@ module Danger
59
79
  #
60
80
  # @return [Array<String]
61
81
  def find_swift_files
62
- files = (git.modified_files - git.deleted_files) + git.added_files
82
+ renamed_files_hash = git.renamed_files.map { |rename| [rename[:before], rename[:after]] }.to_h
83
+
84
+ post_rename_modified_files = git.modified_files
85
+ .map { |modified_file| renamed_files_hash[modified_file] || modified_file }
86
+
87
+ files = (post_rename_modified_files - git.deleted_files) + git.added_files
88
+
89
+ @exclude = %w() if @exclude.nil?
63
90
 
64
91
  files
65
92
  .select { |file| file.end_with?(".swift") }
93
+ .reject { |file| @exclude.any? { |glob| File.fnmatch(glob, file) } }
66
94
  .uniq
67
95
  .sort
68
96
  end
@@ -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
- cmd << %w(--dryrun --verbose)
16
+
17
+ unless swiftversion.nil? || 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 = /rules applied:(.*)\n.*updated (.*)$/
50
+ ERRORS_REGEX = /(.*:\d+:\d+): ((warning|error):.*)$/.freeze
45
51
 
46
52
  def errors(output)
47
53
  errors = []
@@ -49,20 +55,20 @@ module Danger
49
55
  next if match.count < 2
50
56
 
51
57
  errors << {
52
- file: match[1],
53
- rules: match[0].split(",").map(&:strip)
58
+ file: match[0].sub("#{Dir.pwd}/", ""),
59
+ rules: match[1].split(",").map(&:strip)
54
60
  }
55
61
  end
56
62
  errors
57
63
  end
58
64
 
59
- RUNTIME_REGEX = /.*swiftformat completed.*(.+\..+)s/
65
+ RUNTIME_REGEX = /.*SwiftFormat completed.*(.+\..+)s/.freeze
60
66
 
61
67
  def run_time(output)
62
68
  if RUNTIME_REGEX.match(output)
63
69
  RUNTIME_REGEX.match(output)[1]
64
70
  else
65
- logger = Logger.new(STDERR)
71
+ logger = Logger.new($stderr)
66
72
  logger.error("Invalid run_time output: #{output}")
67
73
  "-1"
68
74
  end
@@ -0,0 +1,16 @@
1
+ #!/bin/bash
2
+
3
+ set -euo pipefail
4
+
5
+ version=$(cat lib/swiftformat/gem_version.rb | grep -o "\d\.\d\.\d")
6
+
7
+ echo "Releasing version ${version}"
8
+
9
+ echo "Releasing to rubygems.org"
10
+ bundle exec rake release
11
+
12
+ echo "Releasing to GitHub Package Registry"
13
+ gem push \
14
+ --key github \
15
+ --host https://rubygems.pkg.github.com/garriguv \
16
+ pkg/danger-swiftformat-${version}.gem
@@ -0,0 +1,8 @@
1
+ import SwiftUI
2
+
3
+ struct MyView: View {
4
+ var body: some View {
5
+ Text("Hello World!")
6
+ .padding()
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ import SwiftUI
2
+ struct MyView: View {
3
+ var body : some View {
4
+ Text( "Hello World!")
5
+ .padding()
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ import SwiftUI
2
+
3
+ struct MyView: View {
4
+ var body: some View {
5
+ Text("Hello World!")
6
+ .padding()
7
+ }
8
+ }
@@ -1,9 +1,4 @@
1
- running swiftformat...
2
- formatting /Users/garriguv/FirstClass.swift
3
- -- no changes
4
- formatting /Users/garriguv/FileWithErrors.swift
5
- -- no changes
6
- formatting /Users/garriguv/OtherFile.swift
7
- -- no changes
8
-
9
- swiftformat completed. 0/3 files would have been updated in 0.08s
1
+ Running SwiftFormat...
2
+ (lint mode - no files will be changed.)
3
+ SwiftFormat completed in 0.01s.
4
+ 0/2 files require formatting.
@@ -1,10 +1,8 @@
1
- running swiftformat...
2
- formatting /Users/garriguv/FirstClass.swift
3
- -- no changes
4
- formatting /Users/garriguv/FileWithErrors.swift
5
- -- rules applied: consecutiveBlankLines, spaceAroundParens, trailingSpace
6
- would have updated /Users/garriguv/FileWithErrors.swift
7
- formatting /Users/garriguv/OtherFile.swift
8
- -- no changes
9
-
10
- swiftformat completed. 1/3 files would have been updated in 0.08s
1
+ Running SwiftFormat...
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.
@@ -1,7 +1,7 @@
1
1
  require "pathname"
2
2
  ROOT = Pathname.new(File.expand_path("..", __dir__))
3
- $:.unshift((ROOT + "lib").to_s)
4
- $:.unshift((ROOT + "spec").to_s)
3
+ $:.unshift("#{ROOT}lib".to_s)
4
+ $:.unshift("#{ROOT}spec".to_s)
5
5
 
6
6
  require "bundler/setup"
7
7
  require "pry"
@@ -39,9 +39,102 @@ module Danger
39
39
  allow(@sut.git).to receive(:added_files).and_return(["Added.swift"])
40
40
  allow(@sut.git).to receive(:modified_files).and_return(["Modified.swift"])
41
41
  allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
42
+ allow(@sut.git).to receive(:renamed_files).and_return([{}])
42
43
  allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
43
44
  allow_any_instance_of(SwiftFormat).to receive(:check_format)
44
- .with(%w(Added.swift Modified.swift), additional_args)
45
+ .with(%w(Added.swift Modified.swift), additional_args, nil)
46
+ .and_return(success_output)
47
+
48
+ @sut.additional_args = additional_args
49
+
50
+ @sut.check_format(fail_on_error: true)
51
+
52
+ status = @sut.status_report
53
+ expect(status[:errors]).to be_empty
54
+ expect(status[:markdowns]).to be_empty
55
+ end
56
+ end
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
+
82
+ context "with additional_message" do
83
+ let(:additional_message) { "I'm the additional message." }
84
+ let(:error_output) { { errors: [{ file: "Modified.swift", rules: %w(firstRule secondRule) }], stats: { run_time: "0.16s" } } }
85
+
86
+ it "should include the additional message in the report" do
87
+ allow(@sut.git).to receive(:added_files).and_return(["Added.swift"])
88
+ allow(@sut.git).to receive(:modified_files).and_return(["Modified.swift"])
89
+ allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
90
+ allow(@sut.git).to receive(:renamed_files).and_return([{}])
91
+ allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
92
+ allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil, nil).and_return(error_output)
93
+ @sut.additional_message = additional_message
94
+ @sut.check_format(fail_on_error: true)
95
+
96
+ status = @sut.status_report
97
+ markdown = status[:markdowns].first.message
98
+ expect(markdown).to include(additional_message)
99
+ end
100
+ end
101
+
102
+ context "with exclude" do
103
+ let(:exclude) { %w(**/Modified.swift Pods/** Carthage/** **/*_autogenerated.swift) }
104
+ let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } }
105
+
106
+ it "should filter the files passed to swiftformat" do
107
+ allow(@sut.git).to receive(:added_files).and_return(%w(Added.swift Pods/Test.swift Carthage/SQLite.swift Sources/Module/JSONParsing_autogenerated.swift))
108
+ allow(@sut.git).to receive(:modified_files).and_return(["Source/Modified.swift"])
109
+ allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
110
+ allow(@sut.git).to receive(:renamed_files).and_return([{}])
111
+ allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
112
+ allow_any_instance_of(SwiftFormat).to receive(:check_format)
113
+ .with(%w(Added.swift), nil, nil)
114
+ .and_return(success_output)
115
+
116
+ @sut.exclude = exclude
117
+
118
+ @sut.check_format(fail_on_error: true)
119
+
120
+ status = @sut.status_report
121
+ expect(status[:errors]).to be_empty
122
+ expect(status[:markdowns]).to be_empty
123
+ end
124
+ end
125
+
126
+ context "with renamed files" do
127
+ let(:additional_args) { "--indent tab --self insert" }
128
+ let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } }
129
+
130
+ it "should use the post-rename filename" do
131
+ allow(@sut.git).to receive(:added_files).and_return(["Added.swift"])
132
+ allow(@sut.git).to receive(:modified_files).and_return(["ModifiedBefore.swift"])
133
+ allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
134
+ allow(@sut.git).to receive(:renamed_files).and_return([{ before: "ModifiedBefore.swift", after: "ModifiedAfter.swift" }])
135
+ allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true)
136
+ allow_any_instance_of(SwiftFormat).to receive(:check_format)
137
+ .with(%w(Added.swift ModifiedAfter.swift), additional_args, nil)
45
138
  .and_return(success_output)
46
139
 
47
140
  @sut.additional_args = additional_args
@@ -64,6 +157,7 @@ module Danger
64
157
  allow(@sut.git).to receive(:added_files).and_return(["Added.m"])
65
158
  allow(@sut.git).to receive(:modified_files).and_return(["Modified.m"])
66
159
  allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.m"])
160
+ allow(@sut.git).to receive(:renamed_files).and_return([{}])
67
161
  end
68
162
 
69
163
  it "should not do anything" do
@@ -81,11 +175,12 @@ module Danger
81
175
  allow(@sut.git).to receive(:added_files).and_return(["Added.swift"])
82
176
  allow(@sut.git).to receive(:modified_files).and_return(["Modified.swift"])
83
177
  allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"])
178
+ allow(@sut.git).to receive(:renamed_files).and_return([{}])
84
179
  end
85
180
 
86
181
  context "when swiftformat does not find any errors" do
87
182
  before do
88
- 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)
89
184
  end
90
185
 
91
186
  it "should not do anything" do
@@ -99,7 +194,7 @@ module Danger
99
194
 
100
195
  context "when swiftformat finds errors" do
101
196
  before do
102
- 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)
103
198
  end
104
199
 
105
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/ --dryrun --verbose))
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 . --dryrun --verbose))
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
- file: "/Users/garriguv/FileWithErrors.swift",
54
- rules: %w(consecutiveBlankLines spaceAroundParens trailingSpace)
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.08"
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 . --dryrun --verbose))
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.08"
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 . --dryrun --verbose))
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,37 +85,37 @@ 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 . --dryrun --verbose))
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.08"
94
+ run_time: "0.01"
96
95
  }
97
96
  }
98
97
 
99
- expect(@sut.check_format(%w(.), nil)).to eq(output)
98
+ expect(@sut.check_format(%w(.), nil, nil)).to eq(output)
100
99
  end
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 --dryrun --verbose))
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.08"
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 --dryrun --verbose))
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.0
4
+ version: 0.8.1
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: 2019-01-04 00:00:00.000000000 Z
11
+ date: 2021-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -173,6 +173,10 @@ files:
173
173
  - lib/swiftformat/gem_version.rb
174
174
  - lib/swiftformat/plugin.rb
175
175
  - lib/swiftformat/swiftformat.rb
176
+ - scripts/release.sh
177
+ - spec/fixtures/0_GoodFile.swift
178
+ - spec/fixtures/1_BadFile.swift
179
+ - spec/fixtures/2_GoodFile.swift
176
180
  - spec/fixtures/swiftformat_output.txt
177
181
  - spec/fixtures/swiftformat_output_bad.txt
178
182
  - spec/fixtures/swiftformat_output_with_errors.txt
@@ -182,8 +186,9 @@ files:
182
186
  homepage: https://github.com/garriguv/danger-swiftformat
183
187
  licenses:
184
188
  - MIT
185
- metadata: {}
186
- post_install_message:
189
+ metadata:
190
+ github_repo: ssh://github.com/garriguv/danger-ruby-swiftformat
191
+ post_install_message:
187
192
  rdoc_options: []
188
193
  require_paths:
189
194
  - lib
@@ -198,11 +203,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
203
  - !ruby/object:Gem::Version
199
204
  version: '0'
200
205
  requirements: []
201
- rubygems_version: 3.0.1
202
- signing_key:
206
+ rubygems_version: 3.1.4
207
+ signing_key:
203
208
  specification_version: 4
204
209
  summary: A danger plugin for checking Swift formatting using SwiftFormat.
205
210
  test_files:
211
+ - spec/fixtures/0_GoodFile.swift
212
+ - spec/fixtures/1_BadFile.swift
213
+ - spec/fixtures/2_GoodFile.swift
206
214
  - spec/fixtures/swiftformat_output.txt
207
215
  - spec/fixtures/swiftformat_output_bad.txt
208
216
  - spec/fixtures/swiftformat_output_with_errors.txt
@@ -1,12 +0,0 @@
1
- language: ruby
2
- cache:
3
- directories:
4
- - bundle
5
-
6
- rvm:
7
- - 2.2.8
8
- - 2.3.5
9
- - 2.4.2
10
-
11
- script:
12
- - bundle exec rake spec