danger-pmd 0.4.0 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/danger_plugin.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pmd/plugin"
3
+ require 'pmd/plugin'
data/lib/danger_pmd.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pmd/gem_version"
3
+ require 'pmd/gem_version'
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Represent a PMD file.
3
4
  class PmdFile
4
- require_relative "./pmd_violation"
5
+ require_relative './pmd_violation'
5
6
 
6
7
  attr_accessor :file
7
8
 
@@ -17,23 +18,18 @@ class PmdFile
17
18
 
18
19
  def initialize(prefix, file)
19
20
  @file = file
20
- @absolute_path = file.attribute("name").value.to_s
21
-
22
- if prefix.end_with?(file_separator)
23
- @prefix = prefix
24
- else
25
- @prefix = prefix + file_separator
26
- end
27
-
28
- if @absolute_path.start_with?(@prefix)
29
- @relative_path = @absolute_path[@prefix.length, @absolute_path.length - @prefix.length]
30
- else
31
- @relative_path = @absolute_path
32
- end
21
+ @absolute_path = file.attribute('name').value.to_s
22
+
23
+ prefix += (prefix.end_with?(file_separator) ? '' : file_separator)
24
+ @relative_path = if @absolute_path.start_with?(prefix)
25
+ @absolute_path[prefix.length, @absolute_path.length - prefix.length]
26
+ else
27
+ @absolute_path
28
+ end
33
29
  end
34
30
 
35
31
  def violations
36
- @violations ||= file.xpath("violation").map do |pmd_violation|
32
+ @violations ||= file.xpath('violation').map do |pmd_violation|
37
33
  PmdViolation.new(pmd_violation)
38
34
  end
39
35
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Represent a PMD violation.
3
4
  class PmdViolation
4
5
  PRIORITY_ERROR_THRESHOLD = 4
5
6
  attr_accessor :violation
@@ -9,7 +10,7 @@ class PmdViolation
9
10
  end
10
11
 
11
12
  def priority
12
- @priority ||= violation.attribute("priority").value.to_i
13
+ @priority ||= violation.attribute('priority').value.to_i
13
14
  end
14
15
 
15
16
  def type
@@ -17,10 +18,10 @@ class PmdViolation
17
18
  end
18
19
 
19
20
  def line
20
- @line ||= violation.attribute("beginline").value.to_i
21
+ @line ||= violation.attribute('beginline').value.to_i
21
22
  end
22
23
 
23
24
  def description
24
- @description ||= violation.text.gsub("\n", "")
25
+ @description ||= violation.text.gsub("\n", '')
25
26
  end
26
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pmd
4
- VERSION = "0.4.0"
4
+ VERSION = '1.0.5'
5
5
  end
data/lib/pmd/plugin.rb CHANGED
@@ -11,50 +11,57 @@ module Danger
11
11
  #
12
12
  # @example Running PMD with a specific Gradle task or report file (glob accepted)
13
13
  #
14
- # pmd.gradle_task = 'app:pmd' #defalut: pmd
15
- # pmd.report_file = "module/build/reports/pmd/pmd.xml" #defalut: app/build/reports/pmd/pmd.xml
14
+ # pmd.gradle_task = 'module:pmd' # default: 'pmd'
15
+ # pmd.report_file = 'module/build/reports/pmd/pmd.xml' # default: 'app/build/reports/pmd/pmd.xml'
16
16
  # pmd.report
17
17
  #
18
18
  # @example Running PMD with a specific root path
19
19
  #
20
- # pmd.root_path = '/Users/developer/project
20
+ # pmd.root_path = '/Users/developer/project' # default: result of `git rev-parse --show-toplevel`
21
21
  # pmd.report
22
22
  #
23
23
  # @example Running PMD with an array of report files (glob accepted)
24
24
  #
25
- # pmd.report_files = ["modules/**/build/reports/pmd/pmd.xml", "app/build/reports/pmd/pmd.xml"]
25
+ # pmd.report_files = ['modules/**/build/reports/pmd/pmd.xml', 'app/build/reports/pmd/pmd.xml']
26
26
  # pmd.report
27
27
  #
28
28
  # @example Running PMD without running a Gradle task
29
29
  #
30
- # pmd.skip_gradle_task = true
30
+ # pmd.skip_gradle_task = true # default: false
31
31
  # pmd.report
32
32
  #
33
+ # @example Running PMD without inline comment
34
+ #
35
+ # pmd.report(inline_mode: false) # default: true
36
+ #
33
37
  # @see mathroule/danger-pmd
34
38
  # @tags java, android, pmd
