danger-swiftlint 0.2.1 → 0.3.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/Changelog.md +4 -0
- data/Gemfile.lock +30 -16
- data/README.md +2 -0
- data/lib/danger_plugin.rb +76 -27
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +85 -16
- data/spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift +1 -0
- data/spec/fixtures/some_config.yml +8 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ab53ea91e7386c252bd97c2ed1eb870cc15cd49
|
4
|
+
data.tar.gz: 0005c7f2952722f6900127a316a2a92c57ba7aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07b86f7d1fcb2a48a328d79f97f22d7a8abbf20e3026b7c51704f20f8c6eddb978dea223bfbca99dbccb881deb2e829a16c3b5219ea2e9fd5f4050306c8c8ddf
|
7
|
+
data.tar.gz: 1ff32813a484950a474c56e0ba786842c6e9e592eb4f233eab459fb79291942c7692476d14d1b924351a08e1f7cae43fb81e4d05f59e28936dc96c263f101c10
|
data/Changelog.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
- Nothing yet!
|
6
6
|
|
7
|
+
## 0.3.0
|
8
|
+
|
9
|
+
- Adds selective linting, now SwiftLint will only run on the PR added and modified files. See [#23](https://github.com/ashfurrow/danger-swiftlint/pull/23)
|
10
|
+
|
7
11
|
## 0.2.1
|
8
12
|
|
9
13
|
- Adds support for specifying a directory in which to run SwiftLint. See [#19](https://github.com/ashfurrow/danger-swiftlint/pull/19).
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,40 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-swiftlint (0.
|
4
|
+
danger-swiftlint (0.3.0)
|
5
5
|
danger
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.
|
10
|
+
addressable (2.5.0)
|
11
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
11
12
|
bacon (1.2.0)
|
12
|
-
claide (1.0.
|
13
|
+
claide (1.0.1)
|
14
|
+
claide-plugins (0.9.2)
|
15
|
+
cork
|
16
|
+
nap
|
17
|
+
open4 (~> 1.3)
|
13
18
|
coderay (1.1.1)
|
14
19
|
colored (1.2)
|
15
|
-
cork (0.
|
20
|
+
cork (0.2.0)
|
16
21
|
colored (~> 1.2)
|
17
|
-
danger (0.
|
22
|
+
danger (4.0.3)
|
18
23
|
claide (~> 1.0)
|
24
|
+
claide-plugins (>= 0.9.2)
|
19
25
|
colored (~> 1.2)
|
20
26
|
cork (~> 0.1)
|
21
|
-
faraday (~> 0)
|
27
|
+
faraday (~> 0.9)
|
28
|
+
faraday-http-cache (~> 1.0)
|
22
29
|
git (~> 1)
|
30
|
+
kramdown (~> 1.5)
|
23
31
|
octokit (~> 4.2)
|
24
|
-
redcarpet (~> 3.3)
|
25
32
|
terminal-table (~> 1)
|
26
33
|
diff-lcs (1.2.5)
|
27
|
-
faraday (0.
|
34
|
+
faraday (0.10.0)
|
28
35
|
multipart-post (>= 1.2, < 3)
|
36
|
+
faraday-http-cache (1.3.1)
|
37
|
+
faraday (~> 0.8)
|
29
38
|
ffi (1.9.10)
|
30
39
|
formatador (0.2.5)
|
31
40
|
git (1.3.0)
|
@@ -43,6 +52,7 @@ GEM
|
|
43
52
|
guard (~> 2.1)
|
44
53
|
guard-compat (~> 1.1)
|
45
54
|
rspec (>= 2.99.0, < 4.0)
|
55
|
+
kramdown (1.13.1)
|
46
56
|
listen (3.0.7)
|
47
57
|
rb-fsevent (>= 0.9.3)
|
48
58
|
rb-inotify (>= 0.9.7)
|
@@ -54,23 +64,25 @@ GEM
|
|
54
64
|
mocha-on-bacon (0.2.2)
|
55
65
|
mocha (>= 0.13.0)
|
56
66
|
multipart-post (2.0.0)
|
67
|
+
nap (1.1.0)
|
57
68
|
nenv (0.3.0)
|
58
69
|
notiffany (0.1.0)
|
59
70
|
nenv (~> 0.1)
|
60
71
|
shellany (~> 0.0)
|
61
|
-
octokit (4.
|
62
|
-
sawyer (~> 0.
|
72
|
+
octokit (4.6.2)
|
73
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
74
|
+
open4 (1.3.4)
|
63
75
|
prettybacon (0.0.2)
|
64
76
|
bacon (~> 1.2)
|
65
77
|
pry (0.10.3)
|
66
78
|
coderay (~> 1.1.0)
|
67
79
|
method_source (~> 0.8.1)
|
68
80
|
slop (~> 3.4)
|
81
|
+
public_suffix (2.0.4)
|
69
82
|
rake (10.5.0)
|
70
83
|
rb-fsevent (0.9.7)
|
71
84
|
rb-inotify (0.9.7)
|
72
85
|
ffi (>= 0.5.0)
|
73
|
-
redcarpet (3.3.4)
|
74
86
|
rspec (3.4.0)
|
75
87
|
rspec-core (~> 3.4.0)
|
76
88
|
rspec-expectations (~> 3.4.0)
|
@@ -84,13 +96,15 @@ GEM
|
|
84
96
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
97
|
rspec-support (~> 3.4.0)
|
86
98
|
rspec-support (3.4.1)
|
87
|
-
sawyer (0.
|
88
|
-
addressable (>= 2.3.5, < 2.
|
89
|
-
faraday (~> 0.8, < 0
|
99
|
+
sawyer (0.8.1)
|
100
|
+
addressable (>= 2.3.5, < 2.6)
|
101
|
+
faraday (~> 0.8, < 1.0)
|
90
102
|
shellany (0.0.1)
|
91
103
|
slop (3.6.0)
|
92
|
-
terminal-table (1.
|
104
|
+
terminal-table (1.7.3)
|
105
|
+
unicode-display_width (~> 1.1.1)
|
93
106
|
thor (0.19.1)
|
107
|
+
unicode-display_width (1.1.2)
|
94
108
|
|
95
109
|
PLATFORMS
|
96
110
|
ruby
|
@@ -110,4 +124,4 @@ DEPENDENCIES
|
|
110
124
|
rspec (~> 3.4)
|
111
125
|
|
112
126
|
BUNDLED WITH
|
113
|
-
1.
|
127
|
+
1.13.1
|
data/README.md
CHANGED
@@ -12,6 +12,8 @@ Add this line to your Gemfile:
|
|
12
12
|
gem 'danger-swiftlint'
|
13
13
|
```
|
14
14
|
|
15
|
+
SwiftLint also needs to be installed before you run Danger, which you can do [via Homebrew](https://github.com/realm/SwiftLint#installation) or a [Brewfile](https://github.com/Homebrew/homebrew-bundle).
|
16
|
+
|
15
17
|
## Usage
|
16
18
|
|
17
19
|
The easiest way to use is just add this to your Dangerfile:
|
data/lib/danger_plugin.rb
CHANGED
@@ -29,7 +29,7 @@ module Danger
|
|
29
29
|
# if nil, modified and added files from the diff will be used.
|
30
30
|
# @return [void]
|
31
31
|
#
|
32
|
-
def lint_files
|
32
|
+
def lint_files(files=nil)
|
33
33
|
# Installs SwiftLint if needed
|
34
34
|
system "brew install swiftlint" unless swiftlint_installed?
|
35
35
|
|
@@ -39,33 +39,82 @@ module Danger
|
|
39
39
|
return
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
42
|
+
require 'tempfile'
|
43
|
+
Tempfile.open('.swiftlint_danger.yml') do |temp_config_file|
|
44
|
+
on_the_fly_configuration_path = nil
|
45
|
+
excluded_dirs = []
|
46
|
+
if config_file
|
47
|
+
require 'yaml'
|
48
|
+
original_config = YAML.load_file(config_file)
|
49
|
+
|
50
|
+
danger_compatible_config = original_config
|
51
|
+
danger_compatible_config.tap { |hash| hash.delete('included') }
|
52
|
+
|
53
|
+
excluded_dirs = danger_compatible_config['excluded']
|
54
|
+
.map { |path| File.dirname(config_file) + '/' + path }
|
55
|
+
.select { |path| File.exists?(File.expand_path(path)) || Dir.exists?(File.expand_path(path)) }
|
56
|
+
|
57
|
+
File.write(temp_config_file.path, danger_compatible_config.to_yaml)
|
58
|
+
|
59
|
+
on_the_fly_configuration_path = temp_config_file.path
|
60
|
+
end
|
61
|
+
|
62
|
+
swiftlint_command = "swiftlint lint --quiet --reporter json"
|
63
|
+
swiftlint_command += " --config #{on_the_fly_configuration_path}" if on_the_fly_configuration_path
|
64
|
+
|
65
|
+
require 'json'
|
66
|
+
|
67
|
+
if directory
|
68
|
+
swiftlint_command = "cd #{directory} && #{swiftlint_command}" if directory
|
69
|
+
|
70
|
+
result_json = JSON.parse(`(#{swiftlint_command})`).flatten
|
71
|
+
else
|
72
|
+
# Either use files provided, or use the modified + added
|
73
|
+
swift_files = files ? Dir.glob(files) : (git.modified_files + git.added_files)
|
74
|
+
|
75
|
+
swift_files.select! do |line| line.end_with?(".swift") end
|
76
|
+
|
77
|
+
require 'find'
|
78
|
+
swift_files = swift_files.reject do |file|
|
79
|
+
found = false
|
80
|
+
excluded_dirs.each do |excluded_dir|
|
81
|
+
found = Find.find(File.expand_path(excluded_dir)).include?(File.expand_path(file))
|
82
|
+
break if found
|
83
|
+
end
|
84
|
+
found
|
85
|
+
end
|
86
|
+
|
87
|
+
# Make sure we don't fail when paths have spaces
|
88
|
+
swift_files = swift_files.map { |file| "\"#{file}\"" }
|
89
|
+
|
90
|
+
result_json = swift_files
|
91
|
+
.uniq
|
92
|
+
.collect { |f| `(#{swiftlint_command} --path #{f})`.strip }
|
93
|
+
.reject { |s| s == '' }
|
94
|
+
.map { |s| JSON.parse(s).flatten }
|
95
|
+
.flatten
|
96
|
+
end
|
97
|
+
|
98
|
+
# Convert to swiftlint results
|
99
|
+
warnings = result_json.select do |results|
|
100
|
+
results['severity'] == 'Warning'
|
101
|
+
end
|
102
|
+
errors = result_json.select do |results|
|
103
|
+
results['severity'] == 'Error'
|
104
|
+
end
|
105
|
+
|
106
|
+
message = ''
|
107
|
+
|
108
|
+
# We got some error reports back from swiftlint
|
109
|
+
if warnings.count > 0 || errors.count > 0
|
110
|
+
message = "### SwiftLint found issues\n\n"
|
111
|
+
end
|
112
|
+
|
113
|
+
message << parse_results(warnings, 'Warnings') unless warnings.empty?
|
114
|
+
message << parse_results(errors, 'Errors') unless errors.empty?
|
115
|
+
|
116
|
+
markdown message unless message.empty?
|
63
117
|
end
|
64
|
-
|
65
|
-
message << parse_results(warnings, 'Warnings') unless warnings.empty?
|
66
|
-
message << parse_results(errors, 'Errors') unless errors.empty?
|
67
|
-
|
68
|
-
markdown message unless message.empty?
|
69
118
|
end
|
70
119
|
|
71
120
|
# Parses swiftlint invocation results into a string
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -26,9 +26,9 @@ module Danger
|
|
26
26
|
|
27
27
|
it 'does not markdown an empty message' do
|
28
28
|
allow(@swiftlint).to receive(:`)
|
29
|
-
.with('swiftlint lint --quiet --reporter json')
|
29
|
+
.with('swiftlint lint --quiet --reporter json --path "spec/fixtures/SwiftFile.swift"')
|
30
30
|
.and_return('[]')
|
31
|
-
|
31
|
+
|
32
32
|
expect(@swiftlint.status_report[:markdowns].first).to be_nil
|
33
33
|
end
|
34
34
|
|
@@ -38,16 +38,16 @@ module Danger
|
|
38
38
|
allow(@swiftlint).to receive(:`).with("which swiftlint").and_return("/bin/wheverever/swiftlint")
|
39
39
|
|
40
40
|
# Set up our stubbed JSON response
|
41
|
-
@swiftlint_response = '[{"reason": "Force casts should be avoided.", "file": "/
|
41
|
+
@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 }]'
|
42
42
|
end
|
43
43
|
|
44
|
-
it 'handles a known SwiftLint report' do
|
45
|
-
allow(@swiftlint).to receive(:`).with('(swiftlint lint --quiet --reporter json)').and_return(@swiftlint_response)
|
44
|
+
it 'handles a known SwiftLint report with give files' do
|
45
|
+
allow(@swiftlint).to receive(:`).with('(swiftlint lint --quiet --reporter json --path "spec/fixtures/SwiftFile.swift")').and_return(@swiftlint_response)
|
46
46
|
|
47
47
|
# Do it
|
48
|
-
@swiftlint.lint_files
|
48
|
+
@swiftlint.lint_files("spec/fixtures/*.swift")
|
49
49
|
|
50
|
-
output = @swiftlint.status_report[:markdowns].first
|
50
|
+
output = @swiftlint.status_report[:markdowns].first.to_s
|
51
51
|
|
52
52
|
expect(output).to_not be_empty
|
53
53
|
|
@@ -57,21 +57,46 @@ module Danger
|
|
57
57
|
expect(output).to include("SwiftFile.swift | 13 | Force casts should be avoided.")
|
58
58
|
end
|
59
59
|
|
60
|
-
it 'handles no files' do
|
61
|
-
allow(@swiftlint).to receive(
|
60
|
+
it 'handles no given files by looking up the git diff' do
|
61
|
+
allow(@swiftlint.git).to receive(:modified_files).and_return(['spec/fixtures/SwiftFile.swift'])
|
62
|
+
allow(@swiftlint.git).to receive(:added_files).and_return([])
|
63
|
+
|
64
|
+
allow(@swiftlint).to receive(:`).with('(swiftlint lint --quiet --reporter json --path "spec/fixtures/SwiftFile.swift")').and_return(@swiftlint_response)
|
62
65
|
|
63
66
|
@swiftlint.lint_files
|
64
67
|
|
65
|
-
expect(@swiftlint.status_report[:markdowns].first).to_not be_empty
|
68
|
+
expect(@swiftlint.status_report[:markdowns].first.to_s).to_not be_empty
|
66
69
|
end
|
67
70
|
|
68
|
-
it 'uses a config file' do
|
69
|
-
|
70
|
-
allow(@swiftlint).to receive(:`).with('(swiftlint lint --quiet --reporter json --config some_config.yml)').and_return(@swiftlint_response)
|
71
|
+
it 'uses a config file generated on the fly by removing the "included" values from the given one' do
|
72
|
+
fake_temp_file = Tempfile.new('fake.yml')
|
71
73
|
|
72
|
-
|
74
|
+
begin
|
75
|
+
allow(Tempfile).to receive(:open) { |&block| block.call(fake_temp_file) }
|
76
|
+
|
77
|
+
@swiftlint.config_file = 'spec/fixtures/some_config.yml'
|
78
|
+
|
79
|
+
expect(YAML.load_file(@swiftlint.config_file)['included']).to_not be_nil
|
80
|
+
|
81
|
+
allow(@swiftlint).to receive(:`).with('(swiftlint lint --quiet --reporter json --config ' + fake_temp_file.path + ' --path "spec/fixtures/SwiftFile.swift")') do
|
82
|
+
# The tempfile lifetime is limited to the execution of the lint
|
83
|
+
# command, as such if we were to assert it after the command has
|
84
|
+
# run the file wouldn't exist anymore.
|
85
|
+
#
|
86
|
+
# By injecting the assertion here, whithin the method execution,
|
87
|
+
# we access the file while it still exists.
|
88
|
+
expect(YAML.load_file(fake_temp_file.path)['included']).to be_nil
|
89
|
+
|
90
|
+
@swiftlint_response
|
91
|
+
end
|
92
|
+
|
93
|
+
@swiftlint.lint_files("spec/fixtures/*.swift")
|
73
94
|
|
74
|
-
|
95
|
+
expect(@swiftlint.status_report[:markdowns].first.to_s).to_not be_empty
|
96
|
+
ensure
|
97
|
+
fake_temp_file.close
|
98
|
+
fake_temp_file.unlink
|
99
|
+
end
|
75
100
|
end
|
76
101
|
|
77
102
|
it 'uses a custom directory' do
|
@@ -80,7 +105,51 @@ module Danger
|
|
80
105
|
|
81
106
|
@swiftlint.lint_files
|
82
107
|
|
83
|
-
expect(@swiftlint.status_report[:markdowns].first).to_not be_empty
|
108
|
+
expect(@swiftlint.status_report[:markdowns].first.to_s).to_not be_empty
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'does not crash if JSON reporter returns an empty string rather than an object' do
|
112
|
+
# This can occurr if for some reson there is no file at the give path.
|
113
|
+
# In such a case SwiftLint will write to stderr:
|
114
|
+
#
|
115
|
+
# Could not read contents of `path/to/file`
|
116
|
+
# No lintable files found at path 'path/to/file'
|
117
|
+
#
|
118
|
+
# and exit with code 1.
|
119
|
+
#
|
120
|
+
# To our code this would simply look like an empty result, which
|
121
|
+
# would then become an empty string, which cannot be parsed into a
|
122
|
+
# JSON object.
|
123
|
+
response = ''
|
124
|
+
allow(@swiftlint).to receive(:`).with('(swiftlint lint --quiet --reporter json --path "spec/fixtures/SwiftFile.swift")').and_return(response)
|
125
|
+
|
126
|
+
@swiftlint.lint_files("spec/fixtures/*.swift")
|
127
|
+
|
128
|
+
output = @swiftlint.status_report[:markdowns].first.to_s
|
129
|
+
|
130
|
+
# If we get to this point then we haven't crashed, happy days
|
131
|
+
expect(output).to be_empty
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'does not lint files in the excluded paths' do
|
135
|
+
allow(@swiftlint.git).to receive(:modified_files).and_return(['spec/fixtures/SwiftFile.swift', 'spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift'])
|
136
|
+
allow(@swiftlint.git).to receive(:added_files).and_return([])
|
137
|
+
|
138
|
+
fake_temp_file = Tempfile.new('fake.yml')
|
139
|
+
|
140
|
+
begin
|
141
|
+
allow(Tempfile).to receive(:open) { |&block| block.call(fake_temp_file) }
|
142
|
+
|
143
|
+
# The only call that should be received is this one, if @swiftlint
|
144
|
+
# will be called with any other param the test will fail
|
145
|
+
allow(@swiftlint).to receive(:`).with('(swiftlint lint --quiet --reporter json --config ' + fake_temp_file.path + ' --path "spec/fixtures/SwiftFile.swift")').and_return(@swiftlint_response)
|
146
|
+
|
147
|
+
@swiftlint.config_file = 'spec/fixtures/some_config.yml'
|
148
|
+
@swiftlint.lint_files
|
149
|
+
ensure
|
150
|
+
fake_temp_file.close
|
151
|
+
fake_temp_file.unlink
|
152
|
+
end
|
84
153
|
end
|
85
154
|
end
|
86
155
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
// This file intentional left blank-ish.
|
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.3.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:
|
13
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: danger
|
@@ -147,6 +147,8 @@ files:
|
|
147
147
|
- lib/version.rb
|
148
148
|
- spec/danger_plugin_spec.rb
|
149
149
|
- spec/fixtures/SwiftFile.swift
|
150
|
+
- spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift
|
151
|
+
- spec/fixtures/some_config.yml
|
150
152
|
- spec/spec_helper.rb
|
151
153
|
homepage: https://github.com/ashfurrow/danger-swiftlint
|
152
154
|
licenses:
|
@@ -168,11 +170,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
170
|
version: '0'
|
169
171
|
requirements: []
|
170
172
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.5.2
|
172
174
|
signing_key:
|
173
175
|
specification_version: 4
|
174
176
|
summary: A Danger plugin for linting Swift with SwiftLint.
|
175
177
|
test_files:
|
176
178
|
- spec/danger_plugin_spec.rb
|
177
179
|
- spec/fixtures/SwiftFile.swift
|
180
|
+
- spec/fixtures/excluded_dir/SwiftFileThatShouldNotBeIncluded.swift
|
181
|
+
- spec/fixtures/some_config.yml
|
178
182
|
- spec/spec_helper.rb
|