danger-periphery 0.2.0 → 0.2.1
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/lib/danger_plugin.rb +51 -29
- data/lib/periphery/checkstyle_parser.rb +12 -16
- data/lib/periphery/runner.rb +15 -18
- data/lib/periphery.rb +2 -2
- data/lib/version.rb +1 -1
- metadata +3 -26
- data/.github/workflows/lint.yml +0 -12
- data/.github/workflows/test.yml +0 -10
- data/.gitignore +0 -9
- data/.rspec +0 -3
- data/.rubocop.yml +0 -338
- data/Dangerfile +0 -14
- data/Gemfile +0 -17
- data/Gemfile.lock +0 -178
- data/Guardfile +0 -48
- data/LICENSE.txt +0 -22
- data/README.md +0 -106
- data/Rakefile +0 -19
- data/bin/download_periphery +0 -7
- data/danger-periphery.gemspec +0 -24
- data/spec/danger_plugin_spec.rb +0 -195
- data/spec/periphery/checkstyle_parser_spec.rb +0 -34
- data/spec/periphery/runner_spec.rb +0 -116
- data/spec/spec_helper.rb +0 -83
- data/spec/support/fixtures/github_pr.json +0 -381
- data/spec/support/fixtures/mock-periphery +0 -18
- data/spec/support/fixtures/test/main.swift +0 -23
- data/spec/support/fixtures/test.xcodeproj/project.pbxproj +0 -286
data/Rakefile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
require "rspec/core/rake_task"
|
5
|
-
require "rubocop/rake_task"
|
6
|
-
|
7
|
-
RSpec::Core::RakeTask.new(:specs)
|
8
|
-
|
9
|
-
task default: :specs
|
10
|
-
|
11
|
-
task spec: %i(specs rubocop spec_docs)
|
12
|
-
|
13
|
-
desc "Run RuboCop on the lib/specs directory"
|
14
|
-
RuboCop::RakeTask.new(:rubocop)
|
15
|
-
|
16
|
-
desc "Ensure that the plugin passes `danger plugins lint`"
|
17
|
-
task :spec_docs do
|
18
|
-
sh "danger plugins lint"
|
19
|
-
end
|
data/bin/download_periphery
DELETED
data/danger-periphery.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path("lib", __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require "version"
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = "danger-periphery"
|
9
|
-
spec.version = DangerPeriphery::VERSION
|
10
|
-
spec.authors = ["Ryosuke Ito"]
|
11
|
-
spec.email = ["rito.0305@gmail.com"]
|
12
|
-
spec.description = "A Danger plugin to detect unused codes."
|
13
|
-
spec.summary = spec.description
|
14
|
-
spec.homepage = "https://github.com/manicmaniac/danger-periphery"
|
15
|
-
spec.license = "MIT"
|
16
|
-
spec.required_ruby_version = ">= 2.6.0"
|
17
|
-
spec.metadata["rubygems_mfa_required"] = "true"
|
18
|
-
|
19
|
-
spec.files = `git ls-files`.split($/)
|
20
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.add_dependency "danger-plugin-api", "~> 1.0"
|
24
|
-
end
|
data/spec/danger_plugin_spec.rb
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe Danger::DangerPeriphery do
|
4
|
-
include DangerPluginHelper
|
5
|
-
|
6
|
-
let(:periphery_options) do
|
7
|
-
{
|
8
|
-
project: fixture("test.xcodeproj"),
|
9
|
-
targets: "test",
|
10
|
-
schemes: "test"
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be a plugin" do
|
15
|
-
expect(Danger::DangerPeriphery.new(nil)).to be_a Danger::Plugin
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with Dangerfile" do
|
19
|
-
let(:dangerfile) { testing_dangerfile }
|
20
|
-
let(:periphery) { dangerfile.periphery }
|
21
|
-
|
22
|
-
before do
|
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
|
27
|
-
allow(Pathname).to receive(:getwd).and_return fixtures_path
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when periphery is not installed" do
|
31
|
-
before { periphery.binary_path = "not_installed" }
|
32
|
-
|
33
|
-
it "fails with error" do
|
34
|
-
expect { periphery.scan }.to raise_error Errno::ENOENT
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
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
|
48
|
-
|
49
|
-
it "reports nothing" do
|
50
|
-
periphery.scan(periphery_options)
|
51
|
-
|
52
|
-
expect(dangerfile.status_report[:warnings]).to be_empty
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
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
|
69
|
-
end
|
70
|
-
|
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)
|
81
|
-
|
82
|
-
expect(dangerfile.status_report[:warnings]).to include "Function 'unusedMethod()' is unused"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "with block" do
|
88
|
-
subject { dangerfile.status_report[:warnings] }
|
89
|
-
|
90
|
-
before do
|
91
|
-
allow(periphery.git).to receive(:renamed_files).and_return []
|
92
|
-
allow(periphery.git).to receive(:modified_files).and_return ["test/main.swift"]
|
93
|
-
allow(periphery.git).to receive(:deleted_files).and_return []
|
94
|
-
allow(periphery.git).to receive(:added_files).and_return []
|
95
|
-
periphery.scan(periphery_options, &block)
|
96
|
-
end
|
97
|
-
|
98
|
-
context "that returns nil" do
|
99
|
-
let(:block) { ->(violation) {} }
|
100
|
-
|
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
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "#postprocessor" do
|
140
|
-
subject { dangerfile.status_report[:warnings] }
|
141
|
-
|
142
|
-
before do
|
143
|
-
allow(periphery.git).to receive(:renamed_files).and_return []
|
144
|
-
allow(periphery.git).to receive(:modified_files).and_return ["test/main.swift"]
|
145
|
-
allow(periphery.git).to receive(:deleted_files).and_return []
|
146
|
-
allow(periphery.git).to receive(:added_files).and_return []
|
147
|
-
periphery.postprocessor = postprocessor
|
148
|
-
periphery.scan(periphery_options)
|
149
|
-
end
|
150
|
-
|
151
|
-
context "when returns nil" do
|
152
|
-
let(:postprocessor) { ->(path, line, column, message) {} }
|
153
|
-
|
154
|
-
it "does not report warnings" do
|
155
|
-
expect(subject).to be_empty
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context "when returns false" do
|
160
|
-
let(:postprocessor) { ->(path, line, column, message) { false } }
|
161
|
-
|
162
|
-
it "does not report warnings" do
|
163
|
-
expect(subject).to be_empty
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context "when returns true" do
|
168
|
-
let(:postprocessor) { ->(path, line, column, message) { true } }
|
169
|
-
|
170
|
-
it "reports warnings" do
|
171
|
-
expect(subject).to include "Function 'unusedMethod()' is unused"
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context "when returns a modified array" do
|
176
|
-
let(:postprocessor) do
|
177
|
-
->(path, line, column, message) { [path, line, column, message.gsub(/Function/, "Foobar")] }
|
178
|
-
end
|
179
|
-
|
180
|
-
it "reports modified warnings" do
|
181
|
-
expect(subject).to include "Foobar 'unusedMethod()' is unused"
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
describe "#process_warnings" do
|
187
|
-
it "sets postprocessor" do
|
188
|
-
periphery.process_warnings do |path, line, column, message|
|
189
|
-
nil
|
190
|
-
end
|
191
|
-
expect { periphery.process_warnings { |*args| nil } }.to(change { periphery.postprocessor })
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
@@ -1,34 +0,0 @@
|
|
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,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe Periphery::Runner do
|
4
|
-
subject(:runner) { described_class.new(binary_path) }
|
5
|
-
|
6
|
-
let(:binary_path) { binary("periphery") }
|
7
|
-
|
8
|
-
describe "#scan" do
|
9
|
-
subject { runner.scan(options) }
|
10
|
-
|
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
|
19
|
-
|
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
|
32
|
-
|
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:"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#scan_arguments" do
|
42
|
-
subject { runner.scan_arguments(options) }
|
43
|
-
|
44
|
-
context "with empty options" do
|
45
|
-
let(:options) { {} }
|
46
|
-
|
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
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
it "returns correct arguments" do
|
59
|
-
expect(subject).to eq %w(--clean-build --skip-build)
|
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
|
101
|
-
|
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
|
-
}
|
109
|
-
end
|
110
|
-
|
111
|
-
it "returns correct arguments" do
|
112
|
-
expect(subject).to eq %w(--project test.xcodeproj --targets test --clean-build)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ROOT = Pathname.new(File.expand_path("..", __dir__))
|
4
|
-
$:.unshift("#{ROOT}lib".to_s, "#{ROOT}spec".to_s)
|
5
|
-
|
6
|
-
require "bundler/setup"
|
7
|
-
require "danger"
|
8
|
-
require "danger_plugin"
|
9
|
-
require "pry"
|
10
|
-
require "rspec"
|
11
|
-
|
12
|
-
module FixtureHelper
|
13
|
-
def fixtures_path
|
14
|
-
Pathname.new("support/fixtures").expand_path(__dir__)
|
15
|
-
end
|
16
|
-
|
17
|
-
def fixture(filename)
|
18
|
-
fixtures_path.join(filename).to_s
|
19
|
-
end
|
20
|
-
|
21
|
-
def binaries_path
|
22
|
-
Pathname.new("../bin").expand_path(__dir__)
|
23
|
-
end
|
24
|
-
|
25
|
-
def binary(filename)
|
26
|
-
binaries_path.join(filename).to_s
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
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
|
38
|
-
|
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
|
72
|
-
|
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
|
78
|
-
end
|
79
|
-
|
80
|
-
RSpec.configure do |config|
|
81
|
-
config.filter_gems_from_backtrace "bundler"
|
82
|
-
config.include FixtureHelper
|
83
|
-
end
|