danger-swiftlint 0.11.1 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 801ca7331651b5d31e403630ca6e5a7770da6e49
4
- data.tar.gz: ad870c7c8b02c63f5ce0a51030ccb9eef85b346e
3
+ metadata.gz: 8be68ded24b96b58bdd94c5c100ed819fcea439f
4
+ data.tar.gz: c22a1ac2e4d56c2d19e9aad5ab84146ff3b0824b
5
5
  SHA512:
6
- metadata.gz: 724d304989202a0703445c167377db51e6307261cf9d8939a9aaeac19da08f539b90e8deecdef7f959cb6e009fccbf820972fd7df367fad24f6135a8b78a8a5f
7
- data.tar.gz: 65deb8b5a903315562c330aa156d87ac6a244f1220f6dbaeeb2979012099742b8ea2f99da6fdf7010be64d281344205c430a1e987082723a46b20432728c3269
6
+ metadata.gz: e2e83319fa891bcccf74e4c027cbee79742e56006e484fadbd9e51fdf7c44cf99e666f6867db16cfbf6524089ffb0ac921cef0097e82efd58a6768553a33aa5c
7
+ data.tar.gz: d7e95e8fa0baa9a2550feb75b78e50357a3a4ca144e2fae8b28da9fd2bf2994f2566d78a6b3937e7eb1a66ed08901947467f472e9bbf2e401d3edf82de3245df
data/lib/danger_plugin.rb CHANGED
@@ -49,27 +49,34 @@ module Danger
49
49
  # Fails if swiftlint isn't installed
50
50
  raise 'swiftlint is not installed' unless swiftlint.installed?
51
51
 
52
- config = if config_file
53
- config_file
54
- elsif File.file?('.swiftlint.yml')
55
- File.expand_path('.swiftlint.yml')
56
- end
57
- log "Using config file: #{config}"
52
+ config_file_path = if config_file
53
+ config_file
54
+ elsif File.file?('.swiftlint.yml')
55
+ File.expand_path('.swiftlint.yml')
56
+ end
57
+ log "Using config file: #{config_file_path}"
58
58
 
59
59
  dir_selected = directory ? File.expand_path(directory) : Dir.pwd
60
60
  log "Swiftlint will be run from #{dir_selected}"
61
61
 
62
+ # Get config
63
+ config = load_config(config_file_path)
64
+
62
65
  # Extract excluded paths
63
- excluded_paths = excluded_files_from_config(config)
66
+ excluded_paths = format_paths(config['excluded'] || [], config_file_path)
67
+
68
+ # Extract included paths
69
+ included_paths = format_paths(config['included'] || [], config_file_path)
64
70
 
65
71
  # Extract swift files (ignoring excluded ones)
66
- files = find_swift_files(dir_selected, files, excluded_paths)
72
+ files = find_swift_files(dir_selected, files, excluded_paths, included_paths)
73
+ log files
67
74
  log "Swiftlint will lint the following files: #{files.join(', ')}"
68
75
 
69
76
  # Prepare swiftlint options
