danger-periphery 0.2.1 → 0.2.2
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 +45 -11
- data/lib/periphery/json_parser.rb +67 -0
- data/lib/periphery.rb +1 -0
- data/lib/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1232912ce0ad696e3ea2b34b383fbc70831ccbf0a4294673a5a122c37909d677
|
4
|
+
data.tar.gz: 36c2fd6ab1f814f209cb0843db05e3d6c4bcad47360d6695db4968954048590e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67cbcfbbd827ab1f276d5f0f42728cea8a38a018495bbedefd62b441fae2b6e8fd92358269fde43d2d1c8d4e14494f5c3a510dc1c51473a8ac869375d4992f25
|
7
|
+
data.tar.gz: 68d40960394c7cba16e2ae6080803b493995641548bfaa31d3f5f0b32761cb47448863c063a7ae9be6b13283682ff6c5c9d4cece0fb200dd33bb0ca17c09dac8
|
data/lib/danger_plugin.rb
CHANGED
@@ -23,6 +23,8 @@ module Danger
|
|
23
23
|
# @return [String]
|
24
24
|
attr_accessor :binary_path
|
25
25
|
|
26
|
+
# @deprecated Use {#scan} with block instead.
|
27
|
+
#
|
26
28
|
# Proc object to process each warnings just before showing them.
|
27
29
|
# The Proc must receive 4 arguments: path, line, column, message
|
28
30
|
# and return one of:
|
@@ -36,17 +38,22 @@ module Danger
|
|
36
38
|
#
|
37
39
|
# By default the Proc returns true.
|
38
40
|
# @return [Proc]
|
39
|
-
|
41
|
+
attr_reader :postprocessor
|
42
|
+
|
43
|
+
# For internal use only.
|
44
|
+
#
|
45
|
+
# @return [Symbol]
|
46
|
+
attr_writer :format
|
40
47
|
|
41
48
|
OPTION_OVERRIDES = {
|
42
49
|
disable_update_check: true,
|
43
|
-
format: 'checkstyle',
|
44
50
|
quiet: true
|
45
51
|
}.freeze
|
46
52
|
|
47
53
|
def initialize(dangerfile)
|
48
54
|
super(dangerfile)
|
49
55
|
@postprocessor = ->(_path, _line, _column, _message) { true }
|
56
|
+
@format = :checkstyle
|
50
57
|
end
|
51
58
|
|
52
59
|
# Scans Swift files.
|
@@ -54,7 +61,7 @@ module Danger
|
|
54
61
|
#
|
55
62
|
# @example Ignore all warnings from files matching regular expression
|
56
63
|
# periphery.scan do |violation|
|
57
|
-
# !
|
64
|
+
# !violation.path.match(/.*\/generated\.swift/)
|
58
65
|
# end
|
59
66
|
#
|
60
67
|
# @param [Hash] options Options passed to Periphery with the following translation rules.
|
@@ -71,10 +78,10 @@ module Danger
|
|
71
78
|
# suppressed, otherwise not.
|
72
79
|
#
|
73
80
|
# @return [void]
|
74
|
-
def scan(
|
75
|
-
output = Periphery::Runner.new(binary_path).scan(options.merge(OPTION_OVERRIDES))
|
81
|
+
def scan(options = {}, &block)
|
82
|
+
output = Periphery::Runner.new(binary_path).scan(options.merge(OPTION_OVERRIDES).merge(format: @format))
|
76
83
|
files = files_in_diff
|
77
|
-
|
84
|
+
parser.parse(output).each do |entry|
|
78
85
|
next unless files.include?(entry.path)
|
79
86
|
|
80
87
|
result = postprocess(entry, &block)
|
@@ -85,18 +92,21 @@ module Danger
|
|
85
92
|
end
|
86
93
|
end
|
87
94
|
|
95
|
+
# @deprecated Use {#scan} with block instead.
|
96
|
+
#
|
88
97
|
# Convenience method to set {#postprocessor} with block.
|
89
98
|
#
|
90
99
|
# @return [Proc]
|
91
|
-
#
|
92
|
-
# @example Ignore all warnings from files matching regular expression
|
93
|
-
# periphery.process_warnings do |path, line, column, message|
|
94
|
-
# ! path.match(/.*\/generated\.swift/)
|
95
|
-
# end
|
96
100
|
def process_warnings(&block)
|
101
|
+
deprecate_in_favor_of_scan
|
97
102
|
@postprocessor = block
|
98
103
|
end
|
99
104
|
|
105
|
+
def postprocessor=(postprocessor)
|
106
|
+
deprecate_in_favor_of_scan
|
107
|
+
@postprocessor = postprocessor
|
108
|
+
end
|
109
|
+
|
100
110
|
private
|
101
111
|
|
102
112
|
def files_in_diff
|
@@ -132,5 +142,29 @@ module Danger
|
|
132
142
|
raise 'Proc passed to postprocessor must return one of nil, true, false and Array that includes 4 elements.'
|
133
143
|
end
|
134
144
|
end
|
145
|
+
|
146
|
+
def deprecate_in_favor_of_scan
|
147
|
+
caller_method_name = caller(1, 1)[0].sub(/.*`(.*)'.*/, '\1')
|
148
|
+
caller_location = caller_locations(2, 1)[0]
|
149
|
+
message = [
|
150
|
+
"`#{self.class}##{caller_method_name}` is deprecated; use `#{self.class}#scan` with block instead. ",
|
151
|
+
'It will be removed from future releases.'
|
152
|
+
].join
|
153
|
+
location_message = "#{self.class}##{caller_method_name} called from #{caller_location}"
|
154
|
+
Kernel.warn("NOTE: #{message}\n#{location_message}")
|
155
|
+
issue_reference = 'See manicmaniac/danger-periphery#37 for detail.'
|
156
|
+
warn("#{message}\n#{issue_reference}", file: caller_location.path, line: caller_location.lineno)
|
157
|
+
end
|
158
|
+
|
159
|
+
def parser
|
160
|
+
case @format
|
161
|
+
when :checkstyle
|
162
|
+
Periphery::CheckstyleParser.new
|
163
|
+
when :json
|
164
|
+
Periphery::JsonParser.new
|
165
|
+
else
|
166
|
+
raise "#{@format} is unsupported"
|
167
|
+
end
|
168
|
+
end
|
135
169
|
end
|
136
170
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'periphery/scan_result'
|
5
|
+
|
6
|
+
module Periphery
|
7
|
+
# Parses JSON formatted output produced by Periphery with +--format=json+ option.
|
8
|
+
class JsonParser
|
9
|
+
def parse(string)
|
10
|
+
JSON.parse(string).map do |entry|
|
11
|
+
path, line, column = parse_location(entry['location'])
|
12
|
+
message = compose_message(*entry.slice('name', 'kind', 'hints').values)
|
13
|
+
ScanResult.new(path, line, column, message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def relative_path(path, base = Pathname.getwd)
|
20
|
+
Pathname.new(path).relative_path_from(base).to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
# Parses a string like '/path/to/file.swift:19:10'
|
24
|
+
def parse_location(location)
|
25
|
+
location.scan(/^(.+):(\d+):(\d+)$/) do |path, line, column|
|
26
|
+
return [relative_path(path), line.to_i, column.to_i]
|
27
|
+
end
|
28
|
+
raise ArgumentError, "#{location} is not in a valid format"
|
29
|
+
end
|
30
|
+
|
31
|
+
def compose_message(name, kind, hints)
|
32
|
+
return 'unused' unless name
|
33
|
+
|
34
|
+
# Assumes hints contains only one item.
|
35
|
+
# https://github.com/peripheryapp/periphery/blob/2.9.0/Sources/Frontend/Formatters/JsonFormatter.swift#L27
|
36
|
+
# https://github.com/peripheryapp/periphery/blob/2.9.0/Sources/Frontend/Formatters/JsonFormatter.swift#L42
|
37
|
+
hint = hints[0]
|
38
|
+
+"#{display_name(kind).capitalize} '#{name}' #{describe_hint(hint)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def display_name(kind)
|
42
|
+
case kind
|
43
|
+
when 'enumelement' then 'enum case'
|
44
|
+
when 'function.constructor' then 'initializer'
|
45
|
+
when 'var.parameter' then 'parameter'
|
46
|
+
when 'generic_type_param' then 'generic type parameter'
|
47
|
+
when nil then ''
|
48
|
+
else kind.start_with?('var') ? 'property' : kind.split('.', 2)[0]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def describe_hint(hint)
|
53
|
+
case hint
|
54
|
+
when 'unused' then 'is unused'
|
55
|
+
when 'assignOnlyProperty' then 'is assigned, but never used'
|
56
|
+
when 'redundantProtocol' then "is redundant as it's never used as an existential type"
|
57
|
+
when 'redundantConformance' then 'conformance is redundant'
|
58
|
+
# FIXME: There's no information about the name of module in JSON output,
|
59
|
+
# unlike other formatters can output `outside of FooModule`.
|
60
|
+
# This is known problem and may be fixed in future Periphery's release.
|
61
|
+
# See the status of https://github.com/peripheryapp/periphery/pull/519
|
62
|
+
when 'redundantPublicAccessibility' then 'is declared public, but not used outside of the module'
|
63
|
+
else ''
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
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.2
|
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-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/danger_plugin.rb
|
35
35
|
- lib/periphery.rb
|
36
36
|
- lib/periphery/checkstyle_parser.rb
|
37
|
+
- lib/periphery/json_parser.rb
|
37
38
|
- lib/periphery/runner.rb
|
38
39
|
- lib/periphery/scan_result.rb
|
39
40
|
- lib/version.rb
|
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
58
|
- !ruby/object:Gem::Version
|
58
59
|
version: '0'
|
59
60
|
requirements: []
|
60
|
-
rubygems_version: 3.
|
61
|
+
rubygems_version: 3.1.2
|
61
62
|
signing_key:
|
62
63
|
specification_version: 4
|
63
64
|
summary: A Danger plugin to detect unused codes.
|