danger-periphery 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +58 -1
- data/Gemfile.lock +50 -42
- data/Guardfile +20 -14
- data/README.md +25 -0
- data/Rakefile +1 -1
- data/bin/download_periphery +1 -1
- data/danger-periphery.gemspec +1 -1
- data/lib/danger_plugin.rb +18 -12
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +93 -44
- data/spec/spec_helper.rb +2 -2
- data/spec/support/fixtures/mock-periphery +18 -0
- metadata +6 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b949d4e8279afb04d63616f89e15f3ef0efaf700b83d027273f1973d085fa23
|
4
|
+
data.tar.gz: cd8e2564827d41bdee17e7b8fead197f3dc1481f129ee9dcbc22779ea1783489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d0e28054ab01f50603b92cf32b6005d1befa875545afaa9d8fbd80bdf048d097776bcfcdfe01cc746a0cc24d9455284a400be7b9d11142249db9b2731d1b578
|
7
|
+
data.tar.gz: 97d0f89856d52fe03fbda8f3b8539279343e2b28340042ee5db2aa2984222cf6e3ac5eacde6ad17eebc7b393f9d6163ce16f296e8a044fe984442b31566ae6ee
|
data/.rubocop.yml
CHANGED
@@ -124,6 +124,9 @@ Metrics/BlockLength:
|
|
124
124
|
Style/MixinGrouping:
|
125
125
|
Enabled: false
|
126
126
|
|
127
|
+
Naming/BlockForwarding:
|
128
|
+
Enabled: true
|
129
|
+
|
127
130
|
Naming/FileName:
|
128
131
|
Enabled: false
|
129
132
|
|
@@ -145,10 +148,22 @@ Style/PercentLiteralDelimiters:
|
|
145
148
|
"%W": ()
|
146
149
|
"%x": ()
|
147
150
|
|
151
|
+
Security/CompoundHash:
|
152
|
+
Enabled: true
|
153
|
+
|
148
154
|
Security/YAMLLoad:
|
149
155
|
Enabled: false
|
150
156
|
|
151
|
-
Gemspec/
|
157
|
+
Gemspec/DeprecatedAttributeAssignment:
|
158
|
+
Enabled: true
|
159
|
+
|
160
|
+
Gemspec/RequireMFA:
|
161
|
+
Enabled: true
|
162
|
+
|
163
|
+
Layout/LineContinuationLeadingSpace:
|
164
|
+
Enabled: true
|
165
|
+
|
166
|
+
Layout/LineContinuationSpacing:
|
152
167
|
Enabled: true
|
153
168
|
|
154
169
|
Layout/LineEndStringConcatenationIndentation:
|
@@ -166,6 +181,9 @@ Lint/AmbiguousOperatorPrecedence:
|
|
166
181
|
Lint/AmbiguousRange:
|
167
182
|
Enabled: true
|
168
183
|
|
184
|
+
Lint/ConstantOverwrittenInRescue:
|
185
|
+
Enabled: true
|
186
|
+
|
169
187
|
Lint/DeprecatedConstants:
|
170
188
|
Enabled: true
|
171
189
|
|
@@ -190,6 +208,9 @@ Lint/IncompatibleIoSelectWithFiberScheduler:
|
|
190
208
|
Lint/LambdaWithoutLiteralBlock:
|
191
209
|
Enabled: true
|
192
210
|
|
211
|
+
Lint/NonAtomicFileOperation:
|
212
|
+
Enabled: true
|
213
|
+
|
193
214
|
Lint/NoReturnInBeginEndBlocks:
|
194
215
|
Enabled: true
|
195
216
|
|
@@ -202,6 +223,9 @@ Lint/OrAssignmentToConstant:
|
|
202
223
|
Lint/RedundantDirGlobSort:
|
203
224
|
Enabled: true
|
204
225
|
|
226
|
+
Lint/RefinementImportMethods:
|
227
|
+
Enabled: true
|
228
|
+
|
205
229
|
Lint/RequireRelativeSelfPath:
|
206
230
|
Enabled: true
|
207
231
|
|
@@ -220,6 +244,9 @@ Lint/UnexpectedBlockArity:
|
|
220
244
|
Lint/UnmodifiedReduceAccumulator:
|
221
245
|
Enabled: true
|
222
246
|
|
247
|
+
Lint/UselessRuby2Keywords:
|
248
|
+
Enabled: true
|
249
|
+
|
223
250
|
Security/IoMethods:
|
224
251
|
Enabled: true
|
225
252
|
|
@@ -235,6 +262,18 @@ Style/DocumentDynamicEvalDefinition:
|
|
235
262
|
Style/EndlessMethod:
|
236
263
|
Enabled: true
|
237
264
|
|
265
|
+
Style/EnvHome:
|
266
|
+
Enabled: true
|
267
|
+
|
268
|
+
Style/FetchEnvVar:
|
269
|
+
Enabled: true
|
270
|
+
|
271
|
+
Style/FileRead:
|
272
|
+
Enabled: true
|
273
|
+
|
274
|
+
Style/FileWrite:
|
275
|
+
Enabled: true
|
276
|
+
|
238
277
|
Style/HashConversion:
|
239
278
|
Enabled: true
|
240
279
|
|
@@ -247,12 +286,21 @@ Style/IfWithBooleanLiteralBranches:
|
|
247
286
|
Style/InPatternThen:
|
248
287
|
Enabled: true
|
249
288
|
|
289
|
+
Style/MapCompactWithConditionalBlock:
|
290
|
+
Enabled: true
|
291
|
+
|
292
|
+
Style/MapToHash:
|
293
|
+
Enabled: true
|
294
|
+
|
250
295
|
Style/MultilineInPatternThen:
|
251
296
|
Enabled: true
|
252
297
|
|
253
298
|
Style/NegatedIfElseCondition:
|
254
299
|
Enabled: true
|
255
300
|
|
301
|
+
Style/NestedFileDirname:
|
302
|
+
Enabled: true
|
303
|
+
|
256
304
|
Style/NilLambda:
|
257
305
|
Enabled: true
|
258
306
|
|
@@ -262,12 +310,21 @@ Style/NumberedParameters:
|
|
262
310
|
Style/NumberedParametersLimit:
|
263
311
|
Enabled: true
|
264
312
|
|
313
|
+
Style/ObjectThen:
|
314
|
+
Enabled: true
|
315
|
+
|
316
|
+
Style/OpenStructUse:
|
317
|
+
Enabled: true
|
318
|
+
|
265
319
|
Style/QuotedSymbols:
|
266
320
|
Enabled: true
|
267
321
|
|
268
322
|
Style/RedundantArgument:
|
269
323
|
Enabled: true
|
270
324
|
|
325
|
+
Style/RedundantInitialize:
|
326
|
+
Enabled: true
|
327
|
+
|
271
328
|
Style/RedundantSelfAssignmentBranch:
|
272
329
|
Enabled: true
|
273
330
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-periphery (0.
|
4
|
+
danger-periphery (0.2.0)
|
5
5
|
danger-plugin-api (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
addressable (2.8.0)
|
11
11
|
public_suffix (>= 2.0.2, < 5.0)
|
12
12
|
ast (2.4.2)
|
13
|
-
claide (1.0
|
13
|
+
claide (1.1.0)
|
14
14
|
claide-plugins (0.9.2)
|
15
15
|
cork
|
16
16
|
nap
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
colored2 (3.1.2)
|
20
20
|
cork (0.3.0)
|
21
21
|
colored2 (~> 3.1)
|
22
|
-
danger (8.
|
22
|
+
danger (8.6.1)
|
23
23
|
claide (~> 1.0)
|
24
24
|
claide-plugins (>= 0.9.2)
|
25
25
|
colored2 (~> 3.1)
|
@@ -34,34 +34,38 @@ GEM
|
|
34
34
|
terminal-table (>= 1, < 4)
|
35
35
|
danger-plugin-api (1.0.0)
|
36
36
|
danger (> 2.0)
|
37
|
-
danger-rubocop (0.
|
37
|
+
danger-rubocop (0.10.0)
|
38
38
|
danger
|
39
39
|
rubocop (~> 1.0)
|
40
40
|
diff-lcs (1.5.0)
|
41
|
-
faraday (1.
|
41
|
+
faraday (1.10.0)
|
42
42
|
faraday-em_http (~> 1.0)
|
43
43
|
faraday-em_synchrony (~> 1.0)
|
44
44
|
faraday-excon (~> 1.1)
|
45
|
-
faraday-httpclient (~> 1.0
|
45
|
+
faraday-httpclient (~> 1.0)
|
46
|
+
faraday-multipart (~> 1.0)
|
46
47
|
faraday-net_http (~> 1.0)
|
47
|
-
faraday-net_http_persistent (~> 1.
|
48
|
+
faraday-net_http_persistent (~> 1.0)
|
48
49
|
faraday-patron (~> 1.0)
|
49
50
|
faraday-rack (~> 1.0)
|
50
|
-
|
51
|
+
faraday-retry (~> 1.0)
|
51
52
|
ruby2_keywords (>= 0.0.4)
|
52
53
|
faraday-em_http (1.0.0)
|
53
54
|
faraday-em_synchrony (1.0.0)
|
54
55
|
faraday-excon (1.1.0)
|
55
|
-
faraday-http-cache (2.
|
56
|
+
faraday-http-cache (2.4.0)
|
56
57
|
faraday (>= 0.8)
|
57
58
|
faraday-httpclient (1.0.1)
|
59
|
+
faraday-multipart (1.0.4)
|
60
|
+
multipart-post (~> 2)
|
58
61
|
faraday-net_http (1.0.1)
|
59
62
|
faraday-net_http_persistent (1.2.0)
|
60
63
|
faraday-patron (1.0.0)
|
61
64
|
faraday-rack (1.0.0)
|
65
|
+
faraday-retry (1.0.3)
|
62
66
|
ffi (1.15.5)
|
63
67
|
formatador (1.1.0)
|
64
|
-
git (1.
|
68
|
+
git (1.11.0)
|
65
69
|
rchardet (~> 1.8)
|
66
70
|
guard (2.18.0)
|
67
71
|
formatador (>= 0.2.4)
|
@@ -77,7 +81,8 @@ GEM
|
|
77
81
|
guard (~> 2.1)
|
78
82
|
guard-compat (~> 1.1)
|
79
83
|
rspec (>= 2.99.0, < 4.0)
|
80
|
-
|
84
|
+
json (2.6.2)
|
85
|
+
kramdown (2.4.0)
|
81
86
|
rexml
|
82
87
|
kramdown-parser-gfm (1.1.0)
|
83
88
|
kramdown (~> 2.0)
|
@@ -86,67 +91,70 @@ GEM
|
|
86
91
|
rb-inotify (~> 0.9, >= 0.9.10)
|
87
92
|
lumberjack (1.2.8)
|
88
93
|
method_source (1.0.0)
|
89
|
-
multipart-post (2.
|
94
|
+
multipart-post (2.2.3)
|
90
95
|
nap (1.1.0)
|
91
96
|
nenv (0.3.0)
|
92
97
|
no_proxy_fix (0.1.2)
|
93
98
|
notiffany (0.1.3)
|
94
99
|
nenv (~> 0.1)
|
95
100
|
shellany (~> 0.0)
|
96
|
-
octokit (4.
|
97
|
-
faraday (>=
|
98
|
-
sawyer (~> 0.
|
101
|
+
octokit (4.25.1)
|
102
|
+
faraday (>= 1, < 3)
|
103
|
+
sawyer (~> 0.9)
|
99
104
|
open4 (1.3.4)
|
100
|
-
parallel (1.
|
101
|
-
parser (3.
|
105
|
+
parallel (1.22.1)
|
106
|
+
parser (3.1.2.0)
|
102
107
|
ast (~> 2.4.1)
|
103
108
|
pry (0.14.1)
|
104
109
|
coderay (~> 1.1)
|
105
110
|
method_source (~> 1.0)
|
106
|
-
public_suffix (4.0.
|
107
|
-
rainbow (3.
|
111
|
+
public_suffix (4.0.7)
|
112
|
+
rainbow (3.1.1)
|
108
113
|
rake (13.0.6)
|
109
|
-
rb-fsevent (0.11.
|
114
|
+
rb-fsevent (0.11.1)
|
110
115
|
rb-inotify (0.10.1)
|
111
116
|
ffi (~> 1.0)
|
112
117
|
rchardet (1.8.0)
|
113
|
-
regexp_parser (2.
|
118
|
+
regexp_parser (2.5.0)
|
114
119
|
rexml (3.2.5)
|
115
|
-
rspec (3.
|
116
|
-
rspec-core (~> 3.
|
117
|
-
rspec-expectations (~> 3.
|
118
|
-
rspec-mocks (~> 3.
|
119
|
-
rspec-core (3.
|
120
|
-
rspec-support (~> 3.
|
121
|
-
rspec-expectations (3.
|
120
|
+
rspec (3.11.0)
|
121
|
+
rspec-core (~> 3.11.0)
|
122
|
+
rspec-expectations (~> 3.11.0)
|
123
|
+
rspec-mocks (~> 3.11.0)
|
124
|
+
rspec-core (3.11.0)
|
125
|
+
rspec-support (~> 3.11.0)
|
126
|
+
rspec-expectations (3.11.0)
|
122
127
|
diff-lcs (>= 1.2.0, < 2.0)
|
123
|
-
rspec-support (~> 3.
|
124
|
-
rspec-mocks (3.
|
128
|
+
rspec-support (~> 3.11.0)
|
129
|
+
rspec-mocks (3.11.1)
|
125
130
|
diff-lcs (>= 1.2.0, < 2.0)
|
126
|
-
rspec-support (~> 3.
|
127
|
-
rspec-support (3.
|
128
|
-
rubocop (1.
|
131
|
+
rspec-support (~> 3.11.0)
|
132
|
+
rspec-support (3.11.0)
|
133
|
+
rubocop (1.31.2)
|
134
|
+
json (~> 2.3)
|
129
135
|
parallel (~> 1.10)
|
130
|
-
parser (>= 3.
|
136
|
+
parser (>= 3.1.0.0)
|
131
137
|
rainbow (>= 2.2.2, < 4.0)
|
132
138
|
regexp_parser (>= 1.8, < 3.0)
|
133
|
-
rexml
|
134
|
-
rubocop-ast (>= 1.
|
139
|
+
rexml (>= 3.2.5, < 4.0)
|
140
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
135
141
|
ruby-progressbar (~> 1.7)
|
136
142
|
unicode-display_width (>= 1.4.0, < 3.0)
|
137
|
-
rubocop-ast (1.
|
138
|
-
parser (>= 3.
|
143
|
+
rubocop-ast (1.19.1)
|
144
|
+
parser (>= 3.1.1.0)
|
139
145
|
ruby-progressbar (1.11.0)
|
140
146
|
ruby2_keywords (0.0.5)
|
141
|
-
sawyer (0.
|
147
|
+
sawyer (0.9.2)
|
142
148
|
addressable (>= 2.3.5)
|
143
|
-
faraday (
|
149
|
+
faraday (>= 0.17.3, < 3)
|
144
150
|
shellany (0.0.1)
|
145
151
|
terminal-table (3.0.2)
|
146
152
|
unicode-display_width (>= 1.1.1, < 3)
|
147
153
|
thor (1.2.1)
|
148
|
-
unicode-display_width (2.
|
149
|
-
|
154
|
+
unicode-display_width (2.2.0)
|
155
|
+
webrick (1.7.0)
|
156
|
+
yard (0.9.28)
|
157
|
+
webrick (~> 1.7.0)
|
150
158
|
|
151
159
|
PLATFORMS
|
152
160
|
ruby
|
data/Guardfile
CHANGED
@@ -4,27 +4,33 @@ module ::Guard
|
|
4
4
|
class Periphery < Plugin
|
5
5
|
def initialize(options = {})
|
6
6
|
opts = options.dup
|
7
|
-
@
|
8
|
-
|
9
|
-
|
7
|
+
@command = [
|
8
|
+
"bin/periphery",
|
9
|
+
"scan",
|
10
|
+
"--project",
|
11
|
+
opts.delete(:project),
|
12
|
+
"--targets",
|
13
|
+
opts.delete(:targets),
|
14
|
+
"--schemes",
|
15
|
+
opts.delete(:schemes),
|
16
|
+
"--format",
|
17
|
+
"checkstyle"
|
18
|
+
]
|
10
19
|
super(opts)
|
11
20
|
end
|
12
21
|
|
13
|
-
def
|
14
|
-
command
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
).join(" ")
|
21
|
-
puts(command)
|
22
|
-
system(command)
|
22
|
+
def run_all
|
23
|
+
UI.info(@command.shelljoin)
|
24
|
+
system(*@command)
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_on_changes(_paths)
|
28
|
+
run_all
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
27
|
-
guard :rspec, cmd: "bundle exec rspec" do
|
33
|
+
guard :rspec, cmd: "bundle exec rspec -t ~slow", run_all: { cmd: "bundle exec rspec" } do
|
28
34
|
require "guard/rspec/dsl"
|
29
35
|
dsl = Guard::RSpec::Dsl.new(self)
|
30
36
|
|
data/README.md
CHANGED
@@ -42,6 +42,31 @@ periphery.scan(
|
|
42
42
|
|
43
43
|
## Advanced Usage
|
44
44
|
|
45
|
+
### Postprocess warnings by passing block to `#scan`
|
46
|
+
|
47
|
+
You can modify warnings as you like by passing a block to `scan`.
|
48
|
+
`scan` takes a block that receives `ScanResult` instance as arguments.
|
49
|
+
Each `ScanResult` instance corresponds with each entry of Danger warnings.
|
50
|
+
If that block returns falsy value, danger-periphery suppresses the corresponding warning.
|
51
|
+
|
52
|
+
For example, if you want your team members to be careful with warnings, the following code may work.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
periphery.scan do |violation|
|
56
|
+
violation.message = "Pay attention please! #{violation.message}"
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
For another example, if you want to suppress warnings complaining about unused parameter of many of `didChangeValue(_ sender: Any)` methods, you can suppress this kind of warnings in the following way.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
periphery.scan do |violation|
|
64
|
+
! violation.message.match(/Parameter 'sender' is unused/)
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
### Postprocess warnings by calling `#process_warnings`
|
69
|
+
|
45
70
|
You can modify warnings as you like by passing a block to `process_warnings`.
|
46
71
|
`process_warnings` takes a block that receives `[path, line, column, message]` as arguments and returns one of the following types.
|
47
72
|
|
data/Rakefile
CHANGED
data/bin/download_periphery
CHANGED
data/danger-periphery.gemspec
CHANGED
@@ -14,10 +14,10 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/manicmaniac/danger-periphery"
|
15
15
|
spec.license = "MIT"
|
16
16
|
spec.required_ruby_version = ">= 2.6.0"
|
17
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
17
18
|
|
18
19
|
spec.files = `git ls-files`.split($/)
|
19
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_dependency "danger-plugin-api", "~> 1.0"
|
data/lib/danger_plugin.rb
CHANGED
@@ -59,13 +59,13 @@ module Danger
|
|
59
59
|
# 4. If value is true, drop value and treat it as option without argument.
|
60
60
|
# 5. Override some options like --disable-update-check, --format, --quiet and so.
|
61
61
|
# @return [void]
|
62
|
-
def scan(**options)
|
62
|
+
def scan(**options, &block)
|
63
63
|
output = Periphery::Runner.new(binary_path).scan(options.merge(OPTION_OVERRIDES))
|
64
64
|
files = files_in_diff
|
65
65
|
Periphery::CheckstyleParser.new.parse(output).
|
66
66
|
lazy.
|
67
67
|
select { |entry| files.include?(entry.path) }.
|
68
|
-
map { |entry| postprocess(entry) }.
|
68
|
+
map { |entry| postprocess(entry, &block) }.
|
69
69
|
force.
|
70
70
|
compact.
|
71
71
|
each { |path, line, column, message| warn(message, file: path, line: line) }
|
@@ -87,21 +87,27 @@ module Danger
|
|
87
87
|
|
88
88
|
def files_in_diff
|
89
89
|
# Taken from https://github.com/ashfurrow/danger-ruby-swiftlint/blob/5184909aab00f12954088684bbf2ce5627e08ed6/lib/danger_plugin.rb#L214-L216
|
90
|
-
renamed_files_hash = git.renamed_files.
|
90
|
+
renamed_files_hash = git.renamed_files.to_h { |rename| [rename[:before], rename[:after]] }
|
91
91
|
post_rename_modified_files = git.modified_files.map { |modified_file| renamed_files_hash[modified_file] || modified_file }
|
92
92
|
(post_rename_modified_files - git.deleted_files) + git.added_files
|
93
93
|
end
|
94
94
|
|
95
|
-
def postprocess(entry)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
[entry.path, entry.line, entry.column, entry.message]
|
101
|
-
elsif result.kind_of?(Array) && result.size == 4
|
102
|
-
result
|
95
|
+
def postprocess(entry, &block)
|
96
|
+
if block
|
97
|
+
if block.call(entry)
|
98
|
+
[entry.path, entry.line, entry.column, entry.message]
|
99
|
+
end
|
103
100
|
else
|
104
|
-
|
101
|
+
result = @postprocessor.call(entry.path, entry.line, entry.column, entry.message)
|
102
|
+
if !result
|
103
|
+
nil
|
104
|
+
elsif result.kind_of?(TrueClass)
|
105
|
+
[entry.path, entry.line, entry.column, entry.message]
|
106
|
+
elsif result.kind_of?(Array) && result.size == 4
|
107
|
+
result
|
108
|
+
else
|
109
|
+
raise "Proc passed to postprocessor must return one of nil, true, false and Array that includes 4 elements."
|
110
|
+
end
|
105
111
|
end
|
106
112
|
end
|
107
113
|
end
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -3,6 +3,14 @@
|
|
3
3
|
describe Danger::DangerPeriphery do
|
4
4
|
include DangerPluginHelper
|
5
5
|
|
6
|
+
let(:periphery_options) do
|
7
|
+
{
|
8
|
+
project: fixture("test.xcodeproj"),
|
9
|
+
targets: "test",
|
10
|
+
schemes: "test"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
6
14
|
it "should be a plugin" do
|
7
15
|
expect(Danger::DangerPeriphery.new(nil)).to be_a Danger::Plugin
|
8
16
|
end
|
@@ -12,9 +20,10 @@ describe Danger::DangerPeriphery do
|
|
12
20
|
let(:periphery) { dangerfile.periphery }
|
13
21
|
|
14
22
|
before do
|
15
|
-
periphery.binary_path =
|
16
|
-
|
17
|
-
|
23
|
+
periphery.binary_path = fixture("mock-periphery")
|
24
|
+
# example json: `curl -o github_pr.json https://api.github.com/repos/danger/danger-plugin-template/pulls/18
|
25
|
+
json = File.read(fixture("github_pr.json"))
|
26
|
+
allow(periphery.github).to receive(:pr_json).and_return json
|
18
27
|
allow(Pathname).to receive(:getwd).and_return fixtures_path
|
19
28
|
end
|
20
29
|
|
@@ -26,60 +35,104 @@ describe Danger::DangerPeriphery do
|
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
29
|
-
context "
|
30
|
-
before
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
context "with a real periphery executable", :slow do
|
39
|
+
before { periphery.binary_path = binary("periphery") }
|
40
|
+
|
41
|
+
context "when .swift files not in diff" do
|
42
|
+
before do
|
43
|
+
allow(periphery.git).to receive(:renamed_files).and_return []
|
44
|
+
allow(periphery.git).to receive(:modified_files).and_return []
|
45
|
+
allow(periphery.git).to receive(:deleted_files).and_return []
|
46
|
+
allow(periphery.git).to receive(:added_files).and_return []
|
47
|
+
end
|
36
48
|
|
37
|
-
|
38
|
-
|
39
|
-
project: fixture("test.xcodeproj"),
|
40
|
-
targets: "test",
|
41
|
-
schemes: "test"
|
42
|
-
)
|
49
|
+
it "reports nothing" do
|
50
|
+
periphery.scan(periphery_options)
|
43
51
|
|
44
|
-
|
52
|
+
expect(dangerfile.status_report[:warnings]).to be_empty
|
53
|
+
end
|
45
54
|
end
|
46
|
-
end
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
context "when .swift files were added" do
|
57
|
+
before do
|
58
|
+
allow(periphery.git).to receive(:renamed_files).and_return []
|
59
|
+
allow(periphery.git).to receive(:modified_files).and_return []
|
60
|
+
allow(periphery.git).to receive(:deleted_files).and_return []
|
61
|
+
allow(periphery.git).to receive(:added_files).and_return ["test/main.swift"]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "reports unused code" do
|
65
|
+
periphery.scan(periphery_options)
|
66
|
+
|
67
|
+
expect(dangerfile.status_report[:warnings]).to include "Function 'unusedMethod()' is unused"
|
68
|
+
end
|
54
69
|
end
|
55
70
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
context "when .swift files were modified" do
|
72
|
+
before do
|
73
|
+
allow(periphery.git).to receive(:renamed_files).and_return []
|
74
|
+
allow(periphery.git).to receive(:modified_files).and_return ["test/main.swift"]
|
75
|
+
allow(periphery.git).to receive(:deleted_files).and_return []
|
76
|
+
allow(periphery.git).to receive(:added_files).and_return []
|
77
|
+
end
|
78
|
+
|
79
|
+
it "reports unused code" do
|
80
|
+
periphery.scan(periphery_options)
|
62
81
|
|
63
|
-
|
82
|
+
expect(dangerfile.status_report[:warnings]).to include "Function 'unusedMethod()' is unused"
|
83
|
+
end
|
64
84
|
end
|
65
85
|
end
|
66
86
|
|
67
|
-
context "
|
87
|
+
context "with block" do
|
88
|
+
subject { dangerfile.status_report[:warnings] }
|
89
|
+
|
68
90
|
before do
|
69
91
|
allow(periphery.git).to receive(:renamed_files).and_return []
|
70
92
|
allow(periphery.git).to receive(:modified_files).and_return ["test/main.swift"]
|
71
93
|
allow(periphery.git).to receive(:deleted_files).and_return []
|
72
94
|
allow(periphery.git).to receive(:added_files).and_return []
|
95
|
+
periphery.scan(periphery_options, &block)
|
73
96
|
end
|
74
97
|
|
75
|
-
|
76
|
-
|
77
|
-
project: fixture("test.xcodeproj"),
|
78
|
-
targets: "test",
|
79
|
-
schemes: "test"
|
80
|
-
)
|
98
|
+
context "that returns nil" do
|
99
|
+
let(:block) { ->(violation) {} }
|
81
100
|
|
82
|
-
|
101
|
+
it "filters out all warnings" do
|
102
|
+
expect(subject).to be_empty
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "that returns false" do
|
107
|
+
let(:block) { ->(violation) { false } }
|
108
|
+
|
109
|
+
it "filters out all warnings" do
|
110
|
+
expect(subject).to be_empty
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "that returns true" do
|
115
|
+
let(:block) { ->(violation) { true } }
|
116
|
+
|
117
|
+
it "reports warnings without filtering anything" do
|
118
|
+
expect(subject).to include "Function 'unusedMethod()' is unused"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "that returns truthy value" do
|
123
|
+
let(:block) { ->(violation) { 0 } }
|
124
|
+
|
125
|
+
it "reports warnings without filtering anything" do
|
126
|
+
expect(subject).to include "Function 'unusedMethod()' is unused"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "that modifies the given violation" do
|
131
|
+
let(:block) { ->(violation) { violation.message.gsub!(/Function/, "Foobar") } }
|
132
|
+
|
133
|
+
it "reports modified warnings" do
|
134
|
+
expect(subject).to include "Foobar 'unusedMethod()' is unused"
|
135
|
+
end
|
83
136
|
end
|
84
137
|
end
|
85
138
|
|
@@ -92,11 +145,7 @@ describe Danger::DangerPeriphery do
|
|
92
145
|
allow(periphery.git).to receive(:deleted_files).and_return []
|
93
146
|
allow(periphery.git).to receive(:added_files).and_return []
|
94
147
|
periphery.postprocessor = postprocessor
|
95
|
-
periphery.scan(
|
96
|
-
project: fixture("test.xcodeproj"),
|
97
|
-
targets: "test",
|
98
|
-
schemes: "test"
|
99
|
-
)
|
148
|
+
periphery.scan(periphery_options)
|
100
149
|
end
|
101
150
|
|
102
151
|
context "when returns nil" do
|
data/spec/spec_helper.rb
CHANGED
@@ -11,7 +11,7 @@ require "rspec"
|
|
11
11
|
|
12
12
|
module FixtureHelper
|
13
13
|
def fixtures_path
|
14
|
-
Pathname.new("
|
14
|
+
Pathname.new("support/fixtures").expand_path(__dir__)
|
15
15
|
end
|
16
16
|
|
17
17
|
def fixture(filename)
|
@@ -19,7 +19,7 @@ module FixtureHelper
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def binaries_path
|
22
|
-
Pathname.new("
|
22
|
+
Pathname.new("../bin").expand_path(__dir__)
|
23
23
|
end
|
24
24
|
|
25
25
|
def binary(filename)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
puts <<~XML
|
5
|
+
<?xml version="1.0" encoding="utf-8"?>
|
6
|
+
<checkstyle version="4.3">
|
7
|
+
<file name="#{__dir__}/test/main.swift">
|
8
|
+
<error line="1" column="10" severity="warning" message="Protocol 'RedundantProtocol' is redundant as it's never used as an existential type"/>
|
9
|
+
<error line="4" column="18" severity="warning" message="Protocol 'RedundantProtocol' conformance is redundant"/>
|
10
|
+
<error line="7" column="14" severity="warning" message="Enum case 'unusedCase' is unused"/>
|
11
|
+
<error line="10" column="9" severity="warning" message="Property 'unusedProperty' is unused"/>
|
12
|
+
<error line="11" column="17" severity="warning" message="Property 'assignOnlyProperty' is assigned, but never used"/>
|
13
|
+
<error line="14" column="17" severity="warning" message="Function 'methodWithRedundantPublicAccessibility(_:)' is declared public, but not used outside of test"/>
|
14
|
+
<error line="14" column="58" severity="warning" message="Parameter 'unusedParameter' is unused"/>
|
15
|
+
<error line="19" column="10" severity="warning" message="Function 'unusedMethod()' is unused"/>
|
16
|
+
</file>
|
17
|
+
</checkstyle>
|
18
|
+
XML
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-periphery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryosuke Ito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -57,12 +57,14 @@ files:
|
|
57
57
|
- spec/periphery/runner_spec.rb
|
58
58
|
- spec/spec_helper.rb
|
59
59
|
- spec/support/fixtures/github_pr.json
|
60
|
+
- spec/support/fixtures/mock-periphery
|
60
61
|
- spec/support/fixtures/test.xcodeproj/project.pbxproj
|
61
62
|
- spec/support/fixtures/test/main.swift
|
62
63
|
homepage: https://github.com/manicmaniac/danger-periphery
|
63
64
|
licenses:
|
64
65
|
- MIT
|
65
|
-
metadata:
|
66
|
+
metadata:
|
67
|
+
rubygems_mfa_required: 'true'
|
66
68
|
post_install_message:
|
67
69
|
rdoc_options: []
|
68
70
|
require_paths:
|
@@ -82,11 +84,4 @@ rubygems_version: 3.0.3.1
|
|
82
84
|
signing_key:
|
83
85
|
specification_version: 4
|
84
86
|
summary: A Danger plugin to detect unused codes.
|
85
|
-
test_files:
|
86
|
-
- spec/danger_plugin_spec.rb
|
87
|
-
- spec/periphery/checkstyle_parser_spec.rb
|
88
|
-
- spec/periphery/runner_spec.rb
|
89
|
-
- spec/spec_helper.rb
|
90
|
-
- spec/support/fixtures/github_pr.json
|
91
|
-
- spec/support/fixtures/test.xcodeproj/project.pbxproj
|
92
|
-
- spec/support/fixtures/test/main.swift
|
87
|
+
test_files: []
|