danger-phpmd 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1e49c9cf20dce174e2333d20d5061022fa3e30c11f742b3534fddffcb0a2850
4
- data.tar.gz: d0d6c25a5a58ad42ecf16e7eeb297808dffe0f73315265ddb823475c84b32278
3
+ metadata.gz: fadbd745fa93f2da53a1a67b93a0ca61de2c21f64fc585a97443e61e56c5e7e1
4
+ data.tar.gz: 8b31e814c6293a58d0291c390a3aaac9ea803ea447950ac19fcb854d211a5131
5
5
  SHA512:
6
- metadata.gz: 3f52ab2348cfd88d732af154e29cf75428bb6f1b32b2553dfc9b4a6ed37c1ca7d3fab00c39aa4734015dd380d297a43efefc9e935147a708df8f72d88e9d25f4
7
- data.tar.gz: a36b2927dc3a6afc38ef368cc822b7c6ca297bc98e4a1aff29ffa6bb9818071a167f4e43c858e34271f8a507350b5f6f3d9ec6c76c8880a1666bd77fd9075436
6
+ metadata.gz: 4bbe29d4fd993884820861ed149c442764d07529aa8eeb2d80f69399c30b59be7dcf79378c994f6078ab7e1192b565737b0785676da7c05bdf0abe47ba0485b2
7
+ data.tar.gz: 6fd877b2192508304cfaf3a55485809f1676fdb4e4476f61add8fea52f4ba592b11d06a3bba32dc614823be946a7d4bc067f56e267ab5b89f881e08d861c890a
@@ -0,0 +1,28 @@
1
+
2
+ name: CI
3
+
4
+ on: [push]
5
+
6
+ jobs:
7
+ test:
8
+
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ ruby-version: ['2.7', '3.0', '3.1']
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Setup PHP environment
17
+ uses: shivammathur/setup-php@v2
18
+ with:
19
+ php-version: '8.0'
20
+ coverage: none
21
+ tools: phpmd
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby-version }}
26
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
27
+ - name: Run tests
28
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -3,6 +3,7 @@
3
3
  # If you don't like these settings, just delete this file :)
4
4
 
5
5
  AllCops:
6
+ NewCops: enable
6
7
  TargetRubyVersion: 2.6
7
8
 
8
9
  Style/StringLiterals:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-phpmd (0.0.1)
