danger-pmd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 25bc46f8d31771647e30e868e5c70414c8a09f5d020351b4442f998698f7f8a5
4
+ data.tar.gz: 882f95e0c94495be3507a2f5be3af5e5eebcf26af3fe9f98fe3b37590719f22b
5
+ SHA512:
6
+ metadata.gz: 9e86137b4137acdc557fa7c17ddfe8958c3d2f153adbe1a2ce8eabfef2d24421aaa641777cecf85088fe9ff7d7b1b8a9bd5b75d52b1c8a761f03e628ee1e0b6b
7
+ data.tar.gz: 17a959da13097dab76c2eab0eee92357701a63f876a2b3743c2b57e4313175fe68a5e53f9d147f214b4c99bfeb72d1ab6131d3cd5f6af6619d03843ec78bef24
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
@@ -0,0 +1,152 @@
1
+ # Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+
3
+ # If you don't like these settings, just delete this file :)
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.3
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+ Enabled: true
11
+
12
+ # kind_of? is a good way to check a type
13
+ Style/ClassCheck:
14
+ EnforcedStyle: kind_of?
15
+
16
+ # It's better to be more explicit about the type
17
+ Style/BracesAroundHashParameters:
18
+ Enabled: false
19
+
20
+ # specs sometimes have useless assignments, which is fine
21
+ Lint/UselessAssignment:
22
+ Exclude:
23
+ - '**/spec/**/*'
24
+
25
+ # We could potentially enable the 2 below:
26
+ Layout/IndentFirstHashElement:
27
+ Enabled: false
28
+
29
+ Layout/AlignHash:
30
+ Enabled: false
31
+
32
+ # HoundCI doesn't like this rule
33
+ Layout/DotPosition:
34
+ Enabled: false
35
+
36
+ # We allow !! as it's an easy way to convert ot boolean
37
+ Style/DoubleNegation:
38
+ Enabled: false
39
+
40
+ # Cop supports --auto-correct.
41
+ Lint/UnusedBlockArgument:
42
+ Enabled: false
43
+
44
+ # We want to allow class Fastlane::Class
45
+ Style/ClassAndModuleChildren:
46
+ Enabled: false
47
+
48
+ Metrics/AbcSize:
49
+ Max: 60
50
+
51
+ # The %w might be confusing for new users
52
+ Style/WordArray:
53
+ MinSize: 19
54
+
55
+ # raise and fail are both okay
56
+ Style/SignalException:
57
+ Enabled: false
58
+
59
+ # Better too much 'return' than one missing
60
+ Style/RedundantReturn:
61
+ Enabled: false
62
+
63
+ # Having if in the same line might not always be good
64
+ Style/IfUnlessModifier:
65
+ Enabled: false
66
+
67
+ # and and or is okay
68
+ Style/AndOr:
69
+ Enabled: false
70
+
71
+ # Configuration parameters: CountComments.
72
+ Metrics/ClassLength:
73
+ Max: 350
74
+
75
+ Metrics/CyclomaticComplexity:
76
+ Max: 17
77
+
78
+ # Configuration parameters: AllowURI, URISchemes.
79
+ Metrics/LineLength:
80
+ Max: 370
81
+
82
+ # Configuration parameters: CountKeywordArgs.
83
+ Metrics/ParameterLists:
84
+ Max: 10
85
+
86
+ Metrics/PerceivedComplexity:
87
+ Max: 18
88
+
89
+ # Sometimes it's easier to read without guards
90
+ Style/GuardClause:
91
+ Enabled: false
92
+
93
+ # something = if something_else
94
+ # that's confusing
95
+ Style/ConditionalAssignment:
96
+ Enabled: false
97
+
98
+ # Better to have too much self than missing a self
99
+ Style/RedundantSelf:
100
+ Enabled: false
101
+
102
+ Metrics/MethodLength:
103
+ Max: 60
104
+
105
+ # We're not there yet
106
+ Style/Documentation:
107
+ Enabled: false
108
+
109
+ # Adds complexity
110
+ Style/IfInsideElse:
111
+ Enabled: false
112
+
113
+ # danger specific
114
+
115
+ Style/BlockComments:
116
+ Enabled: false
117
+
118
+ Layout/MultilineMethodCallIndentation:
119
+ EnforcedStyle: indented
120
+
121
+ # FIXME: 25
122
+ Metrics/BlockLength:
123
+ Max: 345
124
+ Exclude:
125
+ - "**/*_spec.rb"
126
+
127
+ Style/MixinGrouping:
128
+ Enabled: false
129
+
130
+ Style/FileName:
131
+ Enabled: false
132
+
133
+ Layout/IndentHeredoc:
134
+ Enabled: false
135
+
136
+ Style/SpecialGlobalVars:
137
+ Enabled: false
138
+
139
+ PercentLiteralDelimiters:
140
+ PreferredDelimiters:
141
+ "%": ()
142
+ "%i": ()
143
+ "%q": ()
144
+ "%Q": ()
145
+ "%r": "{}"
146
+ "%s": ()
147
+ "%w": ()
148
+ "%W": ()
149
+ "%x": ()
150
+
151
+ Security/YAMLLoad:
152
+ Enabled: false
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.3.1
8
+
9
+ script:
10
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-pmd.gemspec
4
+ gemspec
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-pmd (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+ oga (~> 2.10)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ansi (1.5.0)
14
+ ast (2.4.0)
15
+ claide (1.0.3)
16
+ claide-plugins (0.9.2)
17
+ cork
18
+ nap
19
+ open4 (~> 1.3)
20
+ coderay (1.1.2)
21
+ colored2 (3.1.2)
22
+ cork (0.3.0)
23
+ colored2 (~> 3.1)
24
+ danger (6.1.0)
25
+ claide (~> 1.0)
26
+ claide-plugins (>= 0.9.2)
27
+ colored2 (~> 3.1)
28
+ cork (~> 0.1)
29
+ faraday (~> 0.9)
30
+ faraday-http-cache (~> 2.0)
31
+ git (~> 1.5)
32
+ kramdown (~> 2.0)
33
+ kramdown-parser-gfm (~> 1.0)
34
+ no_proxy_fix
35
+ octokit (~> 4.7)
36
+ terminal-table (~> 1)
37
+ danger-plugin-api (1.0.0)
38
+ danger (> 2.0)
39
+ diff-lcs (1.3)
40
+ faraday (0.16.2)
41
+ multipart-post (>= 1.2, < 3)
42
+ faraday-http-cache (2.0.0)
43
+ faraday (~> 0.8)
44
+ ffi (1.11.1)
45
+ formatador (0.2.5)
46
+ git (1.5.0)
47
+ guard (2.15.1)
48
+ formatador (>= 0.2.4)
49
+ listen (>= 2.7, < 4.0)
50
+ lumberjack (>= 1.0.12, < 2.0)
51
+ nenv (~> 0.1)
52
+ notiffany (~> 0.0)
53
+ pry (>= 0.9.12)
54
+ shellany (~> 0.0)
55
+ thor (>= 0.18.1)
56
+ guard-compat (1.2.1)
57
+ guard-rspec (4.7.3)
58
+ guard (~> 2.1)
59
+ guard-compat (~> 1.1)
60
+ rspec (>= 2.99.0, < 4.0)
61
+ jaro_winkler (1.5.3)
62
+ kramdown (2.1.0)
63
+ kramdown-parser-gfm (1.1.0)
64
+ kramdown (~> 2.0)
65
+ listen (3.0.7)
66
+ rb-fsevent (>= 0.9.3)
67
+ rb-inotify (>= 0.9.7)
68
+ lumberjack (1.0.13)
69
+ method_source (0.9.2)
70
+ multipart-post (2.1.1)
71
+ nap (1.1.0)
72
+ nenv (0.3.0)
73
+ no_proxy_fix (0.1.2)
74
+ notiffany (0.1.3)
75
+ nenv (~> 0.1)
76
+ shellany (~> 0.0)
77
+ octokit (4.14.0)
78
+ sawyer (~> 0.8.0, >= 0.5.3)
79
+ oga (2.15)
80
+ ast
81
+ ruby-ll (~> 2.1)
82
+ open4 (1.3.4)
83
+ parallel (1.17.0)
84
+ parser (2.6.5.0)
85
+ ast (~> 2.4.0)
86
+ pry (0.12.2)
87
+ coderay (~> 1.1.0)
88
+ method_source (~> 0.9.0)
89
+ public_suffix (4.0.1)
90
+ rainbow (3.0.0)
91
+ rake (10.5.0)
92
+ rb-fsevent (0.10.3)
93
+ rb-inotify (0.10.0)
94
+ ffi (~> 1.0)
95
+ rspec (3.8.0)
96
+ rspec-core (~> 3.8.0)
97
+ rspec-expectations (~> 3.8.0)
98
+ rspec-mocks (~> 3.8.0)
99
+ rspec-core (3.8.2)
100
+ rspec-support (~> 3.8.0)
101
+ rspec-expectations (3.8.5)
102
+ diff-lcs (>= 1.2.0, < 2.0)
103
+ rspec-support (~> 3.8.0)
104
+ rspec-mocks (3.8.2)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.8.0)
107
+ rspec-support (3.8.3)
108
+ rubocop (0.75.0)
109
+ jaro_winkler (~> 1.5.1)
110
+ parallel (~> 1.10)
111
+ parser (>= 2.6)
112
+ rainbow (>= 2.2.2, < 4.0)
113
+ ruby-progressbar (~> 1.7)
114
+ unicode-display_width (>= 1.4.0, < 1.7)
115
+ ruby-ll (2.1.2)
116
+ ansi
117
+ ast
118
+ ruby-progressbar (1.10.1)
119
+ sawyer (0.8.2)
120
+ addressable (>= 2.3.5)
121
+ faraday (> 0.8, < 2.0)
122
+ shellany (0.0.1)
123
+ terminal-table (1.8.0)
124
+ unicode-display_width (~> 1.1, >= 1.1.1)
125
+ thor (0.20.3)
126
+ unicode-display_width (1.6.0)
127
+ yard (0.9.20)
128
+
129
+ PLATFORMS
130
+ ruby
131
+
132
+ DEPENDENCIES
133
+ bundler (~> 1.3)
134
+ danger-pmd!
135
+ guard (~> 2.14)
136
+ guard-rspec (~> 4.7)
137
+ listen (= 3.0.7)
138
+ pry
139
+ rake (~> 10.0)
140
+ rspec (~> 3.4)
141
+ rubocop (~> 0.75)
142
+ yard (~> 0.9.20)
143
+
144
+ BUNDLED WITH
145
+ 1.17.2
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 Mathieu Rul <mathroule@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # Danger PMD
2
+
3
+ Danger plugin for PMD report XML file. This plugin is inspired from https://github.com/kazy1991/danger-findbugs.
4
+
5
+ ## Installation
6
+
7
+ $ gem install danger-pmd
8
+
9
+ ## Usage
10
+
11
+ Methods and attributes from this plugin are available in
12
+ your `Dangerfile` under the `pmd` namespace.
13
+
14
+ ## Development
15
+
16
+ 1. Clone this repo
17
+ 2. Run `bundle install` to setup dependencies.
18
+ 3. Run `bundle exec rake spec` to run the tests.
19
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
20
+ 5. Make your changes.
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = %w(lib/**/*.rb spec/**/*.rb)
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,50 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pmd/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-pmd'
8
+ spec.version = Pmd::VERSION
9
+ spec.authors = ['Mathieu Rul']
10
+ spec.email = ['mathroule@gmail.com']
11
+ spec.description = 'A Danger plugin for PMD.'
12
+ spec.summary = 'A Danger plugin for PMD (Programming Mistake Detector), see https://pmd.github.io.'
13
+ spec.homepage = 'https://github.com/mathroule/danger-pmd'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
+ spec.add_runtime_dependency 'oga', '~> 2.10'
23
+
24
+ # General ruby development
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+
28
+ # Testing support
29
+ spec.add_development_dependency 'rspec', '~> 3.4'
30
+
31
+ # Linting code and docs
32
+ spec.add_development_dependency 'rubocop', '~> 0.75'
33
+ spec.add_development_dependency 'yard', '~> 0.9.20'
34
+
35
+ # Makes testing easy via `bundle exec guard`
36
+ spec.add_development_dependency 'guard', '~> 2.14'
37
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
38
+
39
+ # If you want to work on older builds of ruby
40
+ spec.add_development_dependency 'listen', '3.0.7'
41
+
42
+ # This gives you the chance to run a REPL inside your tests
43
+ # via:
44
+ #
45
+ # require 'pry'
46
+ # binding.pry
47
+ #
48
+ # This will stop test execution and let you inspect the results
49
+ spec.add_development_dependency 'pry'
50
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pmd/plugin"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pmd/gem_version"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pmd
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Danger
4
+ # Checks on your Gradle project's Java source files.
5
+ # This is done using [PMD](https://pmd.github.io)
6
+ # Results are passed out as tables in markdown.
7
+ #
8
+ # @example Running PMD with its basic configuration
9
+ #
10
+ # pmd.report
11
+ #
12
+ # @example Running PMD with a specific Gradle task or report_file
13
+ #
14
+ # pmd.gradle_task = 'app:pmd' #defalut: pmd
15
+ # pmd.report_file = "app/build/reports/pmd/pmd.xml"
16
+ # pmd.report
17
+ #
18
+ # @see mathroule/danger-pmd
19
+ # @tags java, android, pmd
20
+
21
+ class DangerPmd < Plugin
22
+ require_relative "./pmd_file"
23
+
24
+ # Custom Gradle module to run.
25
+ # This is useful when your project has different flavors.
26
+ # Defaults to "app".
27
+ # @return [String]
28
+ attr_writer :gradle_module
29
+
30
+ # Custom Gradle task to run.
31
+ # This is useful when your project has different flavors.
32
+ # Defaults to "pmd".
33
+ # @return [String]
34
+ attr_writer :gradle_task
35
+
36
+ # Location of report file
37
+ # If your pmd task outputs to a different location, you can specify it here.
38
+ # Defaults to "build/reports/pmd/pmd.xml".
39
+ # @return [String]
40
+ attr_writer :report_file
41
+
42
+ GRADLEW_NOT_FOUND = "Could not find `gradlew` inside current directory"
43
+ REPORT_FILE_NOT_FOUND = "PMD report not found"
44
+
45
+ # Calls pmd task of your gradle project.
46
+ # It fails if `gradlew` cannot be found inside current directory.
47
+ # It fails if `report_file` cannot be found inside current directory.
48
+ # @return [void]
49
+ def report(inline_mode = true)
50
+ return fail(GRADLEW_NOT_FOUND) unless gradlew_exists?
51
+
52
+ exec_gradle_task
53
+ return fail(REPORT_FILE_NOT_FOUND) unless report_file_exist?
54
+
55
+ if inline_mode
56
+ send_inline_comment
57
+ end
58
+ end
59
+
60
+ # A getter for `gradle_module`, returning "app" if value is nil.
61
+ # @return [String]
62
+ def gradle_module
63
+ @gradle_module ||= "app"
64
+ end
65
+
66
+ # A getter for `gradle_task`, returning "pmd" if value is nil.
67
+ # @return [String]
68
+ def gradle_task
69
+ @gradle_task ||= "pmd"
70
+ end
71
+
72
+ # A getter for `report_file`, returning "app/build/reports/pmd/pmd.xml" if value is nil.
73
+ # @return [String]
74
+ def report_file
75
+ @report_file ||= "app/build/reports/pmd/pmd.xml"
76
+ end
77
+
78
+ # A getter for current updated files
79
+ # @return [Array[String]]
80
+ def target_files
81
+ @target_files ||= (git.modified_files - git.deleted_files) + git.added_files
82
+ end
83
+
84
+ # Run gradle task
85
+ # @return [void]
86
+ def exec_gradle_task
87
+ system "./gradlew #{gradle_task}"
88
+ end
89
+
90
+ # Check gradlew file exists in current directory
91
+ # @return [Bool]
92
+ def gradlew_exists?
93
+ !`ls gradlew`.strip.empty?
94
+ end
95
+
96
+ # Check report_file exists in current directory
97
+ # @return [Bool]
98
+ def report_file_exist?
99
+ File.exist?(report_file)
100
+ end
101
+
102
+ # A getter for `gradle_task`, returning "pmd" if value is nil.
103
+ # @return [Oga::XML::Document]
104
+ def pmd_report
105
+ require "oga"
106
+ @pmd_report ||= Oga.parse_xml(File.open(report_file))
107
+ end
108
+
109
+ # A getter for PMD files.
110
+ # @return [Array[PmdFile]]
111
+ def pmd_files
112
+ @pmd_files ||= pmd_report.xpath("//file").map do |pmd_file|
113
+ PmdFile.new(gradle_module, pmd_file)
114
+ end
115
+ end
116
+
117
+ # Send inline comment with Danger's warn or fail method
118
+ #
119
+ # @return [void]
120
+ def send_inline_comment
121
+ pmd_files.each do |pmd_file|
122
+ next unless target_files.include? pmd_file.absolute_path
123
+
124
+ pmd_file.violations.each do |pmd_violation|
125
+ send(pmd_violation.type, pmd_violation.description, file: pmd_file.absolute_path, line: pmd_violation.line)
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PmdFile
4
+ require_relative "./pmd_violation"
5
+ attr_accessor :module_name
6
+ attr_accessor :file
7
+
8
+ def initialize(module_name, file)
9
+ @module_name = module_name
10
+ @file = file
11
+ end
12
+
13
+ def source_path
14
+ @source_path ||= file.attribute("name").value.to_s
15
+ end
16
+
17
+ def absolute_path
18
+ @absolute_path ||= Pathname.new(source_path[source_path.index(module_name), source_path.length]).to_s
19
+ end
20
+
21
+ def violations
22
+ @violations ||= file.xpath("violation").map do |pmd_violation|
23
+ PmdViolation.new(module_name, pmd_violation)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PmdViolation
4
+ PRIORITY_ERROR_THRESHOLD = 2
5
+ attr_accessor :module_name
6
+ attr_accessor :violation
7
+
8
+ def initialize(module_name, violation)
9
+ @module_name = module_name
10
+ @violation = violation
11
+ end
12
+
13
+ def priority
14
+ @priority ||= violation.attribute("priority").value.to_i
15
+ end
16
+
17
+ def type
18
+ @type ||= priority < PRIORITY_ERROR_THRESHOLD ? :warn : :fail
19
+ end
20
+
21
+ def line
22
+ @line ||= violation.attribute("beginline").value.to_i
23
+ end
24
+
25
+ def description
26
+ @description ||= violation.text.gsub("\n", "")
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd"
5
+ version="6.8.0" timestamp="2019-10-03T20:34:18.074">
6
+ <file name="/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java">
7
+ <violation beginline="5" endline="10" begincolumn="8" endcolumn="1" rule="ClassNamingConventions" ruleset="Code Style" package="com.android.sample" class="Tools" externalInfoUrl="https://pmd.github.io/pmd-6.8.0/pmd_rules_java_codestyle.html#classnamingconventions" priority="1">
8
+ The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'
9
+ </violation>
10
+ </file>
11
+ <file name="/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java">
12
+ <violation beginline="39" endline="39" begincolumn="25" endcolumn="35" rule="UseEqualsToCompareStrings" ruleset="Error Prone" package="com.android.sample" class="MainActivity" method="onCreate" externalInfoUrl="https://pmd.github.io/pmd-6.8.0/pmd_rules_java_errorprone.html#useequalstocomparestrings" priority="3">
13
+ Use equals() to compare strings instead of '==' or '!='
14
+ </violation>
15
+ </file>
16
+ <file name="/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java">
17
+ <violation beginline="15" endline="17" begincolumn="12" endcolumn="5" rule="MethodNamingConventions" ruleset="Code Style" package="com.android.sample" class="ExampleUnitTest" method="addition_isCorrect" externalInfoUrl="https://pmd.github.io/pmd-6.8.0/pmd_rules_java_codestyle.html#methodnamingconventions" priority="1">
18
+ The JUnit 4 test method name 'addition_isCorrect' doesn't match '[a-z][a-zA-Z0-9]*'
19
+ </violation>
20
+ </file>
21
+ <file name="/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java">
22
+ <violation beginline="12" endline="14" begincolumn="12" endcolumn="5" rule="MethodNamingConventions" ruleset="Code Style" package="com.mathroule.demoapp" class="HelperTest" method="getLabel_1" externalInfoUrl="https://pmd.github.io/pmd-6.8.0/pmd_rules_java_codestyle.html#methodnamingconventions" priority="1">
23
+ The JUnit 4 test method name 'getLabel_1' doesn't match '[a-z][a-zA-Z0-9]*'
24
+ </violation>
25
+ <violation beginline="18" endline="20" begincolumn="12" endcolumn="5" rule="MethodNamingConventions" ruleset="Code Style" package="com.mathroule.demoapp" class="HelperTest" method="getLabel_2" externalInfoUrl="https://pmd.github.io/pmd-6.8.0/pmd_rules_java_codestyle.html#methodnamingconventions" priority="1">
26
+ The JUnit 4 test method name 'getLabel_2' doesn't match '[a-z][a-zA-Z0-9]*'
27
+ </violation>
28
+ </file>
29
+ </pmd>
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("spec_helper", __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerPmd do
7
+ it "should be a plugin" do
8
+ expect(Danger::DangerPmd.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ describe "with Dangerfile" do
12
+ before do
13
+ @dangerfile = testing_dangerfile
14
+ @my_plugin = @dangerfile.pmd
15
+ end
16
+
17
+ it "Check default report file path" do
18
+ expect(@my_plugin.report_file).to eq("app/build/reports/pmd/pmd.xml")
19
+ end
20
+
21
+ it "Set custom report file path" do
22
+ custom_report_path = "custom/pmd_report.xml"
23
+ @my_plugin.report_file = custom_report_path
24
+ expect(@my_plugin.report_file).to eq(custom_report_path)
25
+ end
26
+
27
+ it "Check default Gradle module" do
28
+ expect(@my_plugin.gradle_module).to eq("app")
29
+ end
30
+
31
+ it "Set custom Gradle module" do
32
+ my_module = "custom_module"
33
+ @my_plugin.gradle_module = my_module
34
+ expect(@my_plugin.gradle_module).to eq(my_module)
35
+ end
36
+
37
+ it "Check default Gradle task" do
38
+ expect(@my_plugin.gradle_task).to eq("pmd")
39
+ end
40
+
41
+ it "Set custom Gradle task" do
42
+ custom_task = "pmdStagingDebug"
43
+ @my_plugin.gradle_task = custom_task
44
+ expect(@my_plugin.gradle_task).to eq(custom_task)
45
+ end
46
+
47
+ it "Create files" do
48
+ custom_report_path = "spec/fixtures/pmd_report.xml"
49
+ @my_plugin.report_file = custom_report_path
50
+ pmd_files = @my_plugin.pmd_files
51
+ expect(pmd_files).not_to be_nil
52
+
53
+ pmd_file1 = pmd_files[0]
54
+ expect(pmd_file1).not_to be_nil
55
+ expect(pmd_file1.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
56
+ expect(pmd_file1.absolute_path).to eq("app/src/main/java/com/android/sample/Tools.java")
57
+ expect(pmd_file1.violations).not_to be_nil
58
+ expect(pmd_file1.violations.length).to eq(1)
59
+ expect(pmd_file1.violations.first).not_to be_nil
60
+ expect(pmd_file1.violations.first.line).to eq(5)
61
+ expect(pmd_file1.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
62
+
63
+ pmd_file2 = pmd_files[1]
64
+ expect(pmd_file2).not_to be_nil
65
+ expect(pmd_file2.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
66
+ expect(pmd_file2.absolute_path).to eq("app/src/main/java/com/android/sample/MainActivity.java")
67
+ expect(pmd_file2.violations).not_to be_nil
68
+ expect(pmd_file2.violations.length).to eq(1)
69
+ expect(pmd_file2.violations.first).not_to be_nil
70
+ expect(pmd_file2.violations.first.line).to eq(39)
71
+ expect(pmd_file2.violations.first.description).to eq("Use equals() to compare strings instead of '==' or '!='")
72
+
73
+ pmd_file3 = pmd_files[2]
74
+ expect(pmd_file3).not_to be_nil
75
+ expect(pmd_file3.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
76
+ expect(pmd_file3.absolute_path).to eq("app/src/test/java/com/android/sample/ExampleUnitTest.java")
77
+ expect(pmd_file3.violations).not_to be_nil
78
+ expect(pmd_file3.violations.length).to eq(1)
79
+ expect(pmd_file3.violations.first).not_to be_nil
80
+ expect(pmd_file3.violations.first.line).to eq(15)
81
+ expect(pmd_file3.violations.first.description).to eq("The JUnit 4 test method name 'addition_isCorrect' doesn't match '[a-z][a-zA-Z0-9]*'")
82
+
83
+ pmd_file4 = pmd_files[3]
84
+ expect(pmd_file4).not_to be_nil
85
+ expect(pmd_file4.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
86
+ expect(pmd_file4.absolute_path).to eq("app/src/test/java/com/android/sample/ToolsTest.java")
87
+ expect(pmd_file4.violations).not_to be_nil
88
+ expect(pmd_file4.violations.length).to eq(2)
89
+ expect(pmd_file4.violations[0]).not_to be_nil
90
+ expect(pmd_file4.violations[0].line).to eq(12)
91
+ expect(pmd_file4.violations[0].description).to eq("The JUnit 4 test method name 'getLabel_1' doesn't match '[a-z][a-zA-Z0-9]*'")
92
+ expect(pmd_file4.violations[1]).not_to be_nil
93
+ expect(pmd_file4.violations[1].line).to eq(18)
94
+ expect(pmd_file4.violations[1].description).to eq("The JUnit 4 test method name 'getLabel_2' doesn't match '[a-z][a-zA-Z0-9]*'")
95
+ end
96
+
97
+ it "Send inline comments" do
98
+ allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return([])
99
+ custom_report_path = "spec/fixtures/pmd_report.xml"
100
+ @my_plugin.report_file = custom_report_path
101
+ expect(@my_plugin.send_inline_comment).not_to be_nil
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ ROOT = Pathname.new(File.expand_path("..", __dir__))
5
+ $:.unshift((ROOT + "lib").to_s)
6
+ $:.unshift((ROOT + "spec").to_s)
7
+
8
+ require "bundler/setup"
9
+ require "pry"
10
+
11
+ require "rspec"
12
+ require "danger"
13
+
14
+ if `git remote -v` == ""
15
+ puts "You cannot run tests without setting a local git remote on this repo"
16
+ puts "It's a weird side-effect of Danger's internals."
17
+ exit(0)
18
+ end
19
+
20
+ # Use coloured output, it's the best.
21
+ RSpec.configure do |config|
22
+ config.filter_gems_from_backtrace "bundler"
23
+ config.color = true
24
+ config.tty = true
25
+ end
26
+
27
+ require "danger_plugin"
28
+
29
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
30
+ # If you are expanding these files, see if it's already been done ^.
31
+
32
+ # A silent version of the user interface,
33
+ # it comes with an extra function `.string` which will
34
+ # strip all ANSI colours from the string.
35
+
36
+ # rubocop:disable Lint/NestedMethodDefinition
37
+ def testing_ui
38
+ @output = StringIO.new
39
+ def @output.winsize
40
+ [20, 9999]
41
+ end
42
+
43
+ cork = Cork::Board.new(out: @output)
44
+ def cork.string
45
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
46
+ end
47
+ cork
48
+ end
49
+ # rubocop:enable Lint/NestedMethodDefinition
50
+
51
+ # Example environment (ENV) that would come from
52
+ # running a PR on TravisCI
53
+ def testing_env
54
+ {
55
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
56
+ "TRAVIS_PULL_REQUEST" => "800",
57
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
58
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
59
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
60
+ }
61
+ end
62
+
63
+ # A stubbed out Dangerfile for use in tests
64
+ def testing_dangerfile
65
+ env = Danger::EnvironmentManager.new(testing_env)
66
+ Danger::Dangerfile.new(env, testing_ui)
67
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-pmd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mathieu Rul
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oga
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.75'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.75'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.20
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.20
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.14'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.14'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: listen
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.0.7
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.7
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: A Danger plugin for PMD.
168
+ email:
169
+ - mathroule@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rubocop.yml"
176
+ - ".travis.yml"
177
+ - Gemfile
178
+ - Gemfile.lock
179
+ - Guardfile
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - danger-pmd.gemspec
184
+ - lib/danger_plugin.rb
185
+ - lib/danger_pmd.rb
186
+ - lib/pmd/gem_version.rb
187
+ - lib/pmd/plugin.rb
188
+ - lib/pmd/pmd_file.rb
189
+ - lib/pmd/pmd_violation.rb
190
+ - spec/fixtures/pmd_report.xml
191
+ - spec/pmd_spec.rb
192
+ - spec/spec_helper.rb
193
+ homepage: https://github.com/mathroule/danger-pmd
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubygems_version: 3.0.3
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: A Danger plugin for PMD (Programming Mistake Detector), see https://pmd.github.io.
216
+ test_files:
217
+ - spec/fixtures/pmd_report.xml
218
+ - spec/pmd_spec.rb
219
+ - spec/spec_helper.rb