danger-swiftlint 0.1.2 → 0.2.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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -13
- data/lib/danger_plugin.rb +5 -12
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +13 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6c93186c9141189a2be976b2728381f983bc5e
|
4
|
+
data.tar.gz: d100191c3a3ab38801ec23ba87f79294e4a7d26b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4469183c1e4b05686ae048cbeda886eaa25e96bb9197e12473bb63a1a1cd6e228245503dcc66266fae698641f8fb4dd62c21f4de1334d888a803804848de24e
|
7
|
+
data.tar.gz: 467441b08eef27d8415ecaa4302412a087c93848cf298c17afa2624375bfdaa6de59534d56438d9798924c21fec195280fc3e98cdada21723f190760c0b4b921
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-swiftlint (0.1.
|
4
|
+
danger-swiftlint (0.1.2)
|
5
5
|
danger
|
6
6
|
|
7
7
|
GEM
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
colored (1.2)
|
15
15
|
cork (0.1.0)
|
16
16
|
colored (~> 1.2)
|
17
|
-
danger (0.8.
|
17
|
+
danger (0.8.5)
|
18
18
|
claide (~> 1.0)
|
19
19
|
colored (~> 1.2)
|
20
20
|
cork (~> 0.1)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Danger SwiftLint
|
4
4
|
|
5
|
-
A [Danger](https://github.com/danger/danger) plugin for [SwiftLint](https://github.com/realm/SwiftLint).
|
5
|
+
A [Danger](https://github.com/danger/danger) plugin for [SwiftLint](https://github.com/realm/SwiftLint) that runs on macOS.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -20,24 +20,13 @@ The easiest way to use is just add this to your Dangerfile:
|
|
20
20
|
swiftlint.lint_files
|
21
21
|
```
|
22
22
|
|
23
|
-
That
|
23
|
+
That's going to lint all your Swift files. It would be better to only lint the changed or added ones, which is complicated due. Check out [this issue](https://github.com/ashfurrow/danger-swiftlint/issues/16) for more details.
|
24
24
|
|
25
25
|
```rb
|
26
26
|
swiftlint.config_file = '.swiftlint.yml'
|
27
27
|
swiftlint.lint_files
|
28
28
|
```
|
29
29
|
|
30
|
-
And finally, you can provide a list of files manually:
|
31
|
-
|
32
|
-
``` ruby
|
33
|
-
# Look through all changed Swift files
|
34
|
-
swift_files = (modified_files + added_files).select do |file|
|
35
|
-
file.end_with?(".swift")
|
36
|
-
end
|
37
|
-
|
38
|
-
swiftlint.lint_files swift_files
|
39
|
-
```
|
40
|
-
|
41
30
|
## Attribution
|
42
31
|
|
43
32
|
Original structure, sequence, and organization of repo taken from [danger-prose](https://github.com/dbgrandi/danger-prose) by [David Grandinetti](https://github.com/dbgrandi/).
|
data/lib/danger_plugin.rb
CHANGED
@@ -26,7 +26,7 @@ module Danger
|
|
26
26
|
# if nil, modified and added files from the diff will be used.
|
27
27
|
# @return [void]
|
28
28
|
#
|
29
|
-
def lint_files
|
29
|
+
def lint_files
|
30
30
|
# Installs SwiftLint if needed
|
31
31
|
system "brew install swiftlint" unless swiftlint_installed?
|
32
32
|
|
@@ -36,21 +36,14 @@ module Danger
|
|
36
36
|
return
|
37
37
|
end
|
38
38
|
|
39
|
-
# Either use files provided, or use the modified + added
|
40
|
-
swift_files = files ? Dir.glob(files) : (modified_files + added_files)
|
41
|
-
swift_files.select! do |line| line.end_with?(".swift") end
|
42
|
-
|
43
|
-
# Make sure we don't fail when paths have spaces
|
44
|
-
swift_files = swift_files.map { |file| "\"#{file}\"" }
|
45
|
-
|
46
39
|
swiftlint_command = "swiftlint lint --quiet --reporter json"
|
47
40
|
swiftlint_command += " --config #{config_file}" if config_file
|
48
41
|
|
49
42
|
require 'json'
|
50
|
-
result_json =
|
43
|
+
result_json = JSON.parse(`#{swiftlint_command}`).flatten
|
51
44
|
|
52
45
|
# Convert to swiftlint results
|
53
|
-
warnings = result_json.
|
46
|
+
warnings = result_json.select do |results|
|
54
47
|
results['severity'] == 'Warning'
|
55
48
|
end
|
56
49
|
errors = result_json.select do |results|
|
@@ -61,13 +54,13 @@ module Danger
|
|
61
54
|
|
62
55
|
# We got some error reports back from swiftlint
|
63
56
|
if warnings.count > 0 || errors.count > 0
|
64
|
-
message =
|
57
|
+
message = "### SwiftLint found issues\n\n"
|
65
58
|
end
|
66
59
|
|
67
60
|
message << parse_results(warnings, 'Warnings') unless warnings.empty?
|
68
61
|
message << parse_results(errors, 'Errors') unless errors.empty?
|
69
62
|
|
70
|
-
markdown message
|
63
|
+
markdown message unless message.empty?
|
71
64
|
end
|
72
65
|
|
73
66
|
# Parses swiftlint invocation results into a string
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -24,6 +24,14 @@ module Danger
|
|
24
24
|
expect(@swiftlint.swiftlint_installed?).to be_truthy
|
25
25
|
end
|
26
26
|
|
27
|
+
it 'does not markdown an empty message' do
|
28
|
+
allow(@swiftlint).to receive(:`)
|
29
|
+
.with('swiftlint lint --quiet --reporter json')
|
30
|
+
.and_return('[]')
|
31
|
+
|
32
|
+
expect(@swiftlint.status_report[:markdowns].first).to be_nil
|
33
|
+
end
|
34
|
+
|
27
35
|
describe :lint_files do
|
28
36
|
before do
|
29
37
|
# So it doesn't try to install on your computer
|
@@ -34,10 +42,10 @@ module Danger
|
|
34
42
|
end
|
35
43
|
|
36
44
|
it 'handles a known SwiftLint report' do
|
37
|
-
allow(@swiftlint).to receive(:`).with('swiftlint lint --quiet --reporter json
|
45
|
+
allow(@swiftlint).to receive(:`).with('swiftlint lint --quiet --reporter json').and_return(@swiftlint_response)
|
38
46
|
|
39
47
|
# Do it
|
40
|
-
@swiftlint.lint_files
|
48
|
+
@swiftlint.lint_files
|
41
49
|
|
42
50
|
output = @swiftlint.status_report[:markdowns].first
|
43
51
|
|
@@ -50,9 +58,7 @@ module Danger
|
|
50
58
|
end
|
51
59
|
|
52
60
|
it 'handles no files' do
|
53
|
-
allow(@swiftlint).to receive(
|
54
|
-
allow(@swiftlint).to receive(:added_files).and_return([])
|
55
|
-
allow(@swiftlint).to receive(:`).with('swiftlint lint --quiet --reporter json --path "spec/fixtures/SwiftFile.swift"').and_return(@swiftlint_response)
|
61
|
+
allow(@swiftlint).to receive(:`).with('swiftlint lint --quiet --reporter json').and_return(@swiftlint_response)
|
56
62
|
|
57
63
|
@swiftlint.lint_files
|
58
64
|
|
@@ -61,9 +67,9 @@ module Danger
|
|
61
67
|
|
62
68
|
it 'uses a config file' do
|
63
69
|
@swiftlint.config_file = 'some_config.yml'
|
64
|
-
allow(@swiftlint).to receive(:`).with('swiftlint lint --quiet --reporter json --config some_config.yml
|
70
|
+
allow(@swiftlint).to receive(:`).with('swiftlint lint --quiet --reporter json --config some_config.yml').and_return(@swiftlint_response)
|
65
71
|
|
66
|
-
@swiftlint.lint_files
|
72
|
+
@swiftlint.lint_files
|
67
73
|
|
68
74
|
expect(@swiftlint.status_report[:markdowns].first).to_not be_empty
|
69
75
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ash Furrow
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-07-
|
13
|
+
date: 2016-07-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: danger
|