danger-swiftlint 0.15.0 → 0.16.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
- SHA256:
3
- metadata.gz: 01a0939fa22887ccd7c5fb12e95137480358a86b29fa5172013fcab5c4a641e8
4
- data.tar.gz: fd0159f18351b1024d8a0375da700490a1fb65bf854b1afc43d9353129050ba6
2
+ SHA1:
3
+ metadata.gz: ffd9d0b59c7ecad82f6881f19861fcd96b0516a1
4
+ data.tar.gz: fde0df1341996eb7ed3336f27e19130502397ad9
5
5
  SHA512:
6
- metadata.gz: d4ab4971ad7ce9ec8534f1640e6fb6d0ab9ab5ebc150fb3978bf0f2090969ea51af28982d920fb791a579a19ab8a938ce4bea2971b3183473ff30ac00ff5b01e
7
- data.tar.gz: 2d2dda5c3ce69edc438d2054a52ecbb13dd0479dcc116c1c4981393328f2134d69c27790160ac2f5a16e5c67b12739aa311fae403cb7db6793eaca87ff7b884f
6
+ metadata.gz: aab7ab1a826a81b8b71d1bba2a982c35b12a1e5b03521bc190592386faeecf8c0c3605ce6eeb00f4a1b523847d769c0354673b946b0299c98bad4f2f61030ba6
7
+ data.tar.gz: e5f9f91d254bf2a73e59a366bd63a2e1e8c83798d4d2d82f83f14d8d2cbd1b310c3b3a592a208dd6b5090f6b5aca9adb455b7040571b501bbc5e440569daad68
data/lib/danger_plugin.rb CHANGED
@@ -65,12 +65,15 @@ module Danger
65
65
  # Extract excluded paths
66
66
  excluded_paths = format_paths(config['excluded'] || [], config_file_path)
67
67
 
68
+ log "Swiftlint will exclude the following paths: #{excluded_paths}"
69
+
68
70
  # Extract included paths
69
71
  included_paths = format_paths(config['included'] || [], config_file_path)
70
72
 
73
+ log "Swiftlint includes the following paths: #{included_paths}"
74
+
71
75
  # Extract swift files (ignoring excluded ones)
72
76
  files = find_swift_files(dir_selected, files, excluded_paths, included_paths)
73
- log files
74
77
  log "Swiftlint will lint the following files: #{files.join(', ')}"
75
78
 
76
79
  # Prepare swiftlint options
@@ -163,7 +166,24 @@ module Danger
163
166
 
164
167
  # Get the configuration file
165
168
  def load_config(filepath)
166
- filepath ? YAML.load_file(filepath) : {}
169
+ return {} if filepath.nil? || !File.exist?(filepath)
170
+
171
+ config_file = File.open(filepath).read
172
+
173
+ # Replace environment variables
174
+ config_file = parse_environment_variables(config_file)
175
+
176
+ YAML.safe_load(config_file)
177
+ end
178
+
179
+ # Find all requested environment variables in the given string and replace them with the correct values.
180
+ def parse_environment_variables(file_contents)
181
+ # Matches the file contents for environment variables defined like ${VAR_NAME}.
182
+ # Replaces them with the environment variable value if it exists.
183
+ file_contents.gsub(/\$\{([^{}]+)\}/) do |env_var|
184
+ return env_var if ENV[Regexp.last_match[1]].nil?
185
+ ENV[Regexp.last_match[1]]
186
+ end
167
187
  end
168
188
 
169
189
  # Return whether the file exists within a specified collection of paths
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DangerSwiftlint
4
- VERSION = '0.15.0'
4
+ VERSION = '0.16.0'
5
5
  SWIFTLINT_VERSION = '0.25.0'
6
6
  end
@@ -44,6 +44,10 @@ module Danger
44
44
  @swiftlint_response = '[{ "rule_id" : "force_cast", "reason" : "Force casts should be avoided.", "character" : 19, "file" : "/Users/me/this_repo/spec//fixtures/SwiftFile.swift", "severity" : "Error", "type" : "Force Cast", "line" : 13 }]'
45
45
  end
46
46
 
47
+ after(:each) do
48
+ ENV['ENVIRONMENT_EXAMPLE'] = nil
49
+ end
50
+
47
51
  it 'accept files as arguments' do
48
52
  expect_any_instance_of(Swiftlint).to receive(:lint)
49
53
  .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
@@ -235,7 +239,9 @@ module Danger
235
239
  'spec/fixtures/SwiftFile.swift'
236
240
  ])
237
241
  expect(File).to receive(:file?).and_return(true)
238
- expect(YAML).to receive(:load_file).and_return({})
242
+ expect(File).to receive(:exist?).and_return(true)
243
+ expect(File).to receive(:open).and_return(StringIO.new)
244
+ expect(YAML).to receive(:safe_load).and_return({})
239
245
 
240
246
  expect_any_instance_of(Swiftlint).to receive(:lint)
241
247
  .with(hash_including(config: File.expand_path('.swiftlint.yml')), '')
@@ -316,6 +322,25 @@ module Danger
316
322
  expect(status[:warnings]).to_not be_empty
317
323
  expect(status[:errors]).to be_empty
318
324
  end
325
+
326
+ it 'parses environment variables set within the swiftlint config' do
327
+ ENV['ENVIRONMENT_EXAMPLE'] = 'excluded_dir'
328
+
329
+ allow(@swiftlint.git).to receive(:added_files).and_return([])
330
+ allow(@swiftlint.git).to receive(:modified_files).and_return([
331
+ 'spec/fixtures/SwiftFile.swift',
332
+ 'spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift',
333
+ 'spec/fixtures/excluded_dir/SwiftFile WithEscaped+CharactersThatShouldNotBeIncluded.swift'
334
+ ])
335
+
336
+ expect_any_instance_of(Swiftlint).to receive(:lint)
337
+ .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
338
+ .once
339
+ .and_return(@swiftlint_response)
340
+
341
+ @swiftlint.config_file = 'spec/fixtures/environment_variable_config.yml'
342
+ @swiftlint.lint_files
343
+ end
319
344
  end
320
345
  end
321
346
  end
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.15.0
4
+ version: 0.16.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: 2018-03-26 00:00:00.000000000 Z
15
+ date: 2018-03-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: danger
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubyforge_project:
184
- rubygems_version: 2.7.6
184
+ rubygems_version: 2.6.10
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: A Danger plugin for linting Swift with SwiftLint.