danger-phpmd 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 340812563d4594a560b7c381e2ef0676f9d25444cda9d0e8d93c90eb4ffffb4f
4
- data.tar.gz: 7fb867a2b4fadcdddf6433469523bc86fbdc919b4f15665a8bd3522e7c8154c1
3
+ metadata.gz: 9ab0e7618721329c9361bb8cd717c0790ac06f7eaf4322ffcfbf740d20e66228
4
+ data.tar.gz: 87db1c037bc887e68e210372fe77e07d414c40463cbf7cf1c03e1863c7539a43
5
5
  SHA512:
6
- metadata.gz: 52442609ede340b16efcfc915c183851f6acfeed740a43925761239854f705acc5094cdc53efce847b0bcbd0b1969803d834fda9f7090f338aee6133eebc7e7f
7
- data.tar.gz: 74d69ed0fe7ec23aba7065d7a508bf54c4ad7bd0e5d8c6270489f60b12d1aee7c14c36cb6cf0568d46ab55f15adc0b2f1ed01aceeab1126c9542dcd75b41d1f1
6
+ metadata.gz: '01339c744a8903aeb46ad506146c3c716e2d7fffe373ec6be116cb6fb96c1b7cc8f483f7be0e379f06b27de7c516fd27e3997c64e910b597a7b8f06e5f2c84ec'
7
+ data.tar.gz: 26bae6dd2c54dccbdc383207c99bebb958104cd885ce86156116970b985cc1d14c99c7b39c949a5c7d951218ecfd1083b71788a94b9e8ef45b21163bc8f802e5
@@ -8,18 +8,20 @@ jobs:
8
8
 
9
9
  runs-on: ubuntu-latest
10
10
  strategy:
11
+ fail-fast: false
11
12
  matrix:
12
- ruby-version: ['3.1', '3.2', '3.3', '3.4']
13
- php-version: ['8.3', '8.4']
13
+ ruby-version: ['3.4', '4.0']
14
+ php-version: ['8.3', '8.4', '8.5']
15
+ phpmd-version: ['2', '3']
14
16
 
15
17
  steps:
16
- - uses: actions/checkout@v4
18
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
17
19
  - name: Setup PHP environment
18
- uses: shivammathur/setup-php@v2
20
+ uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
19
21
  with:
20
22
  php-version: ${{ matrix.php-version }}
21
23
  coverage: none
22
- tools: phpmd
24
+ tools: phpmd:${{ matrix.phpmd-version }}
23
25
  - name: Set up Ruby
24
26
  uses: ruby/setup-ruby@v1
25
27
  with:
@@ -0,0 +1,21 @@
1
+ name: actionlint
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths:
7
+ - ".github/workflows/**"
8
+ pull_request:
9
+ branches: [main]
10
+ paths:
11
+ - ".github/workflows/**"
12
+
13
+ jobs:
14
+ actionlint:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
18
+ - name: Check workflow files
19
+ uses: docker://rhysd/actionlint:latest
20
+ with:
21
+ args: -color
data/Gemfile.lock CHANGED
@@ -1,16 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-phpmd (0.1.0)
4
+ danger-phpmd (0.3.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.8.7)
11
- public_suffix (>= 2.0.2, < 7.0)
12
- ast (2.4.2)
13
- base64 (0.2.0)
10
+ activesupport (8.1.4.1)
11
+ base64
12
+ bigdecimal
13
+ concurrent-ruby (~> 1.0, >= 1.3.1)
14
+ connection_pool (>= 2.2.5)
15
+ drb
16
+ i18n (>= 1.6, < 2)
17
+ json
18
+ logger (>= 1.4.2)
19
+ minitest (>= 5.1)
20
+ securerandom (>= 0.3)
21
+ tzinfo (~> 2.0, >= 2.0.5)
22
+ uri (>= 0.13.1)
23
+ addressable (2.9.2)
24
+ public_suffix (>= 2.0.2, < 8.0)
25
+ ast (2.4.3)
26
+ base64 (0.3.0)
27
+ bigdecimal (4.1.3)
14
28
  claide (1.1.0)
15
29
  claide-plugins (0.9.2)
16
30
  cork
@@ -18,46 +32,52 @@ GEM
18
32
  open4 (~> 1.3)
19
33
  coderay (1.1.3)
20
34
  colored2 (3.1.2)
