danger-periphery 0.0.1 → 0.1.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/.gitignore +0 -1
- data/Dangerfile +4 -0
- data/Gemfile +5 -6
- data/Gemfile.lock +170 -0
- data/Guardfile +26 -5
- data/README.md +50 -11
- data/Rakefile +2 -8
- data/danger-periphery.gemspec +1 -1
- data/lib/danger_plugin.rb +59 -6
- data/lib/periphery/checkstyle_parser.rb +54 -0
- data/lib/periphery/runner.rb +8 -4
- data/lib/periphery/scan_result.rb +5 -0
- data/lib/periphery.rb +4 -0
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +115 -57
- data/spec/periphery/checkstyle_parser_spec.rb +34 -0
- data/spec/periphery/runner_spec.rb +94 -56
- data/spec/spec_helper.rb +63 -63
- data/spec/support/fixtures/test/main.swift +22 -2
- metadata +10 -7
- data/lib/periphery/scan_log_parser.rb +0 -20
- data/spec/periphery/scan_log_parser_spec.rb +0 -50
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 151988044c8bd6c18f36c5c44952bea6cba9443defbdbab19b309058b37c50fd
|
|
4
|
+
data.tar.gz: f67a5ec28410926edbd3efd022730fb0f8db0d1a07e77f8319a6c3cfdc241e4c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5804a836bd9ea4ac4564fba40e207440b62fd135eb0474d54c9a5c539719e3e9cc1a1e119e1c096c6a08f49a9af59c4aec70bdcfaba4982f54a2e853a413cafa
|
|
7
|
+
data.tar.gz: e22a91d942805d7abc7d4228b27c1caf0926f8a0ce8a5b16048c30c1bae1e42141522b7a13cd63af7598f3c499ed973b608f4a68b6d40193429f2ead4da0c11c
|
data/.gitignore
CHANGED
data/Dangerfile
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
rubocop.lint inline_comment: true
|
|
4
4
|
|
|
5
5
|
periphery.binary_path = "bin/periphery"
|
|
6
|
+
periphery.process_warnings do |path, line, column, message|
|
|
7
|
+
!message.match(/unused/i)
|
|
8
|
+
end
|
|
9
|
+
|
|
6
10
|
periphery.scan(
|
|
7
11
|
project: "spec/support/fixtures/test.xcodeproj",
|
|
8
12
|
schemes: "test",
|
data/Gemfile
CHANGED
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
-
# Specify your gem's dependencies in danger-periphery.gemspec
|
|
6
5
|
gemspec
|
|
7
6
|
|
|
8
7
|
gem "bundler", "~> 2.0"
|
|
9
8
|
gem "danger"
|
|
10
9
|
gem "danger-rubocop"
|
|
11
|
-
gem "guard"
|
|
12
|
-
gem "guard-rspec"
|
|
13
|
-
gem "listen"
|
|
10
|
+
gem "guard"
|
|
11
|
+
gem "guard-rspec"
|
|
12
|
+
gem "listen"
|
|
14
13
|
gem "pry"
|
|
15
|
-
gem "rake"
|
|
16
|
-
gem "rspec"
|
|
14
|
+
gem "rake"
|
|
15
|
+
gem "rspec"
|
|
17
16
|
gem "rubocop"
|
|
18
17
|
gem "yard"
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
danger-periphery (0.1.0)
|
|
5
|
+
danger-plugin-api (~> 1.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.8.0)
|
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
12
|
+
ast (2.4.2)
|
|
13
|
+
claide (1.0.3)
|
|
14
|
+
claide-plugins (0.9.2)
|
|
15
|
+
cork
|
|
16
|
+
nap
|
|
17
|
+
open4 (~> 1.3)
|
|
18
|
+
coderay (1.1.3)
|
|
19
|
+
colored2 (3.1.2)
|
|
20
|
+
cork (0.3.0)
|
|
21
|
+
colored2 (~> 3.1)
|
|
22
|
+
danger (8.4.0)
|
|
23
|
+
claide (~> 1.0)
|
|
24
|
+
claide-plugins (>= 0.9.2)
|
|
25
|
+
colored2 (~> 3.1)
|
|
26
|
+
cork (~> 0.1)
|
|
27
|
+
faraday (>= 0.9.0, < 2.0)
|
|
28
|
+
faraday-http-cache (~> 2.0)
|
|
29
|
+
git (~> 1.7)
|
|
30
|
+
kramdown (~> 2.3)
|
|
31
|
+
kramdown-parser-gfm (~> 1.0)
|
|
32
|
+
no_proxy_fix
|
|
33
|
+
octokit (~> 4.7)
|
|
34
|
+
terminal-table (>= 1, < 4)
|
|
35
|
+
danger-plugin-api (1.0.0)
|
|
36
|
+
danger (> 2.0)
|
|
37
|
+
danger-rubocop (0.9.5)
|
|
38
|
+
danger
|
|
39
|
+
rubocop (~> 1.0)
|
|
40
|
+
diff-lcs (1.5.0)
|
|
41
|
+
faraday (1.8.0)
|
|
42
|
+
faraday-em_http (~> 1.0)
|
|
43
|
+
faraday-em_synchrony (~> 1.0)
|
|
44
|
+
faraday-excon (~> 1.1)
|
|
45
|
+
faraday-httpclient (~> 1.0.1)
|
|
46
|
+
faraday-net_http (~> 1.0)
|
|
47
|
+
faraday-net_http_persistent (~> 1.1)
|
|
48
|
+
faraday-patron (~> 1.0)
|
|
49
|
+
faraday-rack (~> 1.0)
|
|
50
|
+
multipart-post (>= 1.2, < 3)
|
|
51
|
+
ruby2_keywords (>= 0.0.4)
|
|
52
|
+
faraday-em_http (1.0.0)
|
|
53
|
+
faraday-em_synchrony (1.0.0)
|
|
54
|
+
faraday-excon (1.1.0)
|
|
55
|
+
faraday-http-cache (2.2.0)
|
|
56
|
+
faraday (>= 0.8)
|
|
57
|
+
faraday-httpclient (1.0.1)
|
|
58
|
+
faraday-net_http (1.0.1)
|
|
59
|
+
faraday-net_http_persistent (1.2.0)
|
|
60
|
+
faraday-patron (1.0.0)
|
|
61
|
+
faraday-rack (1.0.0)
|
|
62
|
+
ffi (1.15.5)
|
|
63
|
+
formatador (1.1.0)
|
|
64
|
+
git (1.9.1)
|
|
65
|
+
rchardet (~> 1.8)
|
|
66
|
+
guard (2.18.0)
|
|
67
|
+
formatador (>= 0.2.4)
|
|
68
|
+
listen (>= 2.7, < 4.0)
|
|
69
|
+
lumberjack (>= 1.0.12, < 2.0)
|
|
70
|
+
nenv (~> 0.1)
|
|
71
|
+
notiffany (~> 0.0)
|
|
72
|
+
pry (>= 0.13.0)
|
|
73
|
+
shellany (~> 0.0)
|
|
74
|
+
thor (>= 0.18.1)
|
|
75
|
+
guard-compat (1.2.1)
|
|
76
|
+
guard-rspec (4.7.3)
|
|
77
|
+
guard (~> 2.1)
|
|
78
|
+
guard-compat (~> 1.1)
|
|
79
|
+
rspec (>= 2.99.0, < 4.0)
|
|
80
|
+
kramdown (2.3.1)
|
|
81
|
+
rexml
|
|
82
|
+
kramdown-parser-gfm (1.1.0)
|
|
83
|
+
kramdown (~> 2.0)
|
|
84
|
+
listen (3.7.1)
|
|
85
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
86
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
|
87
|
+
lumberjack (1.2.8)
|
|
88
|
+
method_source (1.0.0)
|
|
89
|
+
multipart-post (2.1.1)
|
|
90
|
+
nap (1.1.0)
|
|
91
|
+
nenv (0.3.0)
|
|
92
|
+
no_proxy_fix (0.1.2)
|
|
93
|
+
notiffany (0.1.3)
|
|
94
|
+
nenv (~> 0.1)
|
|
95
|
+
shellany (~> 0.0)
|
|
96
|
+
octokit (4.21.0)
|
|
97
|
+
faraday (>= 0.9)
|
|
98
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
|
99
|
+
open4 (1.3.4)
|
|
100
|
+
parallel (1.21.0)
|
|
101
|
+
parser (3.0.2.0)
|
|
102
|
+
ast (~> 2.4.1)
|
|
103
|
+
pry (0.14.1)
|
|
104
|
+
coderay (~> 1.1)
|
|
105
|
+
method_source (~> 1.0)
|
|
106
|
+
public_suffix (4.0.6)
|
|
107
|
+
rainbow (3.0.0)
|
|
108
|
+
rake (13.0.6)
|
|
109
|
+
rb-fsevent (0.11.0)
|
|
110
|
+
rb-inotify (0.10.1)
|
|
111
|
+
ffi (~> 1.0)
|
|
112
|
+
rchardet (1.8.0)
|
|
113
|
+
regexp_parser (2.1.1)
|
|
114
|
+
rexml (3.2.5)
|
|
115
|
+
rspec (3.10.0)
|
|
116
|
+
rspec-core (~> 3.10.0)
|
|
117
|
+
rspec-expectations (~> 3.10.0)
|
|
118
|
+
rspec-mocks (~> 3.10.0)
|
|
119
|
+
rspec-core (3.10.2)
|
|
120
|
+
rspec-support (~> 3.10.0)
|
|
121
|
+
rspec-expectations (3.10.2)
|
|
122
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
123
|
+
rspec-support (~> 3.10.0)
|
|
124
|
+
rspec-mocks (3.10.3)
|
|
125
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
126
|
+
rspec-support (~> 3.10.0)
|
|
127
|
+
rspec-support (3.10.3)
|
|
128
|
+
rubocop (1.22.1)
|
|
129
|
+
parallel (~> 1.10)
|
|
130
|
+
parser (>= 3.0.0.0)
|
|
131
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
132
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
133
|
+
rexml
|
|
134
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
|
135
|
+
ruby-progressbar (~> 1.7)
|
|
136
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
137
|
+
rubocop-ast (1.12.0)
|
|
138
|
+
parser (>= 3.0.1.1)
|
|
139
|
+
ruby-progressbar (1.11.0)
|
|
140
|
+
ruby2_keywords (0.0.5)
|
|
141
|
+
sawyer (0.8.2)
|
|
142
|
+
addressable (>= 2.3.5)
|
|
143
|
+
faraday (> 0.8, < 2.0)
|
|
144
|
+
shellany (0.0.1)
|
|
145
|
+
terminal-table (3.0.2)
|
|
146
|
+
unicode-display_width (>= 1.1.1, < 3)
|
|
147
|
+
thor (1.2.1)
|
|
148
|
+
unicode-display_width (2.1.0)
|
|
149
|
+
yard (0.9.26)
|
|
150
|
+
|
|
151
|
+
PLATFORMS
|
|
152
|
+
ruby
|
|
153
|
+
universal-darwin-20
|
|
154
|
+
|
|
155
|
+
DEPENDENCIES
|
|
156
|
+
bundler (~> 2.0)
|
|
157
|
+
danger
|
|
158
|
+
danger-periphery!
|
|
159
|
+
danger-rubocop
|
|
160
|
+
guard
|
|
161
|
+
guard-rspec
|
|
162
|
+
listen
|
|
163
|
+
pry
|
|
164
|
+
rake
|
|
165
|
+
rspec
|
|
166
|
+
rubocop
|
|
167
|
+
yard
|
|
168
|
+
|
|
169
|
+
BUNDLED WITH
|
|
170
|
+
2.3.6
|
data/Guardfile
CHANGED
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
module ::Guard
|
|
4
|
+
class Periphery < Plugin
|
|
5
|
+
def initialize(options = {})
|
|
6
|
+
opts = options.dup
|
|
7
|
+
@project = opts.delete(:project)
|
|
8
|
+
@targets = opts.delete(:targets)
|
|
9
|
+
@schemes = opts.delete(:schemes)
|
|
10
|
+
super(opts)
|
|
11
|
+
end
|
|
5
12
|
|
|
6
|
-
|
|
13
|
+
def run_on_modifications(_paths)
|
|
14
|
+
command = %W(
|
|
15
|
+
bin/periphery scan
|
|
16
|
+
--project '#{@project}'
|
|
17
|
+
--targets '#{@targets}'
|
|
18
|
+
--schemes '#{@schemes}'
|
|
19
|
+
--format checkstyle
|
|
20
|
+
).join(" ")
|
|
21
|
+
puts(command)
|
|
22
|
+
system(command)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
7
26
|
|
|
8
27
|
guard :rspec, cmd: "bundle exec rspec" do
|
|
9
28
|
require "guard/rspec/dsl"
|
|
10
29
|
dsl = Guard::RSpec::Dsl.new(self)
|
|
11
30
|
|
|
12
|
-
# RSpec files
|
|
13
31
|
rspec = dsl.rspec
|
|
14
32
|
watch(rspec.spec_helper) { rspec.spec_dir }
|
|
15
33
|
watch(rspec.spec_support) { rspec.spec_dir }
|
|
16
34
|
watch(rspec.spec_files)
|
|
17
35
|
|
|
18
|
-
# Ruby files
|
|
19
36
|
ruby = dsl.ruby
|
|
20
37
|
dsl.watch_spec_files_for(ruby.lib_files)
|
|
21
38
|
end
|
|
39
|
+
|
|
40
|
+
guard :periphery, project: "spec/support/fixtures/test.xcodeproj", targets: "test", schemes: "test" do
|
|
41
|
+
watch("spec/support/fixtures/test/main.swift")
|
|
42
|
+
end
|
data/README.md
CHANGED
|
@@ -1,36 +1,75 @@
|
|
|
1
1
|
# danger-periphery
|
|
2
2
|
|
|
3
|
+
[](https://github.com/manicmaniac/danger-periphery/actions/workflows/test.yml)
|
|
4
|
+
|
|
3
5
|
A Danger plugin to detect unused codes.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
You need to install [Periphery](https://github.com/peripheryapp/periphery) beforehand.
|
|
8
10
|
|
|
9
|
-
Currently `danger-periphery` is in early development stage so it's not published to rubygems.org yet.
|
|
10
|
-
|
|
11
11
|
Write the following code in your Gemfile.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```ruby
|
|
14
|
+
gem "danger-periphery"
|
|
15
|
+
```
|
|
14
16
|
|
|
15
17
|
## Usage
|
|
16
18
|
|
|
17
19
|
If you already have `.periphery.yml`, the easiest way to use is just add this to your Dangerfile.
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
```ruby
|
|
22
|
+
periphery.scan
|
|
23
|
+
```
|
|
20
24
|
|
|
21
25
|
You can specify the path to executable in this way.
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
```ruby
|
|
28
|
+
periphery.binary_path = "bin/periphery"
|
|
29
|
+
```
|
|
24
30
|
|
|
25
31
|
You can pass command line options to `periphery.scan` like the following.
|
|
26
32
|
See `periphery scan -h` for available options.
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
```ruby
|
|
35
|
+
periphery.scan(
|
|
36
|
+
project: "Foo.xcodeproj",
|
|
37
|
+
schemes: ["foo", "bar"],
|
|
38
|
+
targets: "foo",
|
|
39
|
+
clean_build: true
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Advanced Usage
|
|
44
|
+
|
|
45
|
+
You can modify warnings as you like by passing a block to `process_warnings`.
|
|
46
|
+
`process_warnings` takes a block that receives `[path, line, column, message]` as arguments and returns one of the following types.
|
|
47
|
+
|
|
48
|
+
- `Array` that exactly contains `[path, line, column, message]`
|
|
49
|
+
- `true`
|
|
50
|
+
- `false`
|
|
51
|
+
- `nil`
|
|
52
|
+
|
|
53
|
+
If an `Array` is returned, danger-periphery uses the values in an array instead of the raw result produced by Periphery.
|
|
54
|
+
`true` has the same meaning as `[path, line, column, message]`, the argument array as-is.
|
|
55
|
+
|
|
56
|
+
If it returns `false` or `nil`, the processing warning will be suppressed.
|
|
57
|
+
|
|
58
|
+
For example, if you want your team members to be careful with warnings, the following code may work.
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
periphery.process_warnings do |path, line, column, message|
|
|
62
|
+
[path, line, column, "Pay attention please! #{message}"]
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or if you want to suppress all `unused` warnings, to return `nil` or `false` in the block works.
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
periphery.process_warnings do |path, line, column, message|
|
|
70
|
+
!message.match(/unused/i)
|
|
71
|
+
end
|
|
72
|
+
```
|
|
34
73
|
|
|
35
74
|
## Development
|
|
36
75
|
|
data/Rakefile
CHANGED
|
@@ -8,16 +8,10 @@ RSpec::Core::RakeTask.new(:specs)
|
|
|
8
8
|
|
|
9
9
|
task default: :specs
|
|
10
10
|
|
|
11
|
-
task :
|
|
12
|
-
Rake::Task["specs"].invoke
|
|
13
|
-
Rake::Task["rubocop"].invoke
|
|
14
|
-
Rake::Task["spec_docs"].invoke
|
|
15
|
-
end
|
|
11
|
+
task spec: %i(specs rubocop spec_docs)
|
|
16
12
|
|
|
17
13
|
desc "Run RuboCop on the lib/specs directory"
|
|
18
|
-
RuboCop::RakeTask.new(:rubocop)
|
|
19
|
-
task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
|
|
20
|
-
end
|
|
14
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
21
15
|
|
|
22
16
|
desc "Ensure that the plugin passes `danger plugins lint`"
|
|
23
17
|
task :spec_docs do
|
data/danger-periphery.gemspec
CHANGED
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
|
13
13
|
spec.summary = spec.description
|
|
14
14
|
spec.homepage = "https://github.com/manicmaniac/danger-periphery"
|
|
15
15
|
spec.license = "MIT"
|
|
16
|
-
spec.required_ruby_version = ">= 2.
|
|
16
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
17
17
|
|
|
18
18
|
spec.files = `git ls-files`.split($/)
|
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/lib/danger_plugin.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "periphery
|
|
4
|
-
require "periphery/scan_log_parser"
|
|
3
|
+
require "periphery"
|
|
5
4
|
|
|
6
5
|
module Danger
|
|
7
6
|
# Analyze Swift files and detect unused codes in your project.
|
|
@@ -24,6 +23,32 @@ module Danger
|
|
|
24
23
|
# @return [String]
|
|
25
24
|
attr_accessor :binary_path
|
|
26
25
|
|
|
26
|
+
# Proc object to process each warnings just before showing them.
|
|
27
|
+
# The Proc must receive 4 arguments: path, line, column, message
|
|
28
|
+
# and return one of:
|
|
29
|
+
# - an array that contains 4 elements [path, line, column, message]
|
|
30
|
+
# - true
|
|
31
|
+
# - false
|
|
32
|
+
# - nil
|
|
33
|
+
# If Proc returns an array, the warning will be raised based on returned elements.
|
|
34
|
+
# If Proc returns true, the warning will not be modified.
|
|
35
|
+
# If Proc returns false or nil, the warning will be ignored.
|
|
36
|
+
#
|
|
37
|
+
# By default the Proc returns true.
|
|
38
|
+
# @return [Proc]
|
|
39
|
+
attr_accessor :postprocessor
|
|
40
|
+
|
|
41
|
+
OPTION_OVERRIDES = {
|
|
42
|
+
disable_update_check: true,
|
|
43
|
+
format: "checkstyle",
|
|
44
|
+
quiet: true
|
|
45
|
+
}.freeze
|
|
46
|
+
|
|
47
|
+
def initialize(dangerfile)
|
|
48
|
+
super(dangerfile)
|
|
49
|
+
@postprocessor = ->(path, line, column, message) { true }
|
|
50
|
+
end
|
|
51
|
+
|
|
27
52
|
# Scans Swift files.
|
|
28
53
|
# Raises an error when Periphery executable is not found.
|
|
29
54
|
#
|
|
@@ -35,12 +60,27 @@ module Danger
|
|
|
35
60
|
# 5. Override some options like --disable-update-check, --format, --quiet and so.
|
|
36
61
|
# @return [void]
|
|
37
62
|
def scan(**options)
|
|
38
|
-
output = Periphery::Runner.new(binary_path).scan(options.merge(
|
|
39
|
-
entries = Periphery::ScanLogParser.new.parse(output)
|
|
63
|
+
output = Periphery::Runner.new(binary_path).scan(options.merge(OPTION_OVERRIDES))
|
|
40
64
|
files = files_in_diff
|
|
41
|
-
|
|
65
|
+
Periphery::CheckstyleParser.new.parse(output).
|
|
66
|
+
lazy.
|
|
42
67
|
select { |entry| files.include?(entry.path) }.
|
|
43
|
-
|
|
68
|
+
map { |entry| postprocess(entry) }.
|
|
69
|
+
force.
|
|
70
|
+
compact.
|
|
71
|
+
each { |path, line, column, message| warn(message, file: path, line: line) }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Convenience method to set `postprocessor` with block.
|
|
75
|
+
#
|
|
76
|
+
# @return [Proc]
|
|
77
|
+
#
|
|
78
|
+
# @example Ignore all warnings from files matching regular expression
|
|
79
|
+
# periphery.process_warnings do |path, line, column, message|
|
|
80
|
+
# !path.match(/.*\/generated\.swift/)
|
|
81
|
+
# end
|
|
82
|
+
def process_warnings(&block)
|
|
83
|
+
@postprocessor = block
|
|
44
84
|
end
|
|
45
85
|
|
|
46
86
|
private
|
|
@@ -51,5 +91,18 @@ module Danger
|
|
|
51
91
|
post_rename_modified_files = git.modified_files.map { |modified_file| renamed_files_hash[modified_file] || modified_file }
|
|
52
92
|
(post_rename_modified_files - git.deleted_files) + git.added_files
|
|
53
93
|
end
|
|
94
|
+
|
|
95
|
+
def postprocess(entry)
|
|
96
|
+
result = @postprocessor.call(entry.path, entry.line, entry.column, entry.message)
|
|
97
|
+
if !result
|
|
98
|
+
nil
|
|
99
|
+
elsif result.kind_of?(TrueClass)
|
|
100
|
+
[entry.path, entry.line, entry.column, entry.message]
|
|
101
|
+
elsif result.kind_of?(Array) && result.size == 4
|
|
102
|
+
result
|
|
103
|
+
else
|
|
104
|
+
raise "Proc passed to postprocessor must return one of nil, true, false and Array that includes 4 elements."
|
|
105
|
+
end
|
|
106
|
+
end
|
|
54
107
|
end
|
|
55
108
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pathname"
|
|
4
|
+
require "periphery/scan_result"
|
|
5
|
+
require "rexml/parsers/baseparser"
|
|
6
|
+
require "rexml/parsers/streamparser"
|
|
7
|
+
require "rexml/streamlistener"
|
|
8
|
+
|
|
9
|
+
module Periphery
|
|
10
|
+
class CheckstyleParser
|
|
11
|
+
class Listener
|
|
12
|
+
include REXML::StreamListener
|
|
13
|
+
|
|
14
|
+
attr_reader :results
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
@current_file = nil
|
|
18
|
+
@results = []
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def tag_start(name, attrs)
|
|
22
|
+
case name
|
|
23
|
+
when "file"
|
|
24
|
+
@current_file = relative_path(attrs["name"])
|
|
25
|
+
when "error"
|
|
26
|
+
if @current_file
|
|
27
|
+
@results << ScanResult.new(
|
|
28
|
+
@current_file,
|
|
29
|
+
attrs["line"].to_i,
|
|
30
|
+
attrs["column"].to_i,
|
|
31
|
+
attrs["message"]
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def tag_end(name)
|
|
38
|
+
@current_file = nil if name == "file"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def relative_path(path, base = Pathname.getwd)
|
|
44
|
+
Pathname.new(path).relative_path_from(base).to_s
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def parse(string)
|
|
49
|
+
listener = Listener.new
|
|
50
|
+
REXML::Parsers::StreamParser.new(string, listener).parse
|
|
51
|
+
listener.results
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/periphery/runner.rb
CHANGED
|
@@ -13,17 +13,21 @@ module Periphery
|
|
|
13
13
|
def scan(options)
|
|
14
14
|
arguments = [binary_path, "scan"] + scan_arguments(options)
|
|
15
15
|
stdout, stderr, status = Open3.capture3(*arguments)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if status.success?
|
|
17
|
+
stdout
|
|
18
|
+
else
|
|
19
|
+
raise "error: #{arguments} exited with status code #{status.exitstatus}. #{stderr}" unless status.success?
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def scan_arguments(options)
|
|
22
24
|
options.
|
|
25
|
+
lazy.
|
|
23
26
|
select { |_key, value| value }.
|
|
24
27
|
map { |key, value| value.kind_of?(TrueClass) ? [key, nil] : [key, value] }.
|
|
25
28
|
map { |key, value| value.kind_of?(Array) ? [key, value.join(",")] : [key, value] }.
|
|
26
|
-
map { |key, value| ["--#{key.to_s.tr('_', '-')}", value] }.
|
|
29
|
+
map { |key, value| ["--#{key.to_s.tr('_', '-')}", value&.to_s] }.
|
|
30
|
+
force.
|
|
27
31
|
flatten.
|
|
28
32
|
compact
|
|
29
33
|
end
|
data/lib/periphery.rb
ADDED
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
|
@@ -1,87 +1,145 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
describe Danger::DangerPeriphery do
|
|
4
|
+
include DangerPluginHelper
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
it "should be a plugin" do
|
|
7
|
+
expect(Danger::DangerPeriphery.new(nil)).to be_a Danger::Plugin
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "with Dangerfile" do
|
|
11
|
+
let(:dangerfile) { testing_dangerfile }
|
|
12
|
+
let(:periphery) { dangerfile.periphery }
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
periphery.binary_path = binary("periphery")
|
|
16
|
+
json = File.read("#{File.dirname(__FILE__)}/support/fixtures/github_pr.json") # example json: `curl https://api.github.com/repos/danger/danger-plugin-template/pulls/18 > github_pr.json`
|
|
17
|
+
allow(periphery.github).to receive(:pr_json).and_return(json)
|
|
18
|
+
allow(Pathname).to receive(:getwd).and_return fixtures_path
|
|
9
19
|
end
|
|
10
20
|
|
|
11
|
-
context "
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
context "when periphery is not installed" do
|
|
22
|
+
before { periphery.binary_path = "not_installed" }
|
|
23
|
+
|
|
24
|
+
it "fails with error" do
|
|
25
|
+
expect { periphery.scan }.to raise_error Errno::ENOENT
|
|
26
|
+
end
|
|
27
|
+
end
|
|
14
28
|
|
|
29
|
+
context "when .swift files not in diff" do
|
|
15
30
|
before do
|
|
16
|
-
periphery.
|
|
17
|
-
|
|
18
|
-
allow(periphery.
|
|
19
|
-
allow(
|
|
31
|
+
allow(periphery.git).to receive(:renamed_files).and_return []
|
|
32
|
+
allow(periphery.git).to receive(:modified_files).and_return []
|
|
33
|
+
allow(periphery.git).to receive(:deleted_files).and_return []
|
|
34
|
+
allow(periphery.git).to receive(:added_files).and_return []
|
|
20
35
|
end
|
|
21
36
|
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
it "reports nothing" do
|
|
38
|
+
periphery.scan(
|
|
39
|
+
project: fixture("test.xcodeproj"),
|
|
40
|
+
targets: "test",
|
|
41
|
+
schemes: "test"
|
|
42
|
+
)
|
|
24
43
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
expect(dangerfile.status_report[:warnings]).to be_empty
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "when .swift files were added" do
|
|
49
|
+
before do
|
|
50
|
+
allow(periphery.git).to receive(:renamed_files).and_return []
|
|
51
|
+
allow(periphery.git).to receive(:modified_files).and_return []
|
|
52
|
+
allow(periphery.git).to receive(:deleted_files).and_return []
|
|
53
|
+
allow(periphery.git).to receive(:added_files).and_return ["test/main.swift"]
|
|
28
54
|
end
|
|
29
55
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
end
|
|
56
|
+
it "reports unused code" do
|
|
57
|
+
periphery.scan(
|
|
58
|
+
project: fixture("test.xcodeproj"),
|
|
59
|
+
targets: "test",
|
|
60
|
+
schemes: "test"
|
|
61
|
+
)
|
|
37
62
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
targets: "test",
|
|
42
|
-
schemes: "test"
|
|
43
|
-
)
|
|
63
|
+
expect(dangerfile.status_report[:warnings]).to include "Function 'unusedMethod()' is unused"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
44
66
|
|
|
45
|
-
|
|
67
|
+
context "when .swift files were modified" do
|
|
68
|
+
before do
|
|
69
|
+
allow(periphery.git).to receive(:renamed_files).and_return []
|
|
70
|
+
allow(periphery.git).to receive(:modified_files).and_return ["test/main.swift"]
|
|
71
|
+
allow(periphery.git).to receive(:deleted_files).and_return []
|
|
72
|
+
allow(periphery.git).to receive(:added_files).and_return []
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "reports unused code" do
|
|
76
|
+
periphery.scan(
|
|
77
|
+
project: fixture("test.xcodeproj"),
|
|
78
|
+
targets: "test",
|
|
79
|
+
schemes: "test"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
expect(dangerfile.status_report[:warnings]).to include "Function 'unusedMethod()' is unused"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "#postprocessor" do
|
|
87
|
+
subject { dangerfile.status_report[:warnings] }
|
|
88
|
+
|
|
89
|
+
before do
|
|
90
|
+
allow(periphery.git).to receive(:renamed_files).and_return []
|
|
91
|
+
allow(periphery.git).to receive(:modified_files).and_return ["test/main.swift"]
|
|
92
|
+
allow(periphery.git).to receive(:deleted_files).and_return []
|
|
93
|
+
allow(periphery.git).to receive(:added_files).and_return []
|
|
94
|
+
periphery.postprocessor = postprocessor
|
|
95
|
+
periphery.scan(
|
|
96
|
+
project: fixture("test.xcodeproj"),
|
|
97
|
+
targets: "test",
|
|
98
|
+
schemes: "test"
|
|
99
|
+
)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context "when returns nil" do
|
|
103
|
+
let(:postprocessor) { ->(path, line, column, message) {} }
|
|
104
|
+
|
|
105
|
+
it "does not report warnings" do
|
|
106
|
+
expect(subject).to be_empty
|
|
46
107
|
end
|
|
47
108
|
end
|
|
48
109
|
|
|
49
|
-
context "when
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
allow(periphery.git).to receive(:added_files).and_return ["test/main.swift"]
|
|
110
|
+
context "when returns false" do
|
|
111
|
+
let(:postprocessor) { ->(path, line, column, message) { false } }
|
|
112
|
+
|
|
113
|
+
it "does not report warnings" do
|
|
114
|
+
expect(subject).to be_empty
|
|
55
115
|
end
|
|
116
|
+
end
|
|
56
117
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
project: fixture("test.xcodeproj"),
|
|
60
|
-
targets: "test",
|
|
61
|
-
schemes: "test"
|
|
62
|
-
)
|
|
118
|
+
context "when returns true" do
|
|
119
|
+
let(:postprocessor) { ->(path, line, column, message) { true } }
|
|
63
120
|
|
|
64
|
-
|
|
121
|
+
it "reports warnings" do
|
|
122
|
+
expect(subject).to include "Function 'unusedMethod()' is unused"
|
|
65
123
|
end
|
|
66
124
|
end
|
|
67
125
|
|
|
68
|
-
context "when
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
allow(periphery.git).to receive(:modified_files).and_return ["test/main.swift"]
|
|
72
|
-
allow(periphery.git).to receive(:deleted_files).and_return []
|
|
73
|
-
allow(periphery.git).to receive(:added_files).and_return []
|
|
126
|
+
context "when returns a modified array" do
|
|
127
|
+
let(:postprocessor) do
|
|
128
|
+
->(path, line, column, message) { [path, line, column, message.gsub(/Function/, "Foobar")] }
|
|
74
129
|
end
|
|
75
130
|
|
|
76
|
-
it "reports
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
131
|
+
it "reports modified warnings" do
|
|
132
|
+
expect(subject).to include "Foobar 'unusedMethod()' is unused"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
82
136
|
|
|
83
|
-
|
|
137
|
+
describe "#process_warnings" do
|
|
138
|
+
it "sets postprocessor" do
|
|
139
|
+
periphery.process_warnings do |path, line, column, message|
|
|
140
|
+
nil
|
|
84
141
|
end
|
|
142
|
+
expect { periphery.process_warnings { |*args| nil } }.to(change { periphery.postprocessor })
|
|
85
143
|
end
|
|
86
144
|
end
|
|
87
145
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
describe Periphery::CheckstyleParser do
|
|
4
|
+
subject(:parser) { described_class.new }
|
|
5
|
+
|
|
6
|
+
describe "#parse" do
|
|
7
|
+
subject { parser.parse(string) }
|
|
8
|
+
|
|
9
|
+
context "with vaild checkstyle xml" do
|
|
10
|
+
let(:string) do
|
|
11
|
+
<<~LOG
|
|
12
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
13
|
+
<checkstyle version="4.3">
|
|
14
|
+
<file name="/Users/manicmaniac/danger-periphery/main.swift">
|
|
15
|
+
<error line="1" column="1" severity="warning" message="Typealias 'UnusedTypeAlias' is unused"/>
|
|
16
|
+
<error line="2" column="1" severity="warning" message="Class 'UnusedClass' is unused"/>
|
|
17
|
+
<error line="3" column="1" severity="warning" message="Protocol 'UnusedProtocol' is unused"/>
|
|
18
|
+
</file>
|
|
19
|
+
</checkstyle>
|
|
20
|
+
LOG
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
before { allow(Pathname).to receive(:getwd).and_return Pathname.new("/Users/manicmaniac/danger-periphery") }
|
|
24
|
+
|
|
25
|
+
it "parses all warnings" do
|
|
26
|
+
expect(subject).to eq [
|
|
27
|
+
Periphery::ScanResult.new("main.swift", 1, 1, "Typealias 'UnusedTypeAlias' is unused"),
|
|
28
|
+
Periphery::ScanResult.new("main.swift", 2, 1, "Class 'UnusedClass' is unused"),
|
|
29
|
+
Periphery::ScanResult.new("main.swift", 3, 1, "Protocol 'UnusedProtocol' is unused")
|
|
30
|
+
]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -1,77 +1,115 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
describe Periphery::Runner do
|
|
4
|
+
subject(:runner) { described_class.new(binary_path) }
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
describe Runner do
|
|
7
|
-
subject(:runner) { described_class.new(binary_path) }
|
|
6
|
+
let(:binary_path) { binary("periphery") }
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
describe "#scan" do
|
|
9
|
+
subject { runner.scan(options) }
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
context "with valid args" do
|
|
12
|
+
let(:options) do
|
|
13
|
+
{
|
|
14
|
+
project: fixture("test.xcodeproj"),
|
|
15
|
+
targets: "test",
|
|
16
|
+
"schemes" => "test"
|
|
17
|
+
}
|
|
18
|
+
end
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
let(:command) do
|
|
21
|
+
[
|
|
22
|
+
binary_path,
|
|
23
|
+
"scan",
|
|
24
|
+
"--project",
|
|
25
|
+
fixture("test.xcodeproj"),
|
|
26
|
+
"--targets",
|
|
27
|
+
"test",
|
|
28
|
+
"--schemes",
|
|
29
|
+
"test"
|
|
30
|
+
]
|
|
31
|
+
end
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
it "runs scan without args" do
|
|
34
|
+
status = double(Process::Status, success?: true)
|
|
35
|
+
expect(Open3).to receive(:capture3).once.with(*command).and_return ["warning:", "", status]
|
|
36
|
+
expect(subject).to include "warning:"
|
|
26
37
|
end
|
|
27
38
|
end
|
|
39
|
+
end
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
describe "#scan_arguments" do
|
|
42
|
+
subject { runner.scan_arguments(options) }
|
|
31
43
|
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
context "with empty options" do
|
|
45
|
+
let(:options) { {} }
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
it { is_expected.to be_empty }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "with options that takes no argument" do
|
|
51
|
+
let(:options) do
|
|
52
|
+
{
|
|
53
|
+
clean_build: true,
|
|
54
|
+
skip_build: true
|
|
55
|
+
}
|
|
36
56
|
end
|
|
37
57
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
clean_build: true,
|
|
42
|
-
skip_build: true
|
|
43
|
-
}
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "returns correct arguments" do
|
|
47
|
-
expect(subject).to eq %w(--clean-build --skip-build)
|
|
48
|
-
end
|
|
58
|
+
it "returns correct arguments" do
|
|
59
|
+
expect(subject).to eq %w(--clean-build --skip-build)
|
|
49
60
|
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "with options that takes an argument" do
|
|
64
|
+
let(:options) do
|
|
65
|
+
{
|
|
66
|
+
project: "test.xcodeproj",
|
|
67
|
+
targets: "test1,test2"
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "returns correct arguments" do
|
|
72
|
+
expect(subject).to eq %w(--project test.xcodeproj --targets test1,test2)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "with options that takes an array as argument" do
|
|
77
|
+
let(:options) do
|
|
78
|
+
{
|
|
79
|
+
project: "test.xcodeproj",
|
|
80
|
+
targets: %w(test1 test2)
|
|
81
|
+
}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "returns correct arguments" do
|
|
85
|
+
expect(subject).to eq %w(--project test.xcodeproj --targets test1,test2)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context "with options passed as symbol" do
|
|
90
|
+
let(:options) do
|
|
91
|
+
{
|
|
92
|
+
project: "test.xcodeproj",
|
|
93
|
+
targets: :test
|
|
94
|
+
}
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "returns correct arguments" do
|
|
98
|
+
expect(subject).to eq %w(--project test.xcodeproj --targets test)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
50
101
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
it "returns correct arguments" do
|
|
60
|
-
expect(subject).to eq %w(--project test.xcodeproj --targets test1,test2)
|
|
61
|
-
end
|
|
102
|
+
context "with options passed as boolean" do
|
|
103
|
+
let(:options) do
|
|
104
|
+
{
|
|
105
|
+
project: "test.xcodeproj",
|
|
106
|
+
targets: "test",
|
|
107
|
+
clean_build: true
|
|
108
|
+
}
|
|
62
109
|
end
|
|
63
110
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
project: "test.xcodeproj",
|
|
68
|
-
targets: %w(test1 test2)
|
|
69
|
-
}
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "returns correct arguments" do
|
|
73
|
-
expect(subject).to eq %w(--project test.xcodeproj --targets test1,test2)
|
|
74
|
-
end
|
|
111
|
+
it "returns correct arguments" do
|
|
112
|
+
expect(subject).to eq %w(--project test.xcodeproj --targets test --clean-build)
|
|
75
113
|
end
|
|
76
114
|
end
|
|
77
115
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "pathname"
|
|
4
3
|
ROOT = Pathname.new(File.expand_path("..", __dir__))
|
|
5
|
-
$:.unshift("#{ROOT}lib".to_s)
|
|
6
|
-
$:.unshift("#{ROOT}spec".to_s)
|
|
4
|
+
$:.unshift("#{ROOT}lib".to_s, "#{ROOT}spec".to_s)
|
|
7
5
|
|
|
8
6
|
require "bundler/setup"
|
|
9
|
-
require "pry"
|
|
10
|
-
|
|
11
|
-
require "rspec"
|
|
12
7
|
require "danger"
|
|
13
|
-
|
|
14
|
-
if `git remote -v` == ""
|
|
15
|
-
puts "You cannot run tests without setting a local git remote on this repo"
|
|
16
|
-
puts "It's a weird side-effect of Danger's internals."
|
|
17
|
-
exit(0)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Use coloured output, it's the best.
|
|
21
|
-
RSpec.configure do |config|
|
|
22
|
-
config.filter_gems_from_backtrace "bundler"
|
|
23
|
-
config.color = true
|
|
24
|
-
config.tty = true
|
|
25
|
-
end
|
|
26
|
-
|
|
27
8
|
require "danger_plugin"
|
|
9
|
+
require "pry"
|
|
10
|
+
require "rspec"
|
|
28
11
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# A silent version of the user interface,
|
|
33
|
-
# it comes with an extra function `.string` which will
|
|
34
|
-
# strip all ANSI colours from the string.
|
|
35
|
-
|
|
36
|
-
# rubocop:disable Lint/NestedMethodDefinition
|
|
37
|
-
def testing_ui
|
|
38
|
-
@output = StringIO.new
|
|
39
|
-
def @output.winsize
|
|
40
|
-
[20, 9999]
|
|
12
|
+
module FixtureHelper
|
|
13
|
+
def fixtures_path
|
|
14
|
+
Pathname.new("../support/fixtures").expand_path(__FILE__)
|
|
41
15
|
end
|
|
42
16
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
|
17
|
+
def fixture(filename)
|
|
18
|
+
fixtures_path.join(filename).to_s
|
|
46
19
|
end
|
|
47
|
-
cork
|
|
48
|
-
end
|
|
49
|
-
# rubocop:enable Lint/NestedMethodDefinition
|
|
50
20
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
|
|
56
|
-
"TRAVIS_PULL_REQUEST" => "800",
|
|
57
|
-
"TRAVIS_REPO_SLUG" => "artsy/eigen",
|
|
58
|
-
"TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
|
|
59
|
-
"DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
|
|
60
|
-
}
|
|
61
|
-
end
|
|
21
|
+
def binaries_path
|
|
22
|
+
Pathname.new("../../bin").expand_path(__FILE__)
|
|
23
|
+
end
|
|
62
24
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Danger::Dangerfile.new(env, testing_ui)
|
|
25
|
+
def binary(filename)
|
|
26
|
+
binaries_path.join(filename).to_s
|
|
27
|
+
end
|
|
67
28
|
end
|
|
68
29
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
30
|
+
module DangerPluginHelper
|
|
31
|
+
def self.included(_module)
|
|
32
|
+
if `git remote -v` == ""
|
|
33
|
+
puts "You cannot run tests without setting a local git remote on this repo"
|
|
34
|
+
puts "It's a weird side-effect of Danger's internals."
|
|
35
|
+
exit(0)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
72
38
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
39
|
+
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
|
40
|
+
# If you are expanding these files, see if it's already been done ^.
|
|
41
|
+
|
|
42
|
+
# A silent version of the user interface,
|
|
43
|
+
# it comes with an extra function `.string` which will
|
|
44
|
+
# strip all ANSI colours from the string.
|
|
45
|
+
|
|
46
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
|
47
|
+
def testing_ui
|
|
48
|
+
@output = StringIO.new
|
|
49
|
+
def @output.winsize
|
|
50
|
+
[20, 9999]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
cork = Cork::Board.new(out: @output)
|
|
54
|
+
def cork.string
|
|
55
|
+
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
|
56
|
+
end
|
|
57
|
+
cork
|
|
58
|
+
end
|
|
59
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
|
60
|
+
|
|
61
|
+
# Example environment (ENV) that would come from
|
|
62
|
+
# running a PR on TravisCI
|
|
63
|
+
def testing_env
|
|
64
|
+
{
|
|
65
|
+
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
|
|
66
|
+
"TRAVIS_PULL_REQUEST" => "800",
|
|
67
|
+
"TRAVIS_REPO_SLUG" => "artsy/eigen",
|
|
68
|
+
"TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
|
|
69
|
+
"DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
|
|
70
|
+
}
|
|
71
|
+
end
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
# A stubbed out Dangerfile for use in tests
|
|
74
|
+
def testing_dangerfile
|
|
75
|
+
env = Danger::EnvironmentManager.new(testing_env)
|
|
76
|
+
Danger::Dangerfile.new(env, testing_ui)
|
|
77
|
+
end
|
|
79
78
|
end
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
RSpec.configure do |config|
|
|
81
|
+
config.filter_gems_from_backtrace "bundler"
|
|
82
|
+
config.include FixtureHelper
|
|
83
83
|
end
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
case unused
|
|
1
|
+
protocol RedundantProtocol {
|
|
3
2
|
}
|
|
3
|
+
|
|
4
|
+
class SomeClass: RedundantProtocol {
|
|
5
|
+
enum SomeEnum {
|
|
6
|
+
case usedCase
|
|
7
|
+
case unusedCase
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
var unusedProperty = 0
|
|
11
|
+
private var assignOnlyProperty = 0
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
public func methodWithRedundantPublicAccessibility(_ unusedParameter: Int) {
|
|
15
|
+
assignOnlyProperty = 0
|
|
16
|
+
_ = SomeEnum.usedCase
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func unusedMethod() {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
SomeClass().methodWithRedundantPublicAccessibility(0)
|
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.0
|
|
4
|
+
version: 0.1.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:
|
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: danger-plugin-api
|
|
@@ -39,6 +39,7 @@ files:
|
|
|
39
39
|
- ".rubocop.yml"
|
|
40
40
|
- Dangerfile
|
|
41
41
|
- Gemfile
|
|
42
|
+
- Gemfile.lock
|
|
42
43
|
- Guardfile
|
|
43
44
|
- LICENSE.txt
|
|
44
45
|
- README.md
|
|
@@ -46,12 +47,14 @@ files:
|
|
|
46
47
|
- bin/download_periphery
|
|
47
48
|
- danger-periphery.gemspec
|
|
48
49
|
- lib/danger_plugin.rb
|
|
50
|
+
- lib/periphery.rb
|
|
51
|
+
- lib/periphery/checkstyle_parser.rb
|
|
49
52
|
- lib/periphery/runner.rb
|
|
50
|
-
- lib/periphery/
|
|
53
|
+
- lib/periphery/scan_result.rb
|
|
51
54
|
- lib/version.rb
|
|
52
55
|
- spec/danger_plugin_spec.rb
|
|
56
|
+
- spec/periphery/checkstyle_parser_spec.rb
|
|
53
57
|
- spec/periphery/runner_spec.rb
|
|
54
|
-
- spec/periphery/scan_log_parser_spec.rb
|
|
55
58
|
- spec/spec_helper.rb
|
|
56
59
|
- spec/support/fixtures/github_pr.json
|
|
57
60
|
- spec/support/fixtures/test.xcodeproj/project.pbxproj
|
|
@@ -68,21 +71,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
68
71
|
requirements:
|
|
69
72
|
- - ">="
|
|
70
73
|
- !ruby/object:Gem::Version
|
|
71
|
-
version: 2.
|
|
74
|
+
version: 2.6.0
|
|
72
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
76
|
requirements:
|
|
74
77
|
- - ">="
|
|
75
78
|
- !ruby/object:Gem::Version
|
|
76
79
|
version: '0'
|
|
77
80
|
requirements: []
|
|
78
|
-
rubygems_version: 3.0.3
|
|
81
|
+
rubygems_version: 3.0.3.1
|
|
79
82
|
signing_key:
|
|
80
83
|
specification_version: 4
|
|
81
84
|
summary: A Danger plugin to detect unused codes.
|
|
82
85
|
test_files:
|
|
83
86
|
- spec/danger_plugin_spec.rb
|
|
87
|
+
- spec/periphery/checkstyle_parser_spec.rb
|
|
84
88
|
- spec/periphery/runner_spec.rb
|
|
85
|
-
- spec/periphery/scan_log_parser_spec.rb
|
|
86
89
|
- spec/spec_helper.rb
|
|
87
90
|
- spec/support/fixtures/github_pr.json
|
|
88
91
|
- spec/support/fixtures/test.xcodeproj/project.pbxproj
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Periphery
|
|
4
|
-
class ScanLogParser
|
|
5
|
-
def parse(string)
|
|
6
|
-
string.lines.map do |line|
|
|
7
|
-
match = line.match(/^(?<path>.+):(?<line>\d+):(?<column>\d+): warning: (?<message>.*)\n?$/)
|
|
8
|
-
ScanLogEntry.new(relative_path(match[:path]), match[:line].to_i, match[:column].to_i, match[:message]) if match
|
|
9
|
-
end.compact
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
def relative_path(path, base = Pathname.getwd)
|
|
15
|
-
Pathname.new(path).relative_path_from(base).to_s
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
ScanLogEntry = Struct.new(:path, :line, :column, :message)
|
|
20
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "periphery/scan_log_parser"
|
|
4
|
-
|
|
5
|
-
module Periphery
|
|
6
|
-
describe ScanLogParser do
|
|
7
|
-
describe "#parse" do
|
|
8
|
-
subject { described_class.new.parse(string) }
|
|
9
|
-
|
|
10
|
-
context "with empty string" do
|
|
11
|
-
let(:string) { "" }
|
|
12
|
-
|
|
13
|
-
it { is_expected.to be_empty }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context "with a valid string" do
|
|
17
|
-
let(:string) do
|
|
18
|
-
<<~LOG
|
|
19
|
-
* Inspecting project...
|
|
20
|
-
* Building danger-periphery...
|
|
21
|
-
* Indexing...
|
|
22
|
-
* Analyzing...
|
|
23
|
-
|
|
24
|
-
/Users/manicmaniac/danger-periphery/main.swift:1:1: warning: Typealias 'UnusedTypeAlias' is unused
|
|
25
|
-
/Users/manicmaniac/danger-periphery/main.swift:2:1: warning: Class 'UnusedClass' is unused
|
|
26
|
-
/Users/manicmaniac/danger-periphery/main.swift:3:1: warning: Protocol 'UnusedProtocol' is unused
|
|
27
|
-
|
|
28
|
-
* Seeing false positives?
|
|
29
|
-
- Periphery only analyzes files that are members of the targets you specify.
|
|
30
|
-
References to declarations identified as unused may reside in files that are members of other targets, e.g test targets.
|
|
31
|
-
- By default, Periphery does not assume that all public declarations are in use.
|
|
32
|
-
You can instruct it to do so with the --retain-public option.
|
|
33
|
-
- Periphery is a very precise tool, false positives often turn out to be correct after further investigation.
|
|
34
|
-
- If it really is a false positive, please report it - https://github.com/peripheryapp/periphery/issues.
|
|
35
|
-
LOG
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
before { allow(Pathname).to receive(:getwd).and_return Pathname.new("/Users/manicmaniac/danger-periphery") }
|
|
39
|
-
|
|
40
|
-
it "parses all warnings without garbages" do
|
|
41
|
-
expect(subject).to eq [
|
|
42
|
-
ScanLogEntry.new("main.swift", 1, 1, "Typealias 'UnusedTypeAlias' is unused"),
|
|
43
|
-
ScanLogEntry.new("main.swift", 2, 1, "Class 'UnusedClass' is unused"),
|
|
44
|
-
ScanLogEntry.new("main.swift", 3, 1, "Protocol 'UnusedProtocol' is unused")
|
|
45
|
-
]
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|