35
-
36
39
  class DangerPmd < Plugin
37
- require_relative "./entity/pmd_file"
40
+ require_relative './entity/pmd_file'
38
41
 
39
42
  # Custom Gradle task to run.
40
43
  # This is useful when your project has different flavors.
41
- # Defaults to "pmd".
44
+ # Defaults to 'pmd'.
45
+ #
42
46
  # @return [String]
43
47
  attr_writer :gradle_task
44
48
 
45
- # A getter for `gradle_task`, returning "pmd" if value is nil.
49
+ # A getter for `gradle_task`, returning 'pmd' if value is nil.
50
+ #
46
51
  # @return [String]
47
52
  def gradle_task
48
- @gradle_task ||= "pmd"
53
+ @gradle_task ||= 'pmd'
49
54
  end
50
55
 
51
56
  # Skip Gradle task.
52
57
  # If you skip Gradle task, for example project does not manage Gradle.
53
58
  # Defaults to `false`.
54
- # @return [Bool]
59
+ #
60
+ # @return [Boolean]
55
61
  attr_writer :skip_gradle_task
56
62
 
57
63
  # A getter for `skip_gradle_task`, returning false if value is nil.
64
+ #
58
65
  # @return [Boolean]
59
66
  def skip_gradle_task
60
67
  @skip_gradle_task ||= false
@@ -62,35 +69,41 @@ module Danger
62
69
 
63
70
  # An absolute path to a root.
64
71
  # To comment errors to VCS, this needs to know relative path of files from the root.
65
- # Defaults to result of "git rev-parse --show-toplevel".
66
- # @return [String] the root path of git repository by default.
72
+ # Defaults to result of 'git rev-parse --show-toplevel'.
73
+ #
74
+ # @return [String]
67
75
  attr_writer :root_path
68
76
 
69
- # A getter for `root_path`, returning result of "git rev-parse --show-toplevel" if value is nil.
77
+ # A getter for `root_path`, returning result of `git rev-parse --show-toplevel` if value is nil.
78
+ #
70
79
  # @return [String]
71
80
  def root_path
72
81
  @root_path ||= `git rev-parse --show-toplevel`.chomp
73
82
  end
74
83
 
75
84
  # Location of report file.
76
- # If your pmd task outputs to a different location, you can specify it here.
77
- # Defaults to "app/build/reports/pmd/pmd.xml".
85
+ # If your PMD task task outputs to a different location, you can specify it here.
86
+ # Defaults to 'app/build/reports/pmd/pmd.xml'.
87
+ #
78
88
  # @return [String]
79
89
  attr_writer :report_file
80
90
 
81
- # A getter for `report_file`, returning "app/build/reports/pmd/pmd.xml" if value is nil.
91
+ # A getter for `report_file`, returning 'app/build/reports/pmd/pmd.xml' if value is nil.
92
+ #
82
93
  # @return [String]
83
94
  def report_file
84
- @report_file ||= "app/build/reports/pmd/pmd.xml"
95
+ @report_file ||= 'app/build/reports/pmd/pmd.xml'
85
96
  end
86
97
 
87
98
  # Location of report files.
88
- # If your pmd task outputs to a different location, you can specify it here.
89
- # Defaults to ["app/build/reports/pmd/pmd.xml"].
99
+ # If your PMD task outputs to a different location, you can specify it here.
100
+ # Defaults to ['app/build/reports/pmd/pmd.xml'].
101
+ #
90
102
  # @return [Array[String]]
91
103
  attr_writer :report_files
92
104
 
93
- # A getter for `report_files`, returning ["app/build/reports/pmd/pmd.xml"] if value is nil.
105
+ # A getter for `report_files`, returning ['app/build/reports/pmd/pmd.xml'] if value is nil.
106
+ #
94
107
  # @return [Array[String]]
95
108
  def report_files
96
109
  @report_files ||= [report_file]
@@ -100,16 +113,19 @@ module Danger
100
113
  # It fails if `gradlew` cannot be found inside current directory.
101
114
  # It fails if `report_file` cannot be found inside current directory.
102
115
  # It fails if `report_files` is empty.
116
+ #
117
+ # @param [Boolean] inline_mode Report as inline comment, defaults to [true].
118
+ #
103
119
  # @return [Array[PmdFile]]
104
- def report(inline_mode = true)
120
+ def report(inline_mode: true)
105
121
  unless skip_gradle_task
106
- return fail("Could not find `gradlew` inside current directory") unless gradlew_exists?
122
+ raise('Could not find `gradlew` inside current directory') unless gradlew_exists?
107
123
 
