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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15302ed92faf0a3230ddcb167fe3db0ae2e8c1a51d6551d85a4c2cc37c760dd4
|
4
|
+
data.tar.gz: 18880214efa7cb5a29ee9b6872688a6eeb19d805e07cad6c445afeeb24f4cad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e33a6b9fa62d733004fb63337fdff4973dd3b38d40a096db0b84a1249bc7789a3612a99a88d31020e22dd6494c3b7d3c953fe721be16347e825a58e8900a177
|
7
|
+
data.tar.gz: 47a37136e81dc9c4b6fc6b3331e476810e4520503c7fd062714363675926c51525502dc58ef2d610b890ee0d73d731d8ac87910bd8e6ab2f051f47c980b4ac88
|
data/lib/danger_plugin.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'periphery'
|
4
4
|
|
5
5
|
module Danger
|
6
6
|
# Analyze Swift files and detect unused codes in your project.
|
7
|
-
# This is done using
|
7
|
+
# This is done using {https://github.com/peripheryapp/periphery Periphery}.
|
8
8
|
#
|
9
9
|
# @example Specifying options to Periphery.
|
10
10
|
#
|
@@ -15,7 +15,7 @@ module Danger
|
|
15
15
|
# clean_build: true
|
16
16
|
# )
|
17
17
|
#
|
18
|
-
# @see
|
18
|
+
# @see file:README.md
|
19
19
|
# @tags swift
|
20
20
|
class DangerPeriphery < Plugin
|
21
21
|
# Path to Periphery executable.
|
@@ -40,44 +40,58 @@ module Danger
|
|
40
40
|
|
41
41
|
OPTION_OVERRIDES = {
|
42
42
|
disable_update_check: true,
|
43
|
-
format:
|
43
|
+
format: 'checkstyle',
|
44
44
|
quiet: true
|
45
45
|
}.freeze
|
46
46
|
|
47
47
|
def initialize(dangerfile)
|
48
48
|
super(dangerfile)
|
49
|
-
@postprocessor = ->(
|
49
|
+
@postprocessor = ->(_path, _line, _column, _message) { true }
|
50
50
|
end
|
51
51
|
|
52
52
|
# Scans Swift files.
|
53
53
|
# Raises an error when Periphery executable is not found.
|
54
54
|
#
|
55
|
+
# @example Ignore all warnings from files matching regular expression
|
56
|
+
# periphery.scan do |violation|
|
57
|
+
# ! violation.path.match(/.*\/generated\.swift/)
|
58
|
+
# end
|
59
|
+
#
|
55
60
|
# @param [Hash] options Options passed to Periphery with the following translation rules.
|
56
61
|
# 1. Replace all underscores with hyphens in each key.
|
57
62
|
# 2. Prepend double hyphens to each key.
|
58
63
|
# 3. If value is an array, transform it to comma-separated string.
|
59
64
|
# 4. If value is true, drop value and treat it as option without argument.
|
60
|
-
# 5. Override some options
|
65
|
+
# 5. Override some options listed in {OPTION_OVERRIDES}.
|
66
|
+
# Run +$ periphery help scan+ for available options.
|
67
|
+
#
|
68
|
+
# @param [Proc] block Block to process each warning just before showing it.
|
69
|
+
# The Proc receives 1 {Periphery::ScanResult} instance as argument.
|
70
|
+
# If the Proc returns falsy value, the warning corresponding to the given ScanResult will be
|
71
|
+
# suppressed, otherwise not.
|
72
|
+
#
|
61
73
|
# @return [void]
|
62
74
|
def scan(**options, &block)
|
63
75
|
output = Periphery::Runner.new(binary_path).scan(options.merge(OPTION_OVERRIDES))
|
64
76
|
files = files_in_diff
|
65
|
-
Periphery::CheckstyleParser.new.parse(output).
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
77
|
+
Periphery::CheckstyleParser.new.parse(output).each do |entry|
|
78
|
+
next unless files.include?(entry.path)
|
79
|
+
|
80
|
+
result = postprocess(entry, &block)
|
81
|
+
next unless result
|
82
|
+
|
83
|
+
path, line, _column, message = result
|
84
|
+
warn(message, file: path, line: line)
|
85
|
+
end
|
72
86
|
end
|
73
87
|
|
74
|
-
# Convenience method to set
|
88
|
+
# Convenience method to set {#postprocessor} with block.
|
75
89
|
#
|
76
90
|
# @return [Proc]
|
77
91
|
#
|
78
92
|
# @example Ignore all warnings from files matching regular expression
|
79
93
|
# periphery.process_warnings do |path, line, column, message|
|
80
|
-
# !path.match(/.*\/generated\.swift/)
|
94
|
+
# ! path.match(/.*\/generated\.swift/)
|
81
95
|
# end
|
82
96
|
def process_warnings(&block)
|
83
97
|
@postprocessor = block
|
@@ -88,26 +102,34 @@ module Danger
|
|
88
102
|
def files_in_diff
|
89
103
|
# Taken from https://github.com/ashfurrow/danger-ruby-swiftlint/blob/5184909aab00f12954088684bbf2ce5627e08ed6/lib/danger_plugin.rb#L214-L216
|
90
104
|
renamed_files_hash = git.renamed_files.to_h { |rename| [rename[:before], rename[:after]] }
|
91
|
-
post_rename_modified_files = git.modified_files.map
|
105
|
+
post_rename_modified_files = git.modified_files.map do |modified_file|
|
106
|
+
renamed_files_hash[modified_file] || modified_file
|
107
|
+
end
|
92
108
|
(post_rename_modified_files - git.deleted_files) + git.added_files
|
93
109
|
end
|
94
110
|
|
95
111
|
def postprocess(entry, &block)
|
96
112
|
if block
|
97
|
-
|
98
|
-
|
99
|
-
|
113
|
+
postprocess_with_block(entry, &block)
|
114
|
+
else
|
115
|
+
postprocess_with_postprocessor(entry)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def postprocess_with_block(entry, &block)
|
120
|
+
[entry.path, entry.line, entry.column, entry.message] if block.call(entry)
|
121
|
+
end
|
122
|
+
|
123
|
+
def postprocess_with_postprocessor(entry)
|
124
|
+
result = @postprocessor.call(entry.path, entry.line, entry.column, entry.message)
|
125
|
+
if !result
|
126
|
+
nil
|
127
|
+
elsif result.is_a?(TrueClass)
|
128
|
+
[entry.path, entry.line, entry.column, entry.message]
|
129
|
+
elsif result.is_a?(Array) && result.size == 4
|
130
|
+
result
|
100
131
|
else
|
101
|
-
|
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
|
132
|
+
raise 'Proc passed to postprocessor must return one of nil, true, false and Array that includes 4 elements.'
|
111
133
|
end
|
112
134
|
end
|
113
135
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require "rexml/streamlistener"
|
3
|
+
require 'pathname'
|
4
|
+
require 'periphery/scan_result'
|
5
|
+
require 'rexml/parsers/streamparser'
|
6
|
+
require 'rexml/streamlistener'
|
8
7
|
|
9
8
|
module Periphery
|
9
|
+
# Parses {https://checkstyle.sourceforge.io/ Checkstyle} format XML produced by Periphery with
|
10
|
+
# +--format=checkstyle+ option.
|
10
11
|
class CheckstyleParser
|
11
|
-
class Listener
|
12
|
+
class Listener # :nodoc:
|
12
13
|
include REXML::StreamListener
|
13
14
|
|
14
15
|
attr_reader :results
|
@@ -20,22 +21,17 @@ module Periphery
|
|
20
21
|
|
21
22
|
def tag_start(name, attrs)
|
22
23
|
case name
|
23
|
-
when
|
24
|
-
@current_file = relative_path(attrs[
|
25
|
-
when
|
24
|
+
when 'file'
|
25
|
+
@current_file = relative_path(attrs['name'])
|
26
|
+
when 'error'
|
26
27
|
if @current_file
|
27
|
-
@results << ScanResult.new(
|
28
|
-
@current_file,
|
29
|
-
attrs["line"].to_i,
|
30
|
-
attrs["column"].to_i,
|
31
|
-
attrs["message"]
|
32
|
-
)
|
28
|
+
@results << ScanResult.new(@current_file, attrs['line'].to_i, attrs['column'].to_i, attrs['message'])
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
36
32
|
|
37
33
|
def tag_end(name)
|
38
|
-
@current_file = nil if name ==
|
34
|
+
@current_file = nil if name == 'file'
|
39
35
|
end
|
40
36
|
|
41
37
|
private
|
data/lib/periphery/runner.rb
CHANGED
@@ -1,35 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'open3'
|
4
4
|
|
5
5
|
module Periphery
|
6
|
-
class Runner
|
6
|
+
class Runner # :nodoc:
|
7
7
|
attr_reader :binary_path
|
8
8
|
|
9
9
|
def initialize(binary_path)
|
10
|
-
@binary_path = binary_path ||
|
10
|
+
@binary_path = binary_path || 'periphery'
|
11
11
|
end
|
12
12
|
|
13
13
|
def scan(options)
|
14
|
-
arguments = [binary_path,
|
14
|
+
arguments = [binary_path, 'scan'] + scan_arguments(options)
|
15
15
|
stdout, stderr, status = Open3.capture3(*arguments)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
raise "error: #{arguments} exited with status code #{status.exitstatus}. #{stderr}" unless status.success?
|
20
|
-
end
|
16
|
+
raise "error: #{arguments} exited with status code #{status.exitstatus}. #{stderr}" unless status.success?
|
17
|
+
|
18
|
+
stdout
|
21
19
|
end
|
22
20
|
|
23
21
|
def scan_arguments(options)
|
24
|
-
options.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
compact
|
22
|
+
options.each_with_object([]) do |(key, value), new_options|
|
23
|
+
next unless value
|
24
|
+
|
25
|
+
value = nil if value.is_a?(TrueClass)
|
26
|
+
value = value.join(',') if value.is_a?(Array)
|
27
|
+
new_options << "--#{key.to_s.tr('_', '-')}"
|
28
|
+
new_options << value&.to_s if value
|
29
|
+
end
|
33
30
|
end
|
34
31
|
end
|
35
32
|
end
|
data/lib/periphery.rb
CHANGED
data/lib/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
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-07-
|
11
|
+
date: 2022-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -27,39 +27,16 @@ dependencies:
|
|
27
27
|
description: A Danger plugin to detect unused codes.
|
28
28
|
email:
|
29
29
|
- rito.0305@gmail.com
|
30
|
-
executables:
|
31
|
-
- download_periphery
|
30
|
+
executables: []
|
32
31
|
extensions: []
|
33
32
|
extra_rdoc_files: []
|
34
33
|
files:
|
35
|
-
- ".github/workflows/lint.yml"
|
36
|
-
- ".github/workflows/test.yml"
|
37
|
-
- ".gitignore"
|
38
|
-
- ".rspec"
|
39
|
-
- ".rubocop.yml"
|
40
|
-
- Dangerfile
|
41
|
-
- Gemfile
|
42
|
-
- Gemfile.lock
|
43
|
-
- Guardfile
|
44
|
-
- LICENSE.txt
|
45
|
-
- README.md
|
46
|
-
- Rakefile
|
47
|
-
- bin/download_periphery
|
48
|
-
- danger-periphery.gemspec
|
49
34
|
- lib/danger_plugin.rb
|
50
35
|
- lib/periphery.rb
|
51
36
|
- lib/periphery/checkstyle_parser.rb
|
52
37
|
- lib/periphery/runner.rb
|
53
38
|
- lib/periphery/scan_result.rb
|
54
39
|
- lib/version.rb
|
55
|
-
- spec/danger_plugin_spec.rb
|
56
|
-
- spec/periphery/checkstyle_parser_spec.rb
|
57
|
-
- spec/periphery/runner_spec.rb
|
58
|
-
- spec/spec_helper.rb
|
59
|
-
- spec/support/fixtures/github_pr.json
|
60
|
-
- spec/support/fixtures/mock-periphery
|
61
|
-
- spec/support/fixtures/test.xcodeproj/project.pbxproj
|
62
|
-
- spec/support/fixtures/test/main.swift
|
63
40
|
homepage: https://github.com/manicmaniac/danger-periphery
|
64
41
|
licenses:
|
65
42
|
- MIT
|
data/.github/workflows/lint.yml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
name: Lint
|
2
|
-
on: [pull_request]
|
3
|
-
jobs:
|
4
|
-
lint:
|
5
|
-
runs-on: macOS-11
|
6
|
-
env:
|
7
|
-
DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
|
8
|
-
steps:
|
9
|
-
- uses: actions/checkout@v2
|
10
|
-
- run: bin/download_periphery
|
11
|
-
- run: bundle install
|
12
|
-
- run: bundle exec danger
|
data/.github/workflows/test.yml
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED