danger-swiftlint 0.20.1 → 0.21.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
  SHA256:
3
- metadata.gz: 26d3f63d751dffc66d02244fe0312606f209cf92f6741e5b4f269e3ded5786a5
4
- data.tar.gz: 5c4ffed861fc7de303abd515c45c4897f8d65456e603bc8f00a02ec1a4fd4ec9
3
+ metadata.gz: 4c683ebc4b9a3a612c68eee9889d766458b4e1a4517b7f2022d3107175adad46
4
+ data.tar.gz: dacd9783690561139fb4f4fd5ce1d100dbb82e49c881a64e5c454962abee046e
5
5
  SHA512:
6
- metadata.gz: da2ad63e66231b7468d89b7cb68f1e0bb24a17d83d0b1b02318d2b546b9d7c70f3c2be9fa351dde769444f211f2be46c84c49dbe1958c83499c2a31b4297c822
7
- data.tar.gz: cb093d04e518bbb499240bb99abb0ce42cafa55fa6984769adddda3360c7c97239f818469d6095b01816e1f1df49cb2c15bce4da392d43c0963e653e0d9e439a
6
+ metadata.gz: 72a01b3969c23207a994a932d0829fc9f1954c5dc37a1686e44d9496ee885cc15be1cfa4fafbbe42a6b08507c638f6055043455692d03af2c54fcd559e417c7c
7
+ data.tar.gz: d4e0b33363e8cced89e749e954e59d1ad3afb5e20fd788677436b1bebeb9ba7404f4db7cbd54647068bbf0579a02fbe6ccec9b1995ab791065f195b14063f245
@@ -46,6 +46,9 @@ module Danger
46
46
 
47
47
  # Errors found
48
48
  attr_accessor :errors
49
+
50
+ # All issues found
51
+ attr_accessor :issues
49
52
 
50
53
  # Lints Swift files. Will fail if `swiftlint` cannot be installed correctly.
51
54
  # Generates a `markdown` list of warnings for the prose in a corpus of
@@ -57,7 +60,7 @@ module Danger
57
60
  # if nil, modified and added files from the diff will be used.
58
61
  # @return [void]
59
62
  #
60
- def lint_files(files = nil, inline_mode: false, fail_on_error: false, additional_swiftlint_args: '', &select_block)
63
+ def lint_files(files = nil, inline_mode: false, fail_on_error: false, additional_swiftlint_args: '', no_comment: false, &select_block)
61
64
  # Fails if swiftlint isn't installed
62
65
  raise 'swiftlint is not installed' unless swiftlint.installed?
63
66
 
@@ -101,21 +104,25 @@ module Danger
101
104
 
102
105
  # Lint each file and collect the results
103
106
  issues = run_swiftlint(files, lint_all_files, options, additional_swiftlint_args)
107
+ @issues = issues
104
108
  other_issues_count = 0
105
- unless @max_num_violations.nil?
109
+ unless @max_num_violations.nil? || no_comment
106
110
  other_issues_count = issues.count - @max_num_violations if issues.count > @max_num_violations
107
111
  issues = issues.take(@max_num_violations)
108
112
  end
109
113
  log "Received from Swiftlint: #{issues}"
110
114
 
111
115
  # filter out any unwanted violations with the passed in select_block
112
- if select_block
113
- issues.select! { |issue| select_block.call(issue) }
116
+ if select_block && !no_comment
117
+ issues = issues.select { |issue| select_block.call(issue) }
114
118
  end
115
119
 
116
120
  # Filter warnings and errors
117
121
  @warnings = issues.select { |issue| issue['severity'] == 'Warning' }
118
122
  @errors = issues.select { |issue| issue['severity'] == 'Error' }
123
+
124
+ # Early exit so we don't comment
125
+ return if no_comment
119
126
 
120
127
  if inline_mode
121
128
  # Report with inline comment
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DangerSwiftlint
4
- VERSION = '0.20.1'
4
+ VERSION = '0.21.0'
5
5
  SWIFTLINT_VERSION = '0.31.0'
6
6
  end
@@ -410,6 +410,58 @@ module Danger
410
410
  end
411
411
  end
412
412
  end
413
+
414
+ context 'when no_comment is enabled' do
415
+
416
+ it 'does not create comments' do
417
+ allow_any_instance_of(Swiftlint).to receive(:lint)
418
+ .with(hash_including(pwd: File.expand_path('.')), '')
419
+ .and_return(@swiftlint_multiviolation_response)
420
+
421
+ @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], inline_mode: true, no_comment: true)
422
+ status = @swiftlint.status_report
423
+ expect(status[:warnings]).to eql([])
424
+ expect(status[:errors]).to eql([])
425
+ expect(status[:markdown]).to be_nil
426
+ end
427
+
428
+ it 'does not filter with max_violations' do
429
+ allow_any_instance_of(Swiftlint).to receive(:lint)
430
+ .with(hash_including(pwd: File.expand_path('.')), '')
431
+ .and_return(@swiftlint_multiviolation_response)
432
+
433
+ @swiftlint.max_num_violations = 1
434
+ @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], no_comment: true)
435
+ issues = @swiftlint.issues
436
+ expect(issues.length).to eql(2)
437
+ end
438
+
439
+ it 'does not filter with select_block' do
440
+ allow_any_instance_of(Swiftlint).to receive(:lint)
441
+ .with(hash_including(pwd: File.expand_path('.')), '')
442
+ .and_return(@swiftlint_multiviolation_response)
443
+
444
+ @swiftlint.max_num_violations = 1
445
+ @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], no_comment: true) { |v|
446
+ false
447
+ }
448
+ issues = @swiftlint.issues
449
+ expect(issues.length).to eql(2)
450
+ end
451
+
452
+ it 'correctly sets issues, warnings, and errors accessors' do
453
+ allow_any_instance_of(Swiftlint).to receive(:lint)
454
+ .with(hash_including(pwd: File.expand_path('.')), '')
455
+ .and_return(@swiftlint_multiviolation_response)
456
+
457
+ @swiftlint.lint_files(['spec/fixtures/some\ dir/SwiftFile.swift'], no_comment: true)
458
+ issues = @swiftlint.issues
459
+ warnings = @swiftlint.warnings
460
+ errors = @swiftlint.errors
461
+ expect(issues.length).to eql(warnings.length + errors.length)
462
+ end
463
+ end
464
+
413
465
 
414
466
  it 'parses environment variables set within the swiftlint config' do
415
467
  ENV['ENVIRONMENT_EXAMPLE'] = 'excluded_dir'
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.1
4
+ version: 0.21.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: 2019-03-25 00:00:00.000000000 Z
15
+ date: 2019-05-02 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.7.8
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: A Danger plugin for linting Swift with SwiftLint.