108
124
  exec_gradle_task
109
125
  end
110
126
 
111
127
  report_files_expanded = Dir.glob(report_files).sort
112
- return fail("Could not find matching PMD report files for #{report_files} inside current directory") if report_files_expanded.empty?
128
+ raise("Could not find matching PMD report files for #{report_files} inside current directory") if report_files_expanded.empty?
113
129
 
114
130
  do_comment(report_files_expanded, inline_mode)
115
131
  end
@@ -117,47 +133,53 @@ module Danger
117
133
  private
118
134
 
119
135
  # Check gradlew file exists in current directory.
120
- # @return [Bool]
136
+ #
137
+ # @return [Boolean]
121
138
  def gradlew_exists?
122
139
  !`ls gradlew`.strip.empty?
123
140
  end
124
141
 
125
142
  # Run Gradle task.
143
+ #
126
144
  # @return [void]
127
145
  def exec_gradle_task
128
146
  system "./gradlew #{gradle_task}"
129
147
  end
130
148
 
131
- # Check report_file exists in current directory.
132
- # @return [Bool]
133
- def report_file_exist?(report_file)
134
- File.exist?(report_file)
135
- end
136
-
137
149
  # A getter for `pmd_report`, returning PMD report.
150
+ #
151
+ # @param [String] report_file The report file.
152
+ #
138
153
  # @return [Oga::XML::Document]
139
154
  def pmd_report(report_file)
140
- require "oga"
155
+ require 'oga'
141
156
  Oga.parse_xml(File.open(report_file))
142
157
  end
143
158
 
144
159
  # A getter for PMD issues, returning PMD issues.
160
+ #
161
+ # @param [String] report_file The report file.
162
+ #
145
163
  # @return [Array[PmdFile]]
146
164
  def pmd_issues(report_file)
147
- pmd_report(report_file).xpath("//file").map do |pmd_file|
165
+ pmd_report(report_file).xpath('//file').map do |pmd_file|
148
166
  PmdFile.new(root_path, pmd_file)
149
167
  end
150
168
  end
151
169
 
152
170
  # A getter for current updated files.
171
+ #
153
172
  # @return [Array[String]]
154
173
  def target_files
155
174
  @target_files ||= (git.modified_files - git.deleted_files) + git.added_files
156
175
  end
157
176
 
158
177
  # Generate report and send inline comment with Danger's warn or fail method.
178
+ #
179
+ # @param [Boolean] inline_mode Report as inline comment, defaults to [true].
180
+ #
159
181
  # @return [Array[PmdFile]]
160
- def do_comment(report_files, inline_mode = true)
182
+ def do_comment(report_files, inline_mode)
161
183
  pmd_issues = []
162
184
 
163
185
  report_files.each do |report_file|
@@ -166,17 +188,21 @@ module Danger
166
188
 
167
189
  pmd_issues.push(pmd_file)
168
190
 
169
- pmd_file.violations.each do |pmd_violation|
170
- if inline_mode
171
- send(pmd_violation.type, pmd_violation.description, file: pmd_file.relative_path, line: pmd_violation.line)
172
- else
173
- send(pmd_violation.type, "#{pmd_file.relative_path} : #{pmd_violation.description} at #{pmd_violation.line}")
174
- end
175
- end
191
+ send_comment(pmd_file, inline_mode)
176
192
  end
177
193
  end
178
194
 
179
195
  pmd_issues
180
196
  end
197
+
198
+ def send_comment(pmd_file, inline_mode)
199
+ pmd_file.violations.each do |pmd_violation|
200
+ if inline_mode
201
+ send(pmd_violation.type, pmd_violation.description, file: pmd_file.relative_path, line: pmd_violation.line)
202
+ else
203
+ send(pmd_violation.type, "#{pmd_file.relative_path} : #{pmd_violation.description} at #{pmd_violation.line}")
204
+ end
205
+ end
206
+ end
181
207
  end
182
208
  end
@@ -3,15 +3,15 @@
3
3
  require_relative "../spec_helper"
4
4
 
5
5
  module Pmd
6
- require "oga"
6
+ require 'oga'
7
7
 
8
8
  describe PmdFile do
9
- it "should initialize relative path ending with file separator" do
10
- xml = Oga.parse_xml(File.open("spec/fixtures/pmd_report.xml"))
11
- pmd_file = PmdFile.new("/Users/developer/sample/", xml.xpath("//file").first)
9
+ it 'should initialize relative path ending with file separator' do
10
+ xml = Oga.parse_xml(File.open('spec/fixtures/pmd_report.xml'))
11
+ pmd_file = PmdFile.new('/Users/developer/sample/', xml.xpath('//file').first)
12
12
 