35
+ concurrent-ruby (1.3.8)
36
+ connection_pool (3.0.2)
21
37
  cork (0.3.0)
22
38
  colored2 (~> 3.1)
23
- danger (9.5.1)
39
+ danger (9.6.2)
24
40
  base64 (~> 0.2)
25
41
  claide (~> 1.0)
26
42
  claide-plugins (>= 0.9.2)
27
- colored2 (~> 3.1)
43
+ colored2 (>= 3.1, < 5)
28
44
  cork (~> 0.1)
29
45
  faraday (>= 0.9.0, < 3.0)
30
- faraday-http-cache (~> 2.0)
31
- git (~> 1.13)
32
- kramdown (~> 2.3)
46
+ faraday-http-cache (>= 2.0, < 4.0)
47
+ git (>= 1.13)
48
+ kramdown (>= 2.5.1, < 3.0)
33
49
  kramdown-parser-gfm (~> 1.0)
34
50
  octokit (>= 4.0)
35
51
  pstore (~> 0.1)
36
- terminal-table (>= 1, < 4)
52
+ terminal-table (>= 1, < 5)
37
53
  danger-plugin-api (1.0.0)
38
54
  danger (> 2.0)
39
- diff-lcs (1.6.0)
40
- faraday (2.12.2)
41
- faraday-net_http (>= 2.0, < 3.5)
55
+ diff-lcs (1.6.2)
56
+ drb (2.2.3)
57
+ faraday (2.15.1)
58
+ faraday-net_http (>= 2.0, < 3.6)
42
59
  json
43
60
  logger
44
- faraday-http-cache (2.5.1)
61
+ faraday-http-cache (3.0.0)
45
62
  faraday (>= 0.8)
46
- faraday-net_http (3.4.0)
47
- net-http (>= 0.5.0)
48
- ffi (1.17.1)
49
- formatador (1.1.0)
50
- git (1.19.1)
51
- addressable (~> 2.8)
52
- rchardet (~> 1.8)
53
- guard (2.19.1)
63
+ faraday-net_http (3.5.0)
64
+ net-http (~> 0.5)
65
+ ffi (1.17.4)
66
+ formatador (1.2.3)
67
+ reline
68
+ git (6.0.0)
69
+ activesupport (>= 7.0.9)
70
+ addressable (~> 2.9)
71
+ logger (~> 1.6)
72
+ process_executer (~> 4.1)
73
+ rchardet (~> 1.9)
74
+ guard (2.20.2)
54
75
  formatador (>= 0.2.4)
55
76
  listen (>= 2.7, < 4.0)
56
77
  logger (~> 1.6)
57
78
  lumberjack (>= 1.0.12, < 2.0)
58
79
  nenv (~> 0.1)
59
80
  notiffany (~> 0.0)
60
- ostruct (~> 0.6)
61
81
  pry (>= 0.13.0)
62
82
  shellany (~> 0.0)
63
83
  thor (>= 0.18.1)
@@ -66,95 +86,119 @@ GEM
66
86
  guard (~> 2.1)
67
87
  guard-compat (~> 1.1)
68
88
  rspec (>= 2.99.0, < 4.0)
69
- json (2.10.1)
70
- kramdown (2.5.1)
71
- rexml (>= 3.3.9)
89
+ i18n (1.15.2)
90
+ concurrent-ruby (~> 1.0)
91
+ io-console (0.9.5)
92
+ json (3.1.0)
93
+ kramdown (2.5.2)
94
+ rexml (>= 3.4.4)
72
95
  kramdown-parser-gfm (1.1.0)
73
96
  kramdown (~> 2.0)
74
- language_server-protocol (3.17.0.4)
75
- listen (3.0.7)
76
- rb-fsevent (>= 0.9.3)
77
- rb-inotify (>= 0.9.7)
78
- logger (1.6.6)
79
- lumberjack (1.2.10)
97
+ language_server-protocol (3.17.0.6)
98
+ lint_roller (1.1.0)
99
+ listen (3.10.1)
100
+ logger
101
+ rb-fsevent (~> 0.10, >= 0.10.3)
102
+ rb-inotify (~> 0.9, >= 0.9.10)
103
+ logger (1.7.0)
104
+ lumberjack (1.4.2)
80
105
  method_source (1.1.0)
