danger-periphery 0.0.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in danger-periphery.gemspec
6
- gemspec
7
-
8
- gem "bundler", "~> 2.0"
9
- gem "danger"
10
- gem "danger-rubocop"
11
- gem "guard", "~> 2.14"
12
- gem "guard-rspec", "~> 4.7"
13
- gem "listen", "3.0.7"
14
- gem "pry"
15
- gem "rake", "~> 10.0"
16
- gem "rspec", "~> 3.4"
17
- gem "rubocop"
18
- gem "yard"
data/Guardfile DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # A guardfile for making Danger Plugins
4
- # For more info see https://github.com/guard/guard#readme
5
-
6
- # To run, use `bundle exec guard`.
7
-
8
- guard :rspec, cmd: "bundle exec rspec" do
9
- require "guard/rspec/dsl"
10
- dsl = Guard::RSpec::Dsl.new(self)
11
-
12
- # RSpec files
13
- rspec = dsl.rspec
14
- watch(rspec.spec_helper) { rspec.spec_dir }
15
- watch(rspec.spec_support) { rspec.spec_dir }
16
- watch(rspec.spec_files)
17
-
18
- # Ruby files
19
- ruby = dsl.ruby
20
- dsl.watch_spec_files_for(ruby.lib_files)
21
- end
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2021 Ryosuke Ito <rito.0305@gmail.com>
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,42 +0,0 @@
1
- # danger-periphery
2
-
3
- A Danger plugin to detect unused codes.
4
-
5
- ## Installation
6
-
7
- You need to install [Periphery](https://github.com/peripheryapp/periphery) beforehand.
8
-
9
- Currently `danger-periphery` is in early development stage so it's not published to rubygems.org yet.
10
-
11
- Write the following code in your Gemfile.
12
-
13
- gem "danger-periphery", git: "https://github.com/manicmaniac/danger-periphery.git"
14
-
15
- ## Usage
16
-
17
- If you already have `.periphery.yml`, the easiest way to use is just add this to your Dangerfile.
18
-
19
- periphery.scan
20
-
21
- You can specify the path to executable in this way.
22
-
23
- periphery.binary_path = "bin/periphery"
24
-
25
- You can pass command line options to `periphery.scan` like the following.
26
- See `periphery scan -h` for available options.
27
-
28
- periphery.scan(
29
- project: "Foo.xcodeproj",
30
- schemes: ["foo", "bar"],
31
- targets: "foo",
32
- clean_build: true
33
- )
34
-
35
- ## Development
36
-
37
- 1. Clone this repo
38
- 2. Run `bundle install` to setup dependencies.
39
- 3. Run `bin/download_periphery` to install Periphery.
40
- 4. Run `bundle exec rake spec` to run the tests.
41
- 5. Use `bundle exec guard` to automatically have tests run as you make changes.
42
- 6. Make your changes.
data/Rakefile DELETED
@@ -1,25 +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 do
12
- Rake::Task["specs"].invoke
13
- Rake::Task["rubocop"].invoke
14
- Rake::Task["spec_docs"].invoke
15
- end
16
-
17
- desc "Run RuboCop on the lib/specs directory"
18
- RuboCop::RakeTask.new(:rubocop) do |task|
19
- task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
20
- end
21
-
22
- desc "Ensure that the plugin passes `danger plugins lint`"
23
- task :spec_docs do
24
- sh "bundle exec danger plugins lint"
25
- end
@@ -1,7 +0,0 @@
1
- #!/bin/sh
2
-
3
- cd "$(dirname "$0")"
4
- version="2.8.1"
5
- curl -Lo periphery.zip "https://github.com/peripheryapp/periphery/releases/download/$version/periphery-v$version.zip"
6
- unzip periphery.zip
7
- rm periphery.zip LICENSE.md
@@ -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.3.0"
17
-
18
- spec.files = `git ls-files`.split($/)
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
- spec.require_paths = ["lib"]
22
-
23
- spec.add_dependency "danger-plugin-api", "~> 1.0"
24
- end
@@ -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,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("spec_helper", __dir__)
4
-
5
- module Danger
6
- describe Danger::DangerPeriphery do
7
- it "should be a plugin" do
8
- expect(Danger::DangerPeriphery.new(nil)).to be_a Danger::Plugin
9
- end
10
-
11
- context "with Dangerfile" do
12
- let(:dangerfile) { testing_dangerfile }
13
- let(:periphery) { dangerfile.periphery }
14
-
15
- before do
16
- periphery.binary_path = binary("periphery")
17
- 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`
18
- allow(periphery.github).to receive(:pr_json).and_return(json)
19
- allow(Pathname).to receive(:getwd).and_return fixtures_path
20
- end
21
-
22
- context "when periphery is not installed" do
23
- before { periphery.binary_path = "not_installed" }
24
-
25
- it "fails with error" do
26
- expect { periphery.scan }.to raise_error Errno::ENOENT
27
- end
28
- end
29
-
30
- context "when .swift files not in diff" do
31
- before do
32
- allow(periphery.git).to receive(:renamed_files).and_return []
33
- allow(periphery.git).to receive(:modified_files).and_return []
34
- allow(periphery.git).to receive(:deleted_files).and_return []
35
- allow(periphery.git).to receive(:added_files).and_return []
36
- end
37
-
38
- it "reports nothing" do
39
- periphery.scan(
40
- project: fixture("test.xcodeproj"),
41
- targets: "test",
42
- schemes: "test"
43
- )
44
-
45
- expect(dangerfile.status_report[:warnings]).to be_empty
46
- end
47
- end
48
-
49
- context "when .swift files were added" do
50
- before do
51
- allow(periphery.git).to receive(:renamed_files).and_return []
52
- allow(periphery.git).to receive(:modified_files).and_return []
53
- allow(periphery.git).to receive(:deleted_files).and_return []
54
- allow(periphery.git).to receive(:added_files).and_return ["test/main.swift"]
55
- end
56
-
57
- it "reports unused code" do
58
- periphery.scan(
59
- project: fixture("test.xcodeproj"),
60
- targets: "test",
61
- schemes: "test"
62
- )
63
-
64
- expect(dangerfile.status_report[:warnings]).to eq(["Enum 'UnusedEnum' is unused"])
65
- end
66
- end
67
-
68
- context "when .swift files were modified" do
69
- before do
70
- allow(periphery.git).to receive(:renamed_files).and_return []
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 []
74
- end
75
-
76
- it "reports unused code" do
77
- periphery.scan(
78
- project: fixture("test.xcodeproj"),
79
- targets: "test",
80
- schemes: "test"
81
- )
82
-
83
- expect(dangerfile.status_report[:warnings]).to eq(["Enum 'UnusedEnum' is unused"])
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "periphery/runner"
4
-
5
- module Periphery
6
- describe Runner do
7
- subject(:runner) { described_class.new(binary_path) }
8
-
9
- let(:binary_path) { binary("periphery") }
10
-
11
- describe "#scan" do
12
- subject { runner.scan(options) }
13
-
14
- context "with valid args" do
15
- let(:options) do
16
- {
17
- project: fixture("test.xcodeproj"),
18
- targets: "test",
19
- schemes: "test"
20
- }
21
- end
22
-
23
- it "runs scan without args" do
24
- expect(subject).to include "warning:"
25
- end
26
- end
27
- end
28
-
29
- describe "#scan_arguments" do
30
- subject { runner.scan_arguments(options) }
31
-
32
- context "with empty options" do
33
- let(:options) { {} }
34
-
35
- it { is_expected.to be_empty }
36
- end
37
-
38
- context "with options that takes no argument" do
39
- let(:options) do
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
49
- end
50
-
51
- context "with options that takes an argument" do
52
- let(:options) do
53
- {
54
- project: "test.xcodeproj",
55
- targets: "test1,test2"
56
- }
57
- end
58
-
59
- it "returns correct arguments" do
60
- expect(subject).to eq %w(--project test.xcodeproj --targets test1,test2)
61
- end
62
- end
63
-
64
- context "with options that takes an array as argument" do
65
- let(:options) do
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
75
- end
76
- end
77
- end
78
- 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
data/spec/spec_helper.rb DELETED
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
- ROOT = Pathname.new(File.expand_path("..", __dir__))
5
- $:.unshift("#{ROOT}lib".to_s)
6
- $:.unshift("#{ROOT}spec".to_s)
7
-
8
- require "bundler/setup"
9
- require "pry"
10
-
11
- require "rspec"
12
- 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
- require "danger_plugin"
28
-
29
- # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
30
- # If you are expanding these files, see if it's already been done ^.
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]
41
- end
42
-
43
- cork = Cork::Board.new(out: @output)
44
- def cork.string
45
- out.string.gsub(/\e\[([;\d]+)?m/, "")
46
- end
47
- cork
48
- end
49
- # rubocop:enable Lint/NestedMethodDefinition
50
-
51
- # Example environment (ENV) that would come from
52
- # running a PR on TravisCI
53
- def testing_env
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
62
-
63
- # A stubbed out Dangerfile for use in tests
64
- def testing_dangerfile
65
- env = Danger::EnvironmentManager.new(testing_env)
66
- Danger::Dangerfile.new(env, testing_ui)
67
- end
68
-
69
- def fixtures_path
70
- Pathname.new("../support/fixtures").expand_path(__FILE__)
71
- end
72
-
73
- def fixture(filename)
74
- fixtures_path.join(filename).to_s
75
- end
76
-
77
- def binaries_path
78
- Pathname.new("../../bin").expand_path(__FILE__)
79
- end
80
-
81
- def binary(filename)
82
- binaries_path.join(filename).to_s
83
- end