13
- expect(pmd_file.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
14
- expect(pmd_file.relative_path).to eq("app/src/main/java/com/android/sample/Tools.java")
13
+ expect(pmd_file.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
14
+ expect(pmd_file.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
15
15
  expect(pmd_file.violations).not_to be_nil
16
16
  expect(pmd_file.violations.length).to eq(1)
17
17
  expect(pmd_file.violations.first).not_to be_nil
@@ -19,12 +19,12 @@ module Pmd
19
19
  expect(pmd_file.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
20
20
  end
21
21
 
22
- it "should initialize relative path not ending with file separator" do
23
- xml = Oga.parse_xml(File.open("spec/fixtures/pmd_report.xml"))
24
- pmd_file = PmdFile.new("/Users/developer/sample", xml.xpath("//file").first)
22
+ it 'should initialize relative path not ending with file separator' do
23
+ xml = Oga.parse_xml(File.open('spec/fixtures/pmd_report.xml'))
24
+ pmd_file = PmdFile.new('/Users/developer/sample', xml.xpath('//file').first)
25
25
 
26
- expect(pmd_file.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
27
- expect(pmd_file.relative_path).to eq("app/src/main/java/com/android/sample/Tools.java")
26
+ expect(pmd_file.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
27
+ expect(pmd_file.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
28
28
  expect(pmd_file.violations).not_to be_nil
29
29
  expect(pmd_file.violations.length).to eq(1)
30
30
  expect(pmd_file.violations.first).not_to be_nil
@@ -32,12 +32,12 @@ module Pmd
32
32
  expect(pmd_file.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
33
33
  end
34
34
 
35
- it "should initialize relative path not prefixed" do
36
- xml = Oga.parse_xml(File.open("spec/fixtures/pmd_report.xml"))
37
- pmd_file = PmdFile.new("/Users/developer/something", xml.xpath("//file").first)
35
+ it 'should initialize relative path not prefixed' do
36
+ xml = Oga.parse_xml(File.open('spec/fixtures/pmd_report.xml'))
37
+ pmd_file = PmdFile.new('/Users/developer/something', xml.xpath('//file').first)
38
38
 
39
- expect(pmd_file.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
40
- expect(pmd_file.relative_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
39
+ expect(pmd_file.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
40
+ expect(pmd_file.relative_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
41
41
  expect(pmd_file.violations).not_to be_nil
42
42
  expect(pmd_file.violations.length).to eq(1)
43
43
  expect(pmd_file.violations.first).not_to be_nil
data/spec/pmd_spec.rb CHANGED
@@ -1,80 +1,85 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path("spec_helper", __dir__)
3
+ require File.expand_path('spec_helper', __dir__)
4
4
 
5
5
  module Danger
6
6
  describe Danger::DangerPmd do
7
- it "should be a plugin" do
7
+ it 'should be a plugin' do
8
8
  expect(Danger::DangerPmd.new(nil)).to be_a Danger::Plugin
9
9
  end
10
10
 
11
- describe "with Dangerfile" do
11
+ describe 'with Dangerfile' do
12
12
  before do
13
13
  @dangerfile = testing_dangerfile
14
14
  @pmd = @dangerfile.pmd
15
15
  end
16
16
 
17
- it "Check default Gradle task" do
18
- expect(@pmd.gradle_task).to eq("pmd")
17
+ it 'Check default Gradle task' do
18
+ expect(@pmd.gradle_task).to eq('pmd')
19
19
  end
20
20
 
21
- it "Set custom Gradle task" do
22
- custom_task = "pmdStagingDebug"
23
- @pmd.gradle_task = custom_task
24
- expect(@pmd.gradle_task).to eq(custom_task)
21
+ it 'Set custom Gradle task' do
22
+ @pmd.gradle_task = 'pmdStagingDebug'
23
+ expect(@pmd.gradle_task).to eq('pmdStagingDebug')
25
24
  end
26
25
 
27
- it "Check default skip Gradle task" do
28
- expect(@pmd.skip_gradle_task).to eq(false)
26
+ it 'Check default skip Gradle task' do
27
+ expect(@pmd.skip_gradle_task).to be_falsey
29
28
  end
30
29
 
31
- it "Set custom skip Gradle task" do
32
- skip_gradle_task = true
33
- @pmd.skip_gradle_task = skip_gradle_task
34
- expect(@pmd.skip_gradle_task).to eq(skip_gradle_task)
30
+ it 'Set custom skip Gradle task' do
31
+ @pmd.skip_gradle_task = true
32
+ expect(@pmd.skip_gradle_task).to be_truthy
33
+ end
34
+
35
+ it 'Check default root path' do
36
+ expect(@pmd.root_path).to eq(Dir.pwd)
37
+ end
38
+
39
+ it 'Set custom root path' do
40
+ @pmd.root_path = '/Users/developer/project'
41
+ expect(@pmd.root_path).to eq('/Users/developer/project')
35
42
  end
36
43
 
37
- it "Check default report file path" do
38
- expect(@pmd.report_file).to eq("app/build/reports/pmd/pmd.xml")
44
+ it 'Check default report file path' do
45
+ expect(@pmd.report_file).to eq('app/build/reports/pmd/pmd.xml')
39
46
  end
40
47
 
41
- it "Set custom report file path" do
42
- custom_report_path = "custom-path/pmd_sub_report.xml"
43
- @pmd.report_file = custom_report_path
44
- expect(@pmd.report_file).to eq(custom_report_path)
48
+ it 'Set custom report file path' do
49
+ @pmd.report_file = 'custom-path/pmd_sub_report.xml'
50
+ expect(@pmd.report_file).to eq('custom-path/pmd_sub_report.xml')
45
51
  end
46
52
 
47
- it "Check default report files paths" do
48
- expect(@pmd.report_files).to eq(["app/build/reports/pmd/pmd.xml"])
53
+ it 'Check default report files paths' do
54
+ expect(@pmd.report_files).to contain_exactly('app/build/reports/pmd/pmd.xml')
49
55
  end
50
56
 
51
- it "Set custom report files paths" do
52
- custom_report_paths = ["custom-path/pmd_report_1.xml", "custom-path/pmd_report_2.xml"]
53
- @pmd.report_files = custom_report_paths
54
- expect(@pmd.report_files).to eq(custom_report_paths)
57
+ it 'Set custom report files paths' do
58
+ @pmd.report_files = %w[custom-path/pmd_report_1.xml custom-path/pmd_report_2.xml]
59
+ expect(@pmd.report_files).to contain_exactly('custom-path/pmd_report_1.xml', 'custom-path/pmd_report_2.xml')
55
60
  end
56
61
 
57
- it "Check default root path" do
62
+ it 'Check default root path' do
58
63
  expect(@pmd.root_path).to eq(Dir.pwd)
59
64
  end
60
65
 
61
- it "Set custom root path" do
62
- root_path = "/Users/developer/sample/"
63
- @pmd.root_path = root_path
64
- expect(@pmd.root_path).to eq(root_path)
66
+ it 'Set custom root path' do
67
+ @pmd.root_path = '/Users/developer/sample/'
68
+ expect(@pmd.root_path).to eq('/Users/developer/sample/')
65
69
  end
66
70
 
67
- it "Report with report file" do
71
+ it 'Report with report file' do
72
+ # noinspection RubyLiteralArrayInspection
68
73
  target_files = [
69
- "app/src/main/java/com/android/sample/MainActivity.java",
70
- "app/src/main/java/com/android/sample/Tools.java",
71
- "app/src/test/java/com/android/sample/ExampleUnitTest.java",
72
- "app/src/test/java/com/android/sample/ToolsTest.java"
74
+ 'app/src/main/java/com/android/sample/MainActivity.java',
75
+ 'app/src/main/java/com/android/sample/Tools.java',
76
+ 'app/src/test/java/com/android/sample/ExampleUnitTest.java',
77
+ 'app/src/test/java/com/android/sample/ToolsTest.java'
73
78
  ]
74
79
  allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
75
80
 
76
- @pmd.report_file = "spec/fixtures/pmd_report.xml"
77
- @pmd.root_path = "/Users/developer/sample/"
81
+ @pmd.report_file = 'spec/fixtures/pmd_report.xml'
82
+ @pmd.root_path = '/Users/developer/sample/'
78
83
  @pmd.skip_gradle_task = true
79
84
 
80
85
  pmd_issues = @pmd.report
@@ -83,8 +88,8 @@ module Danger
83
88
 
84
89
  pmd_issue1 = pmd_issues[0]
85
90
  expect(pmd_issue1).not_to be_nil
86
- expect(pmd_issue1.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
87
- expect(pmd_issue1.relative_path).to eq("app/src/main/java/com/android/sample/Tools.java")
91
+ expect(pmd_issue1.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
92
+ expect(pmd_issue1.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
88
93
  expect(pmd_issue1.violations).not_to be_nil
89
94
  expect(pmd_issue1.violations.length).to eq(1)
90
95
  expect(pmd_issue1.violations.first).not_to be_nil
@@ -93,8 +98,8 @@ module Danger
93
98
 
94
99
  pmd_issue2 = pmd_issues[1]
95
100
  expect(pmd_issue2).not_to be_nil
96
- expect(pmd_issue2.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
97
- expect(pmd_issue2.relative_path).to eq("app/src/main/java/com/android/sample/MainActivity.java")
101
+ expect(pmd_issue2.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java')
102
+ expect(pmd_issue2.relative_path).to eq('app/src/main/java/com/android/sample/MainActivity.java')
98
103
  expect(pmd_issue2.violations).not_to be_nil
99
104
  expect(pmd_issue2.violations.length).to eq(1)
100
105
  expect(pmd_issue2.violations.first).not_to be_nil
@@ -103,8 +108,8 @@ module Danger
103
108
 
104
109
  pmd_issue3 = pmd_issues[2]
105
110
  expect(pmd_issue3).not_to be_nil
106
- expect(pmd_issue3.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
107
- expect(pmd_issue3.relative_path).to eq("app/src/test/java/com/android/sample/ExampleUnitTest.java")
111
+ expect(pmd_issue3.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java')
112
+ expect(pmd_issue3.relative_path).to eq('app/src/test/java/com/android/sample/ExampleUnitTest.java')
108
113
  expect(pmd_issue3.violations).not_to be_nil
109
114
  expect(pmd_issue3.violations.length).to eq(1)
110
115
  expect(pmd_issue3.violations.first).not_to be_nil
@@ -113,8 +118,8 @@ module Danger
113
118
 
114
119
  pmd_issue4 = pmd_issues[3]
115
120
  expect(pmd_issue4).not_to be_nil
116
- expect(pmd_issue4.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
117
- expect(pmd_issue4.relative_path).to eq("app/src/test/java/com/android/sample/ToolsTest.java")
121
+ expect(pmd_issue4.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java')
122
+ expect(pmd_issue4.relative_path).to eq('app/src/test/java/com/android/sample/ToolsTest.java')
118
123
  expect(pmd_issue4.violations).not_to be_nil
119
124
  expect(pmd_issue4.violations.length).to eq(2)
120
125
  expect(pmd_issue4.violations[0]).not_to be_nil
@@ -125,15 +130,16 @@ module Danger
125
130
  expect(pmd_issue4.violations[1].description).to eq("The JUnit 4 test method name 'getLabel_2' doesn't match '[a-z][a-zA-Z0-9]*'")
126
131
  end
127
132
 
128
- it "Report with report file not in target files" do
133
+ it 'Report with report file not in target files' do
134
+ # noinspection RubyLiteralArrayInspection
129
135
  target_files = [
130
- "app/src/main/java/com/android/sample/Tools.java",
131
- "app/src/test/java/com/android/sample/ToolsTest.java"
136
+ 'app/src/main/java/com/android/sample/Tools.java',
137
+ 'app/src/test/java/com/android/sample/ToolsTest.java'
132
138
  ]
133
139
  allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
134
140
 
135
- @pmd.report_file = "spec/fixtures/pmd_report.xml"
136
- @pmd.root_path = "/Users/developer/sample/"
141
+ @pmd.report_file = 'spec/fixtures/pmd_report.xml'
142
+ @pmd.root_path = '/Users/developer/sample/'
137
143
  @pmd.skip_gradle_task = true
138
144
 
139
145
  pmd_issues = @pmd.report
@@ -142,8 +148,8 @@ module Danger
142
148
 
143
149
  pmd_issue1 = pmd_issues[0]
144
150
  expect(pmd_issue1).not_to be_nil
145
- expect(pmd_issue1.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
146
- expect(pmd_issue1.relative_path).to eq("app/src/main/java/com/android/sample/Tools.java")
151
+ expect(pmd_issue1.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
152
+ expect(pmd_issue1.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
147
153
  expect(pmd_issue1.violations).not_to be_nil
148
154
  expect(pmd_issue1.violations.length).to eq(1)
149
155
  expect(pmd_issue1.violations.first).not_to be_nil
@@ -152,8 +158,8 @@ module Danger
152
158
 
153
159
  pmd_issue2 = pmd_issues[1]
154
160
  expect(pmd_issue2).not_to be_nil
155
- expect(pmd_issue2.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
156
- expect(pmd_issue2.relative_path).to eq("app/src/test/java/com/android/sample/ToolsTest.java")
161
+ expect(pmd_issue2.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java')
162
+ expect(pmd_issue2.relative_path).to eq('app/src/test/java/com/android/sample/ToolsTest.java')
157
163
  expect(pmd_issue2.violations).not_to be_nil
158
164
  expect(pmd_issue2.violations.length).to eq(2)
159
165
  expect(pmd_issue2.violations[0]).not_to be_nil
@@ -164,19 +170,20 @@ module Danger
164
170
  expect(pmd_issue2.violations[1].description).to eq("The JUnit 4 test method name 'getLabel_2' doesn't match '[a-z][a-zA-Z0-9]*'")
165
171
  end
166
172
 
167
- it "Report with report files" do
173
+ it 'Report with report files' do
174
+ # noinspection RubyLiteralArrayInspection
168
175
  target_files = [
169
- "app/src/main/java/com/android/sample/Application.java",
170
- "app/src/main/java/com/android/sample/MainActivity.java",
171
- "app/src/main/java/com/android/sample/Tools.java",
172
- "app/src/main/java/com/android/sample/Utils.java",
173
- "app/src/test/java/com/android/sample/ExampleUnitTest.java",
174
- "app/src/test/java/com/android/sample/ToolsTest.java"
176
+ 'app/src/main/java/com/android/sample/Application.java',
177
+ 'app/src/main/java/com/android/sample/MainActivity.java',
178
+ 'app/src/main/java/com/android/sample/Tools.java',
179
+ 'app/src/main/java/com/android/sample/Utils.java',
180
+ 'app/src/test/java/com/android/sample/ExampleUnitTest.java',
181
+ 'app/src/test/java/com/android/sample/ToolsTest.java'
175
182
  ]
176
183
  allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
177
184
 
178
- @pmd.report_files = ["spec/fixtures/pmd_report.xml", "spec/fixtures/**/pmd_sub_report.xml"]
179
- @pmd.root_path = "/Users/developer/sample/"
185
+ @pmd.report_files = %w[spec/fixtures/pmd_report.xml spec/fixtures/**/pmd_sub_report.xml]
186
+ @pmd.root_path = '/Users/developer/sample/'
180
187
  @pmd.skip_gradle_task = true
181
188
 
182
189
  pmd_issues = @pmd.report
@@ -185,8 +192,8 @@ module Danger
185
192
 
186
193
  pmd_issue1 = pmd_issues[0]
187
194
  expect(pmd_issue1).not_to be_nil
188
- expect(pmd_issue1.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
189
- expect(pmd_issue1.relative_path).to eq("app/src/main/java/com/android/sample/Tools.java")
195
+ expect(pmd_issue1.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
196
+ expect(pmd_issue1.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
190
197
  expect(pmd_issue1.violations).not_to be_nil
191
198
  expect(pmd_issue1.violations.length).to eq(1)
192
199
  expect(pmd_issue1.violations.first).not_to be_nil
@@ -195,8 +202,8 @@ module Danger
195
202
 
196
203
  pmd_issue2 = pmd_issues[1]
197
204
  expect(pmd_issue2).not_to be_nil
198
- expect(pmd_issue2.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
199
- expect(pmd_issue2.relative_path).to eq("app/src/main/java/com/android/sample/MainActivity.java")
205
+ expect(pmd_issue2.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java')
206
+ expect(pmd_issue2.relative_path).to eq('app/src/main/java/com/android/sample/MainActivity.java')
200
207
  expect(pmd_issue2.violations).not_to be_nil
201
208
  expect(pmd_issue2.violations.length).to eq(1)
202
209
  expect(pmd_issue2.violations.first).not_to be_nil
@@ -205,8 +212,8 @@ module Danger
205
212
 
206
213
  pmd_issue3 = pmd_issues[2]
207
214
  expect(pmd_issue3).not_to be_nil
208
- expect(pmd_issue3.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
209
- expect(pmd_issue3.relative_path).to eq("app/src/test/java/com/android/sample/ExampleUnitTest.java")
215
+ expect(pmd_issue3.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java')
216
+ expect(pmd_issue3.relative_path).to eq('app/src/test/java/com/android/sample/ExampleUnitTest.java')
210
217
  expect(pmd_issue3.violations).not_to be_nil
211
218
  expect(pmd_issue3.violations.length).to eq(1)
212
219
  expect(pmd_issue3.violations.first).not_to be_nil
@@ -215,8 +222,8 @@ module Danger
215
222
 
216
223
  pmd_issue4 = pmd_issues[3]
217
224
  expect(pmd_issue4).not_to be_nil
218
- expect(pmd_issue4.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
219
- expect(pmd_issue4.relative_path).to eq("app/src/test/java/com/android/sample/ToolsTest.java")
225
+ expect(pmd_issue4.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java')
226
+ expect(pmd_issue4.relative_path).to eq('app/src/test/java/com/android/sample/ToolsTest.java')
220
227
  expect(pmd_issue4.violations).not_to be_nil
221
228
  expect(pmd_issue4.violations.length).to eq(2)
222
229
  expect(pmd_issue4.violations[0]).not_to be_nil
@@ -228,50 +235,44 @@ module Danger
228
235
 
229
236
  pmd_issue5 = pmd_issues[4]
230
237
  expect(pmd_issue5).not_to be_nil
231
- expect(pmd_issue5.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Utils.java")
232
- expect(pmd_issue5.relative_path).to eq("app/src/main/java/com/android/sample/Utils.java")
238
+ expect(pmd_issue5.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Utils.java')
239
+ expect(pmd_issue5.relative_path).to eq('app/src/main/java/com/android/sample/Utils.java')
233
240
  expect(pmd_issue5.violations).not_to be_nil
234
241
  expect(pmd_issue5.violations.length).to eq(2)
235
242
  expect(pmd_issue5.violations[0]).not_to be_nil
236
243
  expect(pmd_issue5.violations[0].line).to eq(23)
237
- expect(pmd_issue5.violations[0].description).to eq("These nested if statements could be combined")
244
+ expect(pmd_issue5.violations[0].description).to eq('These nested if statements could be combined')
238
245
  expect(pmd_issue5.violations[1]).not_to be_nil
239
246
  expect(pmd_issue5.violations[1].line).to eq(45)
240
- expect(pmd_issue5.violations[1].description).to eq("The String literal \"unused\" appears 4 times in this file; the first occurrence is on line 45")
247
+ expect(pmd_issue5.violations[1].description).to eq('The String literal "unused" appears 4 times in this file; the first occurrence is on line 45')
241
248
 
242
249
  pmd_issue6 = pmd_issues[5]
243
250
  expect(pmd_issue6).not_to be_nil
244
- expect(pmd_issue6.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Application.java")
245
- expect(pmd_issue6.relative_path).to eq("app/src/main/java/com/android/sample/Application.java")
251
+ expect(pmd_issue6.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Application.java')
252
+ expect(pmd_issue6.relative_path).to eq('app/src/main/java/com/android/sample/Application.java')
246
253
  expect(pmd_issue6.violations).not_to be_nil
247
254
  expect(pmd_issue6.violations.length).to eq(1)
248
255
  expect(pmd_issue6.violations[0]).not_to be_nil
249
256
  expect(pmd_issue6.violations[0].line).to eq(135)
250
- expect(pmd_issue6.violations[0].description).to eq("The String literal \"label\" appears 5 times in this file; the first occurrence is on line 135")
257
+ expect(pmd_issue6.violations[0].description).to eq('The String literal "label" appears 5 times in this file; the first occurrence is on line 135')
251
258
  end
252
259
 
253
- it "Report without Gradle" do
260
+ it 'Report without Gradle' do
254
261
  allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return([])
255
262
 
256
- @pmd.report_file = "spec/fixtures/pmd_report.xml"
263
+ @pmd.report_file = 'spec/fixtures/pmd_report.xml'
257
264
  @pmd.skip_gradle_task = false
258
265
 
259
- pmd_issues = @pmd.report
260
- expect(pmd_issues).not_to be_nil
261
- expect(pmd_issues.length).to be(1)
262
- expect(pmd_issues[0]).to be("Could not find `gradlew` inside current directory")
266
+ expect { @pmd.report }.to raise_error('Could not find `gradlew` inside current directory')
263
267
  end
264
268
 
265
- it "Report without existing report file" do
269
+ it 'Report without existing report file' do
266
270
  allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return([])
267
271
 
268
- @pmd.report_file = "spec/fixtures/custom/pmd_report.xml"
272
+ @pmd.report_file = 'spec/fixtures/custom/pmd_report.xml'
269
273
  @pmd.skip_gradle_task = true
270
274
 
271
- pmd_issues = @pmd.report
272
- expect(pmd_issues).not_to be_nil
273
- expect(pmd_issues.length).to be(1)
274
- expect(pmd_issues[0]).to eq("Could not find matching PMD report files for [\"spec/fixtures/custom/pmd_report.xml\"] inside current directory")
275
+ expect { @pmd.report }.to raise_error('Could not find matching PMD report files for ["spec/fixtures/custom/pmd_report.xml"] inside current directory')
275
276
  end
276
277
  end
277
278
  end