4
+ danger-phpmd (0.1.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
@@ -19,7 +19,7 @@ GEM
19
19
  colored2 (3.1.2)
20
20
  cork (0.3.0)
21
21
  colored2 (~> 3.1)
22
- danger (8.4.1)
22
+ danger (8.4.2)
23
23
  claide (~> 1.0)
24
24
  claide-plugins (>= 0.9.2)
25
25
  colored2 (~> 3.1)
@@ -34,17 +34,18 @@ GEM
34
34
  terminal-table (>= 1, < 4)
35
35
  danger-plugin-api (1.0.0)
36
36
  danger (> 2.0)
37
- diff-lcs (1.4.4)
38
- faraday (1.8.0)
37
+ diff-lcs (1.5.0)
38
+ faraday (1.9.3)
39
39
  faraday-em_http (~> 1.0)
40
40
  faraday-em_synchrony (~> 1.0)
41
41
  faraday-excon (~> 1.1)
42
- faraday-httpclient (~> 1.0.1)
42
+ faraday-httpclient (~> 1.0)
43
+ faraday-multipart (~> 1.0)
43
44
  faraday-net_http (~> 1.0)
44
- faraday-net_http_persistent (~> 1.1)
45
+ faraday-net_http_persistent (~> 1.0)
45
46
  faraday-patron (~> 1.0)
46
47
  faraday-rack (~> 1.0)
47
- multipart-post (>= 1.2, < 3)
48
+ faraday-retry (~> 1.0)
48
49
  ruby2_keywords (>= 0.0.4)
49
50
  faraday-em_http (1.0.0)
50
51
  faraday-em_synchrony (1.0.0)
@@ -52,13 +53,16 @@ GEM
52
53
  faraday-http-cache (2.2.0)
53
54
  faraday (>= 0.8)
54
55
  faraday-httpclient (1.0.1)
56
+ faraday-multipart (1.0.2)
57
+ multipart-post (>= 1.2, < 3)
55
58
  faraday-net_http (1.0.1)
56
59
  faraday-net_http_persistent (1.2.0)
57
60
  faraday-patron (1.0.0)
58
61
  faraday-rack (1.0.0)
62
+ faraday-retry (1.0.3)
59
63
  ffi (1.15.4)
60
64
  formatador (0.3.0)
61
- git (1.9.1)
65
+ git (1.10.2)
62
66
  rchardet (~> 1.8)
63
67
  guard (2.18.0)
64
68
  formatador (>= 0.2.4)
@@ -95,7 +99,7 @@ GEM
95
99
  sawyer (~> 0.8.0, >= 0.5.3)
96
100
  open4 (1.3.4)
97
101
  parallel (1.21.0)
98
- parser (3.0.2.0)
102
+ parser (3.1.0.0)
99
103
  ast (~> 2.4.1)
100
104
  pry (0.14.1)
101
105
  coderay (~> 1.1)
@@ -107,7 +111,7 @@ GEM
107
111
  rb-inotify (0.10.1)
108
112
  ffi (~> 1.0)
109
113
  rchardet (1.8.0)
110
- regexp_parser (2.1.1)
114
+ regexp_parser (2.2.0)
111
115
  rexml (3.2.5)
112
116
  rspec (3.10.0)
113
117
  rspec-core (~> 3.10.0)
@@ -122,16 +126,16 @@ GEM
122
126
  diff-lcs (>= 1.2.0, < 2.0)
123
127
  rspec-support (~> 3.10.0)
124
128
  rspec-support (3.10.3)
125
- rubocop (1.22.3)
129
+ rubocop (1.24.1)
126
130
  parallel (~> 1.10)
127
131
  parser (>= 3.0.0.0)
128
132
  rainbow (>= 2.2.2, < 4.0)
129
133
  regexp_parser (>= 1.8, < 3.0)
130
134
  rexml
131
- rubocop-ast (>= 1.12.0, < 2.0)
135
+ rubocop-ast (>= 1.15.1, < 2.0)
132
136
  ruby-progressbar (~> 1.7)
133
137
  unicode-display_width (>= 1.4.0, < 3.0)
134
- rubocop-ast (1.12.0)
138
+ rubocop-ast (1.15.1)
135
139
  parser (>= 3.0.1.1)
136
140
  ruby-progressbar (1.11.0)
137
141
  ruby2_keywords (0.0.5)
@@ -141,9 +145,11 @@ GEM
141
145
  shellany (0.0.1)
142
146
  terminal-table (3.0.2)
143
147
  unicode-display_width (>= 1.1.1, < 3)
144
- thor (1.1.0)
148
+ thor (1.2.1)
145
149
  unicode-display_width (2.1.0)
146
- yard (0.9.26)
150
+ webrick (1.7.0)
151
+ yard (0.9.27)
152
+ webrick (~> 1.7.0)
147
153
 
148
154
  PLATFORMS
149
155
  ruby
data/README.md CHANGED
@@ -6,6 +6,9 @@
6
6
 
7
7
  $ gem install danger-phpmd
8
8
 
9
+ `phpmd` also needs to be installed before you run Danger.
10
+ Please check the [installation guide](https://phpmd.org/download/index.html).
11
+
9
12
  ## Usage
10
13
 
11
14
  Add this to Dangerfile.
@@ -22,5 +25,33 @@ phpmd.run ruleset: "rulesets.xml"
22
25
  ```
23
26
 
24
27
 
28
+ ### GitHub actions
29
+
30
+ ```yaml
31
+ name: CI
32
+
33
+ on: [pull_request]
25
34
 
35
+ jobs:
36
+ danger:
37
+ runs-on: ubuntu-latest
38
+ if: github.event_name == 'pull_request'
39
+ steps:
40
+ - uses: actions/checkout@v2
41
+ - uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: 2.6
44
+ bundler-cache: true
45
+
46
+ - name: Setup PHP environment
47
+ uses: shivammathur/setup-php@v2
48
+ with:
49
+ php-version: '8.0'
50
+ coverage: none
51
+ tools: phpmd
52
+
53
+ - run: bundle exec danger
54
+ env:
55
+ DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56
+ ```
26
57
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phpmd
4
- VERSION = "0.0.3"
4
+ VERSION = "0.1.0"
5
5
  end
data/lib/phpmd/plugin.rb CHANGED
@@ -23,9 +23,10 @@ module Danger
23
23
  # @return [void]
24
24
  def run(options)
25
25
  return if target_files.empty?
26
- cmd = binary_path || "phpmd"
27
- json,e,s = Open3.capture3(cmd, target_files.join(","), "json", options[:ruleset])
28
- results = parse(json)
26
+
27
+ tmpfile = Tempfile.open("phpmd_result")
28
+ Open3.capture3(cmd_path, "--reportfile", tmpfile.path, target_files.join(","), "json", options[:ruleset])
29
+ results = parse(tmpfile.read)
29
30
  results.each do |result|
30
31
  warn(result[:message], file: result[:file], line: result[:line])
31
32
  end
@@ -33,19 +34,26 @@ module Danger
33
34
 
34
35
  private
35
36
 
37
+ def cmd_path
38
+ return binary_path if binary_path
39
+
40
+ File.exist?("./vendor/bin/phpmd") ? "./vendor/bin/phpmd" : "phpmd"
41
+ end
42
+
36
43
  def parse(json)
37
44
  array = JSON.parse json
38
45
  return if array.empty?
46
+
39
47
  path = "#{Dir.pwd}/"
40
48
 
41
49
  results = []
42
- array['files'].each do |line|
43
- file = line['file'].sub(path, "")
44
- line['violations'].each do |violation|
50
+ array["files"].each do |line|
51
+ file = line["file"].sub(path, "")
52
+ line["violations"].each do |violation|
45
53
  results << {
46
- message: violation['description'],
54
+ message: violation["description"],
47
55
  file: file,
48
- line: violation['beginLine']
56
+ line: violation["beginLine"]
49
57
  }
50
58
  end
51
59
  end
@@ -53,7 +61,7 @@ module Danger
53
61
  end
54
62
 
55
63
  def target_files
56
- ((git.added_files + (git.modified_files - git.deleted_files)) - git.renamed_files.map{|r|r[:before]} + git.renamed_files.map{|r|r[:after]}).uniq
64
+ ((git.added_files + (git.modified_files - git.deleted_files)) - git.renamed_files.map { |r| r[:before] } + git.renamed_files.map { |r| r[:after] }).uniq
57
65
  end
58
66
  end
59
67
  end
@@ -0,0 +1,11 @@
1
+ <?php
2
+ class Foo
3
+ {
4
+ public function bar($flag) {
5
+ if ($flag) {
6
+ echo 'Hello';
7
+ } else {
8
+ echo 'World';
9
+ }
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ <?php
data/spec/phpmd_spec.rb CHANGED
@@ -8,39 +8,44 @@ module Danger
8
8
  expect(Danger::DangerPhpmd.new(nil)).to be_a Danger::Plugin
9
9
  end
10
10
 
11
- #
12
- # You should test your custom attributes and methods here
13
- #
14
11
  describe "with Dangerfile" do
15
12
  before do
16
13
  @dangerfile = testing_dangerfile
17
14
  @my_plugin = @dangerfile.phpmd
18
-
19
- # mock the PR data
20
- # you can then use this, eg. github.pr_author, later in the spec
21
- 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`
22
- allow(@my_plugin.github).to receive(:pr_json).and_return(json)
23
15
  end
24
16
 
25
- # Some examples for writing tests
26
- # You should replace these with your own.
27
-
28
- it "Warns on a monday" do
29
- monday_date = Date.parse("2016-07-11")
30
- allow(Date).to receive(:today).and_return monday_date
17
+ context "with a file included no warnings" do
18
+ before do
19
+ allow(@my_plugin).to receive(:target_files).and_return(
20
+ [File.expand_path("fixtures/no_warnings.php", __dir__)]
21
+ )
22
+ end
31
23
 
32
- @my_plugin.warn_on_mondays
24
+ it "warns nothing" do
25
+ @my_plugin.run({ ruleset: "cleancode" })
33
26
 
34
- expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"])
27
+ expect(@dangerfile.status_report[:warnings]).to eq([])
28
+ end
35
29
  end
36
30
 
37
- it "Does nothing on a tuesday" do
38
- monday_date = Date.parse("2016-07-12")
39
- allow(Date).to receive(:today).and_return monday_date
31
+ context "with a file included some warnings" do
32
+ let(:expected_message) { "The method bar uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them." }
33
+ before do
34
+ allow(@my_plugin).to receive(:target_files).and_return(
35
+ [File.expand_path("fixtures/cleancode_warnings.php", __dir__)]
36
+ )
37
+ end
38
+
39
+ it "warns nothing" do
40
+ @my_plugin.run({ ruleset: "cleancode" })
40
41
 
41
- @my_plugin.warn_on_mondays
42
+ expect(@dangerfile.status_report[:warnings]).to eq([expected_message])
42
43
 
43
- expect(@dangerfile.status_report[:warnings]).to eq([])
44
+ violation_report = @dangerfile.violation_report[:warnings].first
45
+ expect(violation_report.file).to eq("spec/fixtures/cleancode_warnings.php")
46
+ expect(violation_report.line).to eq(7)
47
+ expect(violation_report.message).to eq(expected_message)
48
+ end
44
49
  end
45
50
  end
46
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-phpmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyosuke Takayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-06 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -157,6 +157,7 @@ executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
+ - ".github/workflows/CI.yml"
160
161
  - ".gitignore"
161
162
  - ".rubocop.yml"
162
163
  - Gemfile
@@ -170,6 +171,8 @@ files:
170
171
  - lib/danger_plugin.rb
171
172
  - lib/phpmd/gem_version.rb
172
173
  - lib/phpmd/plugin.rb
174
+ - spec/fixtures/cleancode_warnings.php
175
+ - spec/fixtures/no_warnings.php
173
176
  - spec/phpmd_spec.rb
174
177
  - spec/spec_helper.rb
175
178
  homepage: https://github.com/ktakayama/danger-phpmd
@@ -191,10 +194,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
194
  - !ruby/object:Gem::Version
192
195
  version: '0'
193
196
  requirements: []
194
- rubygems_version: 3.0.3
197
+ rubygems_version: 3.3.3
195
198
  signing_key:
196
199
  specification_version: 4
197
200
  summary: Danger plugin for PHPMD.
198
201
  test_files:
202
+ - spec/fixtures/cleancode_warnings.php
203
+ - spec/fixtures/no_warnings.php
199
204
  - spec/phpmd_spec.rb
200
205
  - spec/spec_helper.rb