81
- nap (1.1.0)
106
+ minitest (6.1.0)
107
+ drb (~> 2.0)
108
+ prism (>= 1.5, < 3)
109
+ nap (1.2.0)
82
110
  nenv (0.3.0)
83
- net-http (0.6.0)
84
- uri
111
+ net-http (0.10.0)
112
+ net-protocol (>= 0.3.0)
113
+ uri (>= 0.11.1)
114
+ net-protocol (0.4.0)
115
+ timeout
85
116
  notiffany (0.1.3)
86
117
  nenv (~> 0.1)
87
118
  shellany (~> 0.0)
88
- octokit (9.2.0)
119
+ octokit (10.0.0)
89
120
  faraday (>= 1, < 3)
90
121
  sawyer (~> 0.9)
91
122
  open4 (1.3.4)
92
- ostruct (0.6.1)
93
- parallel (1.26.3)
94
- parser (3.3.7.1)
123
+ parallel (2.3.0)
124
+ parser (3.3.13.0)
95
125
  ast (~> 2.4.1)
96
126
  racc
97
- pry (0.15.2)
127
+ prism (2.1.0)
128
+ process_executer (4.1.1)
129
+ track_open_instances (~> 0.1)
130
+ pry (0.16.1)
98
131
  coderay (~> 1.1)
99
132
  method_source (~> 1.0)
100
- pstore (0.1.4)
101
- public_suffix (6.0.1)
133
+ reline (>= 0.6.0)
134
+ pstore (0.3.0)
135
+ public_suffix (7.0.5)
102
136
  racc (1.8.1)
103
137
  rainbow (3.1.1)
104
- rake (13.2.1)
138
+ rake (13.4.2)
105
139
  rb-fsevent (0.11.2)
106
140
  rb-inotify (0.11.1)
107
141
  ffi (~> 1.0)
108
- rchardet (1.9.0)
109
- regexp_parser (2.10.0)
110
- rexml (3.4.0)
111
- rspec (3.13.0)
142
+ rchardet (1.10.2)
143
+ regexp_parser (2.13.1)
144
+ reline (0.7.0)
145
+ io-console (~> 0.5)
146
+ rexml (3.4.4)
147
+ rspec (3.13.2)
112
148
  rspec-core (~> 3.13.0)
113
149
  rspec-expectations (~> 3.13.0)
114
150
  rspec-mocks (~> 3.13.0)
115
- rspec-core (3.13.3)
151
+ rspec-core (3.13.7)
116
152
  rspec-support (~> 3.13.0)
117
- rspec-expectations (3.13.3)
153
+ rspec-expectations (3.13.6)
118
154
  diff-lcs (>= 1.2.0, < 2.0)
119
155
  rspec-support (~> 3.13.0)
120
- rspec-mocks (3.13.2)
156
+ rspec-mocks (3.13.9)
121
157
  diff-lcs (>= 1.2.0, < 2.0)
122
158
  rspec-support (~> 3.13.0)
123
- rspec-support (3.13.2)
124
- rubocop (1.71.2)
125
- json (~> 2.3)
126
- language_server-protocol (>= 3.17.0)
127
- parallel (~> 1.10)
159
+ rspec-support (3.13.8)
160
+ rubocop (1.92.2)
161
+ json (>= 2.3)
162
+ language_server-protocol (~> 3.17.0.2)
163
+ lint_roller (~> 1.1.0)
164
+ parallel (>= 1.10)
128
165
  parser (>= 3.3.0.2)
129
166
  rainbow (>= 2.2.2, < 4.0)
130
- regexp_parser (>= 2.9.3, < 3.0)
131
- rubocop-ast (>= 1.38.0, < 2.0)
167
+ regexp_parser (>= 2.11.3, < 3.0)
168
+ rubocop-ast (>= 1.49.0, < 2.0)
132
169
  ruby-progressbar (~> 1.7)
133
170
  unicode-display_width (>= 2.4.0, < 4.0)
134
- rubocop-ast (1.38.0)
135
- parser (>= 3.3.1.0)
171
+ rubocop-ast (1.51.0)
172
+ parser (>= 3.3.7.2)
173
+ prism (>= 1.7)
136
174
  ruby-progressbar (1.13.0)
137
- sawyer (0.9.2)
175
+ sawyer (0.9.3)
138
176
  addressable (>= 2.3.5)