70
77
  options = {
71
78
  # Make sure we don't fail when config path has spaces
72
- config: config ? Shellwords.escape(config) : nil,
79
+ config: config_file_path ? Shellwords.escape(config_file_path) : nil,
73
80
  reporter: 'json',
74
81
  quiet: true,
75
82
  pwd: dir_selected
@@ -125,7 +132,7 @@ module Danger
125
132
  # If files are not provided it will use git modifield and added files
126
133
  #
127
134
  # @return [Array] swift files
128
- def find_swift_files(dir_selected, files = nil, excluded_paths = [])
135
+ def find_swift_files(dir_selected, files = nil, excluded_paths = [], included_paths = [])
129
136
  # Needs to be escaped before comparsion with escaped file paths
130
137
  dir_selected = Shellwords.escape(dir_selected)
131
138
 
@@ -146,29 +153,36 @@ module Danger
146
153
  # Ensure only files in the selected directory
147
154
  select { |file| file.start_with?(dir_selected) }.
148
155
  # Reject files excluded on configuration
149
- reject do |file|
150
- excluded_paths.any? do |excluded_path|
151
- Find.find(excluded_path)
152
- .map { |excluded_file| Shellwords.escape(excluded_file) }
153
- .include?(file)
154
- end
156
+ reject { |file| file_exists?(excluded_paths, file) }.
157
+ # Accept files included on configuration
158
+ select do |file|
159
+ next true if included_paths.empty?
160
+ file_exists?(included_paths, file)
155
161
  end
156
162
  end
157
163
 
158
- # Parses the configuration file and return the excluded files
159
- #
160
- # @return [Array] list of files excluded
161
- def excluded_files_from_config(filepath)
162
- config = if filepath
163
- YAML.load_file(filepath)
164
- else
165
- { 'excluded' => [] }
166
- end
164
+ # Get the configuration file
165
+ def load_config(filepath)
166
+ filepath ? YAML.load_file(filepath) : {}
167
+ end
167
168
 
168
- excluded_paths = config['excluded'] || []
169
+ # Return whether the file exists within a specified collection of paths
170
+ #
171
+ # @return [Bool] file exists within specified collection of paths
172
+ def file_exists?(paths, file)
173
+ paths.any? do |path|
174
+ Find.find(path)
175
+ .map { |path_file| Shellwords.escape(path_file) }
176
+ .include?(file)
177
+ end
178
+ end
169
179
 
170
- # Extract excluded paths
171
- excluded_paths
180
+ # Parses the configuration file and return the specified files in path
181
+ #
182
+ # @return [Array] list of files specified in path
183
+ def format_paths(paths, filepath)
184
+ # Extract included paths
185
+ paths
172
186
  .map { |path| File.join(File.dirname(filepath), path) }
173
187
  .map { |path| File.expand_path(path) }
174
188
  .select { |path| File.exist?(path) || Dir.exist?(path) }
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DangerSwiftlint
4
- VERSION = '0.11.1'
4
+ VERSION = '0.12.0'
5
5
  SWIFTLINT_VERSION = '0.20.1'
6
6
  end
@@ -169,6 +169,22 @@ module Danger
169
169
  @swiftlint.lint_files
170
170
  end
171
171
 
172
+ it 'lints files in the included paths' do
173
+ allow(@swiftlint.git).to receive(:added_files).and_return([])
174
+ allow(@swiftlint.git).to receive(:modified_files).and_return([
175
+ 'spec/fixtures/SwiftFile.swift',
176
+ 'spec/fixtures/some_dir/SwiftFile.swift'
177
+ ])
178
+
179
+ expect_any_instance_of(Swiftlint).to receive(:lint)
180
+ .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
181
+ .once
182
+ .and_return(@swiftlint_response)
183
+
184
+ @swiftlint.config_file = 'spec/fixtures/another_config.yml'
185
+ @swiftlint.lint_files
186
+ end
187
+
172
188
  it 'does not crash when excluded is nil' do
173
189
  allow(@swiftlint.git).to receive(:added_files).and_return([])
174
190
  allow(@swiftlint.git).to receive(:modified_files).and_return([
@@ -184,6 +200,21 @@ module Danger
184
200
  @swiftlint.lint_files
185
201
  end
186
202
 
203
+ it 'does not crash when included is nil' do
204
+ allow(@swiftlint.git).to receive(:added_files).and_return([])
205
+ allow(@swiftlint.git).to receive(:modified_files).and_return([
206
+ 'spec/fixtures/SwiftFile.swift'
207
+ ])
208
+
209
+ expect_any_instance_of(Swiftlint).to receive(:lint)
210
+ .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
211
+ .once
212
+ .and_return(@swiftlint_response)
213
+
214
+ @swiftlint.config_file = 'spec/fixtures/empty_included.yml'
215
+ @swiftlint.lint_files
216
+ end
217
+
187
218
  it 'default config is nil, unspecified' do
188
219
  allow(@swiftlint.git).to receive(:added_files).and_return([])
189
220
  allow(@swiftlint.git).to receive(:modified_files).and_return([
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-swiftlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash Furrow
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-12-05 00:00:00.000000000 Z
15
+ date: 2018-01-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: danger
@@ -161,7 +161,7 @@ files:
161
161
  - spec/danger_plugin_spec.rb
162
162
  - spec/spec_helper.rb
163
163
  - spec/swiftlint_spec.rb
164
- homepage: https://github.com/ashfurrow/danger-swiftlint
164
+ homepage: https://github.com/ashfurrow/danger-ruby-swiftlint
165
165
  licenses:
166
166
  - MIT
167
167
  metadata: {}