danger-swiftlint 0.20.0 → 0.20.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: 8a64dedaa81fb282247ffe2cbc5e13f5dc6f3d5e9ce9ab61e897d005aca35102
4
- data.tar.gz: 3eeaafa30861ae658cbeee4201f24460046a2a7d0d150e847318ff4919f5679e
3
+ metadata.gz: 26d3f63d751dffc66d02244fe0312606f209cf92f6741e5b4f269e3ded5786a5
4
+ data.tar.gz: 5c4ffed861fc7de303abd515c45c4897f8d65456e603bc8f00a02ec1a4fd4ec9
5
5
  SHA512:
6
- metadata.gz: 5f6b2f29d79a17c03762310ead3ed2d4ab70d8cd68684d98711fb2d256737495e9ff4309f47469cab5edf8a1d6950bb8a188cd770c53c9aa4a8261dd20df22ad
7
- data.tar.gz: 9b6c2fbc47d8d75e637d2e205d644c36831237731ee6d3b4291811786039157584cf61dab01bda6d94a40a463fe2766a409b5eb38bfaab5801fa6da7b8f9bf3f
6
+ metadata.gz: da2ad63e66231b7468d89b7cb68f1e0bb24a17d83d0b1b02318d2b546b9d7c70f3c2be9fa351dde769444f211f2be46c84c49dbe1958c83499c2a31b4297c822
7
+ data.tar.gz: cb093d04e518bbb499240bb99abb0ce42cafa55fa6984769adddda3360c7c97239f818469d6095b01816e1f1df49cb2c15bce4da392d43c0963e653e0d9e439a
@@ -38,6 +38,15 @@ module Danger
38
38
  # Whether all files should be linted in one pass
39
39
  attr_accessor :lint_all_files
40
40
 
41
+ # Whether we should fail on warnings
42
+ attr_accessor :strict
43
+
44
+ # Warnings found
45
+ attr_accessor :warnings
46
+
47
+ # Errors found
48
+ attr_accessor :errors
49
+
41
50
  # Lints Swift files. Will fail if `swiftlint` cannot be installed correctly.
42
51
  # Generates a `markdown` list of warnings for the prose in a corpus of
43
52
  # .markdown and .md files.
@@ -105,13 +114,13 @@ module Danger
105
114
  end
106
115
 
107
116
  # Filter warnings and errors
108
- warnings = issues.select { |issue| issue['severity'] == 'Warning' }
109
- errors = issues.select { |issue| issue['severity'] == 'Error' }
117
+ @warnings = issues.select { |issue| issue['severity'] == 'Warning' }
118
+ @errors = issues.select { |issue| issue['severity'] == 'Error' }
110
119
 
111
120
  if inline_mode
112
121
  # Report with inline comment
113
- send_inline_comment(warnings, :warn)
114
- send_inline_comment(errors, fail_on_error ? :fail : :warn)
122
+ send_inline_comment(warnings, strict ? :fail : :warn)
123
+ send_inline_comment(errors, (fail_on_error || strict) ? :fail : :warn)
115
124
  warn other_issues_message(other_issues_count) if other_issues_count > 0
116
125
  elsif warnings.count > 0 || errors.count > 0
117
126
  # Report if any warning or error
@@ -121,8 +130,11 @@ module Danger
121
130
  message << "\n#{other_issues_message(other_issues_count)}" if other_issues_count > 0
122
131
  markdown message
123
132
 
124
- # Fail Danger on errors
125
- if fail_on_error && errors.count > 0
133
+ # Fail danger on errors
134
+ should_fail_by_errors = fail_on_error && errors.count > 0
135
+ # Fail danger if any warnings or errors and we are strict
136
+ should_fail_by_strict = strict && (errors.count > 0 || warnings.count > 0)
137
+ if should_fail_by_errors || should_fail_by_strict
126
138
  fail 'Failed due to SwiftLint errors'
127
139
  end
128
140
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DangerSwiftlint
4
- VERSION = '0.20.0'
4
+ VERSION = '0.20.1'
5
5
  SWIFTLINT_VERSION = '0.31.0'
6
6
  end
@@ -348,6 +348,69 @@ module Danger
348
348
  expect(status[:errors]).to be_empty
349
349
  end
350
350
 
351
+ context '#strict' do
352
+ before(:each) do
353
+ allow_any_instance_of(Swiftlint).to receive(:lint)
354
+ .with(hash_including(path: File.expand_path('spec/fixtures/SwiftFile.swift')), '')
355
+ .and_return(swiftlint_response)
356
+ end
357
+
358
+ context 'when not strict' do
359
+ # Response without any errors and a single warning
360
+ let(:swiftlint_response) { '[{ "rule_id" : "force_cast", "reason" : "Force casts should be avoided.", "character" : 19, "file" : "/Users/me/this_repo/spec//fixtures/SwiftFile.swift", "severity" : "Warning", "type" : "Force Cast", "line" : 13 }]' }
361
+
362
+ it 'does not fail on warnings if inline' do
363
+ @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: true, fail_on_error: false, additional_swiftlint_args: '')
364
+
365
+ expect(@swiftlint.failed?).to_not be true
366
+ end
367
+
368
+ it 'does not fail on warnings if not inline' do
369
+ @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: false, fail_on_error: false, additional_swiftlint_args: '')
370
+
371
+ expect(@swiftlint.failed?).to_not be true
372
+ end
373
+ end
374
+
375
+ context 'when strict is enabled' do
376
+ # Response without any errors and a single warning
377
+ let(:swiftlint_response) { '[{ "rule_id" : "force_cast", "reason" : "Force casts should be avoided.", "character" : 19, "file" : "/Users/me/this_repo/spec//fixtures/SwiftFile.swift", "severity" : "Warning", "type" : "Force Cast", "line" : 13 }]' }
378
+
379
+ before(:each) do
380
+ @swiftlint.strict = true
381
+ end
382
+
383
+ it 'fails on warnings if inline' do
384
+ @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: true, fail_on_error: false, additional_swiftlint_args: '')
385
+
386
+ expect(@swiftlint.failed?).to be true
387
+ end
388
+
389
+ it 'fails on warnings if not inline' do
390
+ @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: false, fail_on_error: false, additional_swiftlint_args: '')
391
+
392
+ expect(@swiftlint.failed?).to be true
393
+ end
394
+
395
+ context 'with errors' do
396
+ # Response with an error
397
+ let(:swiftlint_response) { @swiftlint_response }
398
+
399
+ it 'fails if inline' do
400
+ @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: true, fail_on_error: false, additional_swiftlint_args: '')
401
+
402
+ expect(@swiftlint.failed?).to be true
403
+ end
404
+
405
+ it 'fails if not inline' do
406
+ @swiftlint.lint_files('spec/fixtures/*.swift', inline_mode: false, fail_on_error: false, additional_swiftlint_args: '')
407
+
408
+ expect(@swiftlint.failed?).to be true
409
+ end
410
+ end
411
+ end
412
+ end
413
+
351
414
  it 'parses environment variables set within the swiftlint config' do
352
415
  ENV['ENVIRONMENT_EXAMPLE'] = 'excluded_dir'
353
416
 
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.20.0
4
+ version: 0.20.1
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: 2019-03-19 00:00:00.000000000 Z
15
+ date: 2019-03-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: danger