139
177
  faraday (>= 0.17.3, < 3)
178
+ securerandom (0.4.1)
140
179
  shellany (0.0.1)
141
- terminal-table (1.6.0)
142
- thor (1.3.2)
143
- unicode-display_width (3.1.4)
144
- unicode-emoji (~> 4.0, >= 4.0.4)
145
- unicode-emoji (4.0.4)
146
- uri (1.0.2)
147
- yard (0.9.37)
180
+ terminal-table (4.0.0)
181
+ unicode-display_width (>= 1.1.1, < 4)
182
+ thor (1.5.0)
183
+ timeout (0.6.1)
184
+ track_open_instances (0.1.15)
185
+ tzinfo (2.0.6)
186
+ concurrent-ruby (~> 1.0)
187
+ unicode-display_width (3.3.0)
188
+ unicode-emoji (~> 4.3)
189
+ unicode-emoji (4.3.0)
190
+ uri (1.1.2)
191
+ yard (0.9.45)
148
192
 
149
193
  PLATFORMS
150
194
  ruby
151
195
 
152
196
  DEPENDENCIES
153
- bundler (~> 2.0)
197
+ bundler (~> 4.0)
154
198
  danger-phpmd!
155
199
  guard (~> 2.14)
156
200
  guard-rspec (~> 4.7)
157
- listen (= 3.0.7)
201
+ listen (= 3.10.1)
158
202
  pry
159
203
  rake (~> 13.0)
160
204
  rspec (~> 3.4)
@@ -162,4 +206,4 @@ DEPENDENCIES
162
206
  yard
163
207
 
164
208
  BUNDLED WITH
