danger-swiftlint 0.20.0 → 0.20.1
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 +4 -4
- data/lib/danger_plugin.rb +18 -6
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +63 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d3f63d751dffc66d02244fe0312606f209cf92f6741e5b4f269e3ded5786a5
|
4
|
+
data.tar.gz: 5c4ffed861fc7de303abd515c45c4897f8d65456e603bc8f00a02ec1a4fd4ec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da2ad63e66231b7468d89b7cb68f1e0bb24a17d83d0b1b02318d2b546b9d7c70f3c2be9fa351dde769444f211f2be46c84c49dbe1958c83499c2a31b4297c822
|
7
|
+
data.tar.gz: cb093d04e518bbb499240bb99abb0ce42cafa55fa6984769adddda3360c7c97239f818469d6095b01816e1f1df49cb2c15bce4da392d43c0963e653e0d9e439a
|
data/lib/danger_plugin.rb
CHANGED
@@ -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
|
125
|
-
|
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
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -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.
|
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-
|
15
|
+
date: 2019-03-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: danger
|