165
- 2.6.3
209
+ 4.0.24
data/README.md CHANGED
@@ -13,17 +13,35 @@ Please check the [installation guide](https://phpmd.org/download/index.html).
13
13
 
14
14
  Add this to Dangerfile.
15
15
 
16
+ ```ruby
17
+ phpmd.run
16
18
  ```
17
- phpmd.run ruleset: "rulesets.xml"
19
+
20
+ PHPMD 3 automatically detects a configuration file (`phpmd.yml`, `phpmd.xml`, etc.) in the current directory.
21
+ If you want to specify rulesets, pass them to the `ruleset` option. Multiple rulesets can be separated by comma.
22
+
23
+ ```ruby
24
+ phpmd.run ruleset: "phpmd.yml"
25
+ phpmd.run ruleset: "cleancode,codesize"
18
26
  ```
19
27
 
20
28
  If you want to specify phpmd bin file, you can set a bin path to the binary_path parameter.
21
29
 
22
- ```
30
+ ```ruby
23
31
  phpmd.binary_path = "vendor/bin/phpmd"
24
- phpmd.run ruleset: "rulesets.xml"
32
+ phpmd.run
25
33
  ```
26
34
 
35
+ If phpmd fails (e.g. invalid ruleset), an error is raised with the output of phpmd.
36
+
37
+ ### PHPMD 2
38
+
39
+ PHPMD 2 is also supported. The version is detected automatically.
40
+ The `ruleset` option is required for PHPMD 2.
41
+
42
+ ```ruby
43
+ phpmd.run ruleset: "rulesets.xml"
44
+ ```
27
45
 
28
46
  ### GitHub actions
29
47
 
@@ -37,7 +55,7 @@ jobs:
37
55
  runs-on: ubuntu-latest
38
56
  if: github.event_name == 'pull_request'
39
57
  steps:
40
- - uses: actions/checkout@v2
58
+ - uses: actions/checkout@v6
41
59
  - uses: ruby/setup-ruby@v1
42
60
  with:
43
61
  ruby-version: 3.4
@@ -48,10 +66,9 @@ jobs:
48
66
  with:
49
67
  php-version: '8.4'
50
68
  coverage: none
51
- tools: phpmd
69
+ tools: phpmd:3
52
70
 
53
71
  - run: bundle exec danger
54
72
  env:
55
73
  DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56
74
  ```
57
-
data/danger-phpmd.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
23
23
 
24
24
  # General ruby development
25
- spec.add_development_dependency "bundler", "~> 2.0"
25
+ spec.add_development_dependency "bundler", "~> 4.0"
26
26
  spec.add_development_dependency "rake", "~> 13.0"
27
27
 
28
28
  # Testing support
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "guard-rspec", "~> 4.7"
38
38
 
39
39
  # If you want to work on older builds of ruby
40
- spec.add_development_dependency "listen", "3.0.7"
40
+ spec.add_development_dependency "listen", "3.10.1"
41
41
 
42
42
  # This gives you the chance to run a REPL inside your tests
43
43
  # via:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phpmd
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/phpmd/plugin.rb CHANGED
@@ -21,11 +21,13 @@ module Danger
21
21
 
22
22
  # Execute phpmd
23
23
  # @return [void]
24
- def run(options)
24
+ def run(options = {})
25
25
  return if target_files.empty?
26
26
 
27
27
  tmpfile = Tempfile.open("phpmd_result")
28
- Open3.capture3(cmd_path, "--reportfile", tmpfile.path, target_files.join(","), "json", options[:ruleset])
28
+ _stdout, stderr, status = Open3.capture3(*command(tmpfile.path, options[:ruleset]))
29
+ raise "phpmd failed: #{stderr}" unless [0, 2].include?(status.exitstatus)
30
+
29
31
  results = parse(tmpfile.read)
30
32
  results.each do |result|
31
33
  warn(result[:message], file: result[:file], line: result[:line])
@@ -34,6 +36,21 @@ module Danger
34
36
 
35
37
  private
36
38
 
39
+ def command(report_path, ruleset)
40
+ if major_version >= 3
41
+ rulesets = ruleset.to_s.split(",").flat_map { |r| ["--ruleset", r] }
42
+ [cmd_path, "analyze", "--format", "json", "--reportfile-json", report_path, "--no-progress", *rulesets, "--", *target_files]
43
+ else
44
+ [cmd_path, "--reportfile", report_path, target_files.join(","), "json", ruleset]
45
+ end
46
+ end
47
+
48
+ def major_version
49
+ stdout, _stderr, _status = Open3.capture3(cmd_path, "--version")
50
+ match = stdout.match(/PHPMD (\d+)\./)
51
+ match ? match[1].to_i : 3
52
+ end
53
+
37
54
  def cmd_path
38
55
  return binary_path if binary_path
39
56
 
data/renovate.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
- "extends": [
4
- "config:recommended"
3
+ "extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
4
+ "packageRules": [
5
+ {
6
+ "minimumReleaseAge": "1 week",
7
+ "internalChecksFilter": "strict",
8
+ "matchPackageNames": ["*"]
9
+ }
5
10
  ]
6
11
  }
data/spec/phpmd_spec.rb CHANGED
@@ -47,6 +47,18 @@ module Danger
47
47
  expect(violation_report.message).to eq(expected_message)
48
48
  end
49
49
  end
50
+
51
+ context "with an unknown ruleset" do
52
+ before do
53
+ allow(@my_plugin).to receive(:target_files).and_return(
54
+ [File.expand_path("fixtures/no_warnings.php", __dir__)]
55
+ )
56
+ end
57
+
58
+ it "raises an error" do
59
+ expect { @my_plugin.run({ ruleset: "unknown" }) }.to raise_error(/phpmd failed/)
60
+ end
61
+ end
50
62
  end
51
63
  end
52
64
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-phpmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyosuke Takayama
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-15 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: danger-plugin-api
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.0'
32
+ version: '4.0'
33
33
  type: :development
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.0'
39
+ version: '4.0'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rake
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -127,14 +127,14 @@ dependencies:
127
127
  requirements:
128
128
  - - '='
129
129
  - !ruby/object:Gem::Version
130
- version: 3.0.7
130
+ version: 3.10.1
131
131
  type: :development
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - '='
136
136
  - !ruby/object:Gem::Version
137
- version: 3.0.7
137
+ version: 3.10.1
138
138
  - !ruby/object:Gem::Dependency
139
139
  name: pry
140
140
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +157,7 @@ extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
159
  - ".github/workflows/CI.yml"
160
+ - ".github/workflows/actionlint.yml"
160
161
  - ".gitignore"
161
162
  - ".rubocop.yml"
162
163
  - Gemfile
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  - !ruby/object:Gem::Version
194
195
  version: '0'
195
196
  requirements: []
196
- rubygems_version: 3.6.2
197
+ rubygems_version: 4.0.10
197
198
  specification_version: 4
198
199
  summary: Danger plugin for PHPMD.
199
200
  test_files: