ktlint_reporter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a48683e136a28e8ed8a14f64c2c1229da598aee9e8d8cee5fc51351ad887a554
4
+ data.tar.gz: aa1f18c35a9523da5ce31d4a98dc9bcbb23771f7ac555c4e262f38620c102860
5
+ SHA512:
6
+ metadata.gz: 7b40d56401f45dbfefc378258ca205790e3d47d55662c40aee683fe240773045b02e6a129bbffbc9ce09ac55d12c415b69fb85df8e8d4d5f65e9a3a960521116
7
+ data.tar.gz: b96c02cf7311ba506f696f05a664e5d62902f04b327929e5411cb186016cf6d445b2609cd0a15717d5176a695653bb3fe1da4677107d1a13f4efcacda08f15a2
data/.bundle/config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: "vendor/bundle"
3
+ BUNDLE_CLEAN: "true"
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
5
+ **/vendor/bundle/
6
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,170 @@
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
+ Exclude:
7
+ - 'vendor/**/*'
8
+ - 'spec/fixtures/**/*'
9
+ - 'tmp/**/*'
10
+ TargetRubyVersion: 2.3.7
11
+
12
+ Metrics/ModuleLength:
13
+ Exclude:
14
+ - 'spec/**/*'
15
+ Enabled: true
16
+
17
+ Style/StringLiterals:
18
+ EnforcedStyle: double_quotes
19
+ Enabled: true
20
+
21
+ # kind_of? is a good way to check a type
22
+ Style/ClassCheck:
23
+ EnforcedStyle: kind_of?
24
+
25
+ # It's better to be more explicit about the type
26
+ Style/BracesAroundHashParameters:
27
+ Enabled: false
28
+
29
+ # specs sometimes have useless assignments, which is fine
30
+ Lint/UselessAssignment:
31
+ Exclude:
32
+ - '**/spec/**/*'
33
+
34
+ # We could potentially enable the 2 below:
35
+ Layout/IndentHash:
36
+ Enabled: false
37
+
38
+ Layout/AlignHash:
39
+ Enabled: false
40
+
41
+ # HoundCI doesn't like this rule
42
+ Layout/DotPosition:
43
+ Enabled: false
44
+
45
+ # We allow !! as it's an easy way to convert ot boolean
46
+ Style/DoubleNegation:
47
+ Enabled: false
48
+
49
+ # Cop supports --auto-correct.
50
+ Lint/UnusedBlockArgument:
51
+ Enabled: false
52
+
53
+ # We want to allow class Fastlane::Class
54
+ Style/ClassAndModuleChildren:
55
+ Enabled: false
56
+
57
+ Metrics/AbcSize:
58
+ Max: 60
59
+
60
+ # The %w might be confusing for new users
61
+ Style/WordArray:
62
+ MinSize: 19
63
+
64
+ # raise and fail are both okay
65
+ Style/SignalException:
66
+ Enabled: false
67
+
68
+ # Better too much 'return' than one missing
69
+ Style/RedundantReturn:
70
+ Enabled: false
71
+
72
+ # Having if in the same line might not always be good
73
+ Style/IfUnlessModifier:
74
+ Enabled: false
75
+
76
+ # and and or is okay
77
+ Style/AndOr:
78
+ Enabled: false
79
+
80
+ # Configuration parameters: CountComments.
81
+ Metrics/ClassLength:
82
+ Max: 350
83
+
84
+ Metrics/CyclomaticComplexity:
85
+ Max: 17
86
+
87
+ # Configuration parameters: AllowURI, URISchemes.
88
+ Metrics/LineLength:
89
+ Max: 370
90
+
91
+ # Configuration parameters: CountKeywordArgs.
92
+ Metrics/ParameterLists:
93
+ Max: 10
94
+
95
+ Metrics/PerceivedComplexity:
96
+ Max: 18
97
+
98
+ # Sometimes it's easier to read without guards
99
+ Style/GuardClause:
100
+ Enabled: false
101
+
102
+ # something = if something_else
103
+ # that's confusing
104
+ Style/ConditionalAssignment:
105
+ Enabled: false
106
+
107
+ # Better to have too much self than missing a self
108
+ Style/RedundantSelf:
109
+ Enabled: false
110
+
111
+ Metrics/MethodLength:
112
+ Max: 60
113
+
114
+ # We're not there yet
115
+ Style/Documentation:
116
+ Enabled: false
117
+
118
+ # Adds complexity
119
+ Style/IfInsideElse:
120
+ Enabled: false
121
+
122
+ # danger specific
123
+
124
+ Style/BlockComments:
125
+ Enabled: false
126
+
127
+ Layout/MultilineMethodCallIndentation:
128
+ EnforcedStyle: indented
129
+
130
+ # FIXME: 25
131
+ Metrics/BlockLength:
132
+ Max: 345
133
+ Exclude:
134
+ - "**/*_spec.rb"
135
+
136
+ Style/MixinGrouping:
137
+ Enabled: false
138
+
139
+ Style/FileName:
140
+ Enabled: false
141
+
142
+ Layout/IndentHeredoc:
143
+ Enabled: false
144
+
145
+ Style/SpecialGlobalVars:
146
+ Enabled: false
147
+
148
+ PercentLiteralDelimiters:
149
+ PreferredDelimiters:
150
+ "%": ()
151
+ "%i": ()
152
+ "%q": ()
153
+ "%Q": ()
154
+ "%r": "{}"
155
+ "%s": ()
156
+ "%w": ()
157
+ "%W": ()
158
+ "%x": ()
159
+
160
+ Security/YAMLLoad:
161
+ Enabled: false
162
+
163
+ Style/TrailingCommaInArguments:
164
+ Enabled: true
165
+
166
+ Style/TrailingCommaInArrayLiteral:
167
+ Enabled: false
168
+
169
+ Style/TrailingCommaInHashLiteral:
170
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.7
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - vendor/bundle
5
+
6
+ rvm:
7
+ - 2.3.7
8
+ - 2.4.4
9
+ - 2.5.1
10
+
11
+ script:
12
+ - bundle exec rake spec
data/Dangerfile.sample ADDED
@@ -0,0 +1,3 @@
1
+ checkstyle_reports.inline_comment = true
2
+ checkstyle_reports.report('checkstyle-results.xml', modified_files_only: true)
3
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in danger-apkstats.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,136 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-checkstyle_reports (0.1.0)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ ast (2.4.0)
13
+ claide (1.0.2)
14
+ claide-plugins (0.9.2)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.2)
19
+ colored2 (3.1.2)
20
+ cork (0.3.0)
21
+ colored2 (~> 3.1)
22
+ danger (5.6.7)
23
+ claide (~> 1.0)
24
+ claide-plugins (>= 0.9.2)
25
+ colored2 (~> 3.1)
26
+ cork (~> 0.1)
27
+ faraday (~> 0.9)
28
+ faraday-http-cache (~> 1.0)
29
+ git (~> 1.5)
30
+ kramdown (~> 1.5)
31
+ no_proxy_fix
32
+ octokit (~> 4.7)
33
+ terminal-table (~> 1)
34
+ danger-plugin-api (1.0.0)
35
+ danger (> 2.0)
36
+ diff-lcs (1.3)
37
+ faraday (0.15.3)
38
+ multipart-post (>= 1.2, < 3)
39
+ faraday-http-cache (1.3.1)
40
+ faraday (~> 0.8)
41
+ ffi (1.9.25)
42
+ formatador (0.2.5)
43
+ git (1.5.0)
44
+ guard (2.14.2)
45
+ formatador (>= 0.2.4)
46
+ listen (>= 2.7, < 4.0)
47
+ lumberjack (>= 1.0.12, < 2.0)
48
+ nenv (~> 0.1)
49
+ notiffany (~> 0.0)
50
+ pry (>= 0.9.12)
51
+ shellany (~> 0.0)
52
+ thor (>= 0.18.1)
53
+ guard-compat (1.2.1)
54
+ guard-rspec (4.7.3)
55
+ guard (~> 2.1)
56
+ guard-compat (~> 1.1)
57
+ rspec (>= 2.99.0, < 4.0)
58
+ jaro_winkler (1.5.1)
59
+ kramdown (1.17.0)
60
+ listen (3.0.7)
61
+ rb-fsevent (>= 0.9.3)
62
+ rb-inotify (>= 0.9.7)
63
+ lumberjack (1.0.13)
64
+ method_source (0.9.0)
65
+ multipart-post (2.0.0)
66
+ nap (1.1.0)
67
+ nenv (0.3.0)
68
+ no_proxy_fix (0.1.2)
69
+ notiffany (0.1.1)
70
+ nenv (~> 0.1)
71
+ shellany (~> 0.0)
72
+ octokit (4.12.0)
73
+ sawyer (~> 0.8.0, >= 0.5.3)
74
+ open4 (1.3.4)
75
+ parallel (1.12.1)
76
+ parser (2.5.1.2)
77
+ ast (~> 2.4.0)
78
+ powerpack (0.1.2)
79
+ pry (0.11.3)
80
+ coderay (~> 1.1.0)
81
+ method_source (~> 0.9.0)
82
+ public_suffix (3.0.3)
83
+ rainbow (3.0.0)
84
+ rake (10.5.0)
85
+ rb-fsevent (0.10.3)
86
+ rb-inotify (0.9.10)
87
+ ffi (>= 0.5.0, < 2)
88
+ rspec (3.7.0)
89
+ rspec-core (~> 3.7.0)
90
+ rspec-expectations (~> 3.7.0)
91
+ rspec-mocks (~> 3.7.0)
92
+ rspec-core (3.7.1)
93
+ rspec-support (~> 3.7.0)
94
+ rspec-expectations (3.7.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.7.0)
97
+ rspec-mocks (3.7.0)
98
+ diff-lcs (>= 1.2.0, < 2.0)
99
+ rspec-support (~> 3.7.0)
100
+ rspec-support (3.7.1)
101
+ rubocop (0.58.2)
102
+ jaro_winkler (~> 1.5.1)
103
+ parallel (~> 1.10)
104
+ parser (>= 2.5, != 2.5.1.1)
105
+ powerpack (~> 0.1)
106
+ rainbow (>= 2.2.2, < 4.0)
107
+ ruby-progressbar (~> 1.7)
108
+ unicode-display_width (~> 1.0, >= 1.0.1)
109
+ ruby-progressbar (1.9.0)
110
+ sawyer (0.8.1)
111
+ addressable (>= 2.3.5, < 2.6)
112
+ faraday (~> 0.8, < 1.0)
113
+ shellany (0.0.1)
114
+ terminal-table (1.8.0)
115
+ unicode-display_width (~> 1.1, >= 1.1.1)
116
+ thor (0.20.0)
117
+ unicode-display_width (1.4.0)
118
+ yard (0.9.15)
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ bundler (~> 1.3)
125
+ danger-checkstyle_reports!
126
+ guard (~> 2.14)
127
+ guard-rspec (~> 4.7)
128
+ listen (= 3.0.7)
129
+ pry
130
+ rake (~> 10.0)
131
+ rspec (~> 3.4)
132
+ rubocop
133
+ yard
134
+
135
+ BUNDLED WITH
136
+ 1.16.3
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A guardfile for making Danger Plugins
4
+ # For more info see https://github.com/guard/guard#readme
5
+
6
+ # To run, use `bundle exec guard`.
7
+
8
+ guard :rspec, cmd: "bundle exec rspec" do
9
+ require "guard/rspec/dsl"
10
+ dsl = Guard::RSpec::Dsl.new(self)
11
+
12
+ # RSpec files
13
+ rspec = dsl.rspec
14
+ watch(rspec.spec_helper) { rspec.spec_dir }
15
+ watch(rspec.spec_support) { rspec.spec_dir }
16
+ watch(rspec.spec_files)
17
+
18
+ # Ruby files
19
+ ruby = dsl.ruby
20
+ dsl.watch_spec_files_for(ruby.lib_files)
21
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 Jumpei Matsuda <jmatsu.drm@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.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ [![Build Status](https://travis-ci.com/jmatsu/danger-checkstyle_reports.svg?branch=master)](https://travis-ci.com/jmatsu/danger-checkstyle_reports) [![Gem Version](https://badge.fury.io/rb/danger-checkstyle_reports.svg)](https://badge.fury.io/rb/danger-checkstyle_reports)
2
+
3
+ # danger-checkstyle_reports
4
+
5
+ This is a plugin of [Danger](https://github.com/danger/danger) for Android projects.
6
+ This reports checkstyle results.
7
+
8
+ ## Installation
9
+
10
+ `gem install danger-checkstyle_reports`
11
+
12
+ ## Usage
13
+
14
+ `checkstyle_reports` namespace is available under Dangerfile.
15
+
16
+ ### Report errors
17
+
18
+ ```
19
+ # If you'd like inlining comments
20
+ checkstyle_reports.inline_comment = true
21
+ checkstyle_reports.report(/path/to/xml)
22
+ ```
23
+
24
+ ## Development
25
+
26
+ 1. Clone this repo
27
+ 2. Run `bundle install` to setup dependencies.
28
+ 3. Run `bundle exec rake spec` to run the tests.
29
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
30
+ 5. Make your changes.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:specs)
8
+
9
+ task default: :specs
10
+
11
+ task :spec do
12
+ Rake::Task["specs"].invoke
13
+ Rake::Task["rubocop"].invoke
14
+ Rake::Task["spec_docs"].invoke
15
+ end
16
+
17
+ desc "Run RuboCop on the lib/specs directory"
18
+ RuboCop::RakeTask.new(:rubocop) do |task|
19
+ task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
20
+ end
21
+
22
+ desc "Ensure that the plugin passes `danger plugins lint`"
23
+ task :spec_docs do
24
+ sh "bundle exec danger plugins lint"
25
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "checkstyle_reports/gem_version.rb"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "ktlint_reporter"
9
+ spec.version = CheckstyleReports::VERSION
10
+ spec.authors = ["Tedo Manvelidze"]
11
+ spec.email = ["tedex.manvelidze@gmail.com"]
12
+ spec.description = "To report checkstyle results via danger."
13
+ spec.summary = "This is a danger plugin to report checkstyle results with line filtering."
14
+ spec.homepage = "https://github.com/ted3x/danger-checkstyle_reports"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files | grep -v 'fixture/'`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
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"
33
+ spec.add_development_dependency "yard"
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,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckstyleReports::Entity
4
+ class FoundError
5
+ # A detected line number
6
+ #
7
+ # @return [Fixnum]
8
+ attr_reader :line_number
9
+
10
+ # A detected column
11
+ # Optionality depends on 'source'
12
+ #
13
+ # @return [Fixnum, nil]
14
+ attr_reader :column_number
15
+
16
+ # A severity of this error
17
+ #
18
+ # @return [String]
19
+ attr_reader :severity
20
+
21
+ # An error message
22
+ #
23
+ # @return [String]
24
+ attr_reader :html_unescaped_message
25
+
26
+ # A name of a detector
27
+ #
28
+ # @return [String]
29
+ attr_reader :source # String
30
+
31
+ def initialize(node)
32
+ raise "Wrong node was passed. expected error but #{node.name}" if node.name != "error"
33
+
34
+ attributes = node.attributes
35
+
36
+ @line_number = attributes["line"].to_i
37
+ @column_number = attributes["column"]&.to_i
38
+ @severity = attributes["severity"]
39
+ @html_unescaped_message = attributes["message"] # unescape implicitly
40
+ @source = attributes["source"]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckstyleReports::Entity
4
+ class FoundFile
5
+ # A absolute path to this file
6
+ #
7
+ # @return [String]
8
+ attr_reader :path
9
+
10
+ # A relative path to this file
11
+ #
12
+ # @return [String]
13
+ attr_reader :relative_path
14
+
15
+ # Errors which were detected in this file
16
+ #
17
+ # @return [Array<FoundError>]
18
+ attr_reader :errors
19
+
20
+ def initialize(node, prefix:)
21
+ raise "Wrong node was passed. expected file but #{node.name}" if node.name != "file"
22
+
23
+ if prefix.end_with?(file_separator)
24
+ @prefix = prefix
25
+ else
26
+ @prefix = prefix + file_separator
27
+ end
28
+
29
+ name = node.attributes["name"]
30
+
31
+ if Pathname.new(name).absolute?
32
+ raise "Bad prefix was found for #{name}. #{@prefix} was a prefix." unless name.start_with?(@prefix)
33
+
34
+ # Use delete_prefix when min support version becomes ruby 2.5
35
+ @relative_path = name[@prefix.length, name.length - @prefix.length]
36
+ else
37
+ @relative_path = name
38
+ end
39
+
40
+ @path = @prefix + @relative_path
41
+
42
+ @path = node.attributes["name"]
43
+ @errors = []
44
+
45
+ node.elements.each("error") { |n| @errors << FoundError.new(n) }
46
+ end
47
+
48
+ private
49
+
50
+ def file_separator
51
+ File::ALT_SEPARATOR || File::SEPARATOR
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckstyleReports
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckstyleReports
4
+ class Severity
5
+ VALUES = %i(ignore info warning error).freeze
6
+
7
+ def initialize(base)
8
+ @base = base&.to_sym
9
+ end
10
+
11
+ def <=(other)
12
+ return if @base.nil?
13
+ return true if other.nil?
14
+
15
+ VALUES.index(@base) <= VALUES.index(other.to_sym)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'rexml/document'
5
+
6
+ require_relative 'gem_version'
7
+
8
+ require_relative 'lib/severity'
9
+
10
+ require_relative 'entity/found_error'
11
+ require_relative 'entity/found_file'
12
+
13
+ module Danger
14
+ # Comment checkstyle reports.
15
+ #
16
+ # You need to specify the project root. You don't need do it if it is same with git's top-level path.
17
+ #
18
+ # checkstyle_reports.root_path=/path/to/project
19
+ #
20
+ # @example Report errors whose files have been modified (By default)
21
+ #
22
+ # checkstyle_reports.report("app/build/checkstyle/checkstyle.xml"[, modified_files_only: true])
23
+ #
24
+ # @example Report all errors in app/build/checkstyle/checkstyle.xml
25
+ #
26
+ # checkstyle_reports.report("app/build/checkstyle/checkstyle.xml", modified_files_only: false)
27
+ #
28
+ # @see Jumpei Matsuda/danger-checkstyle_reports
29
+ # @tags android, checkstyle
30
+ #
31
+ class DangerCheckstyleReports < Plugin
32
+ REPORT_METHODS = %i[message warn fail].freeze
33
+
34
+ # *Optional*
35
+ # An absolute path to a root.
36
+ # To comment errors to VCS, this needs to know relative path of files from the root.
37
+ #
38
+ # @return [String] the root path of git repository by default.
39
+ attr_accessor :root_path
40
+
41
+ # *Optional*
42
+ # Create inline comment if true.
43
+ #
44
+ # @return [Boolean] true by default
45
+ attr_accessor :inline_comment
46
+
47
+ # *Optional*
48
+ # minimum severity to be reported (inclusive)
49
+ #
50
+ # @return [String, Symbol] error by default
51
+ attr_accessor :min_severity
52
+
53
+ # *Optional*
54
+ # Set report method
55
+ #
56
+ # @return [String, Symbol] error by default
57
+ attr_accessor :report_method
58
+
59
+ # Enable filtering
60
+ # Only show messages within changed files.
61
+ attr_accessor :filtering
62
+
63
+ # Only show messages for the modified lines.
64
+ attr_accessor :filtering_lines
65
+
66
+ # The array of files which include at least one error
67
+ #
68
+ # @return [Array<String>] a collection of relative paths
69
+ attr_reader :reported_files
70
+
71
+ # Report errors based on the given xml file if needed
72
+ #
73
+ # @param [String] xml_file which contains checkstyle results to be reported
74
+ # @param [Boolean] modified_files_only which is a flag to filter out non-added/non-modified files
75
+ # @return [void] void
76
+ def report(xml_file, modified_files_only: true)
77
+ raise 'File path must not be empty' if xml_file.empty?
78
+ raise 'File not found' unless File.exist?(xml_file)
79
+
80
+ @min_severity = (min_severity || :error).to_sym
81
+ @report_method = (report_method || :fail).to_sym
82
+
83
+ raise 'Unknown severity found' unless CheckstyleReports::Severity::VALUES.include?(min_severity)
84
+ raise 'Unknown report method' unless REPORT_METHODS.include?(report_method)
85
+
86
+ files = parse_xml(xml_file, modified_files_only)
87
+
88
+ @reported_files = files.map(&:relative_path)
89
+
90
+ do_comment(files) unless files.empty?
91
+ end
92
+
93
+ private
94
+
95
+ # Parse the given xml file and apply filters if needed
96
+ #
97
+ # @param [String] file_path which is a check-style xml file
98
+ # @param [Boolean] modified_files_only a flag to determine to apply added/modified files-only filter
99
+ # @return [Array<FoundFile>] filtered files
100
+ def parse_xml(file_path, modified_files_only)
101
+ prefix = root_path || `git rev-parse --show-toplevel`.chomp
102
+
103
+ files = []
104
+
105
+ REXML::Document.new(File.read(file_path)).root.elements.each('file') do |f|
106
+ files << CheckstyleReports::Entity::FoundFile.new(f, prefix: prefix)
107
+ end
108
+
109
+ if modified_files_only
110
+ target_files = git.modified_files + git.added_files
111
+
112
+ files.select! { |f| target_files.include?(f.relative_path) }
113
+ end
114
+
115
+ files.reject!(&:errors_empty?)
116
+ files
117
+ end
118
+
119
+ # Comment errors based on the given xml file to VCS
120
+ #
121
+ # @param [Array<FoundFile>] files which contains checkstyle results to be reported
122
+ # @return [void] void
123
+ def do_comment(files)
124
+ base_severity = CheckstyleReports::Severity.new(min_severity)
125
+ target_files = git.modified_files + git.added_files
126
+ target_lines = {}
127
+
128
+ if filtering_lines
129
+ target_files.each do |file|
130
+ added_lines = parse_added_line_numbers(git.diff[file].patch)
131
+ target_lines[file] = added_lines
132
+ end
133
+ end
134
+
135
+ files.each do |f|
136
+ f.errors.each do |e|
137
+ # check severity
138
+ next unless base_severity <= e.severity
139
+
140
+ if filtering_lines
141
+ next unless target_files.include?(f.relative_path)
142
+ added_lines = target_lines[f.relative_path]
143
+ next unless added_lines.include?(e.line_number)
144
+ end
145
+
146
+ if inline_comment
147
+ public_send(report_method, e.html_unescaped_message, file: f.relative_path, line: e.line_number)
148
+ else
149
+ public_send(report_method, "#{f.relative_path} : #{e.html_unescaped_message} at #{e.line_number}")
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ # Parses git diff of a file and returns an array of added line numbers.
156
+ def parse_added_line_numbers(diff)
157
+ current_line_number = nil
158
+ added_line_numbers = []
159
+ diff_lines = diff.strip.split("\n")
160
+ diff_lines.each_with_index do |line, index|
161
+ if (m = %r{\+(\d+)(?:,\d+)? @@}.match(line))
162
+ # (e.g. @@ -32,10 +32,7 @@)
163
+ current_line_number = Integer(m[1])
164
+ else
165
+ if !current_line_number.nil?
166
+ if line.start_with?('+')
167
+ # added line
168
+ added_line_numbers.push(current_line_number)
169
+ current_line_number += 1
170
+ elsif !line.start_with?('-')
171
+ # unmodified line
172
+ current_line_number += 1
173
+ end
174
+ end
175
+ end
176
+ end
177
+ added_line_numbers
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "checkstyle_reports/gem_version"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "checkstyle_reports/plugin"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("spec_helper", __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerCheckstyleReports do
7
+ it "should be a plugin" do
8
+ expect(Danger::DangerCheckstyleReports.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ #
12
+ # You should test your custom attributes and methods here
13
+ #
14
+ describe "with Dangerfile" do
15
+ before do
16
+ @dangerfile = testing_dangerfile
17
+ @my_plugin = @dangerfile.checkstyle_reports
18
+
19
+ # mock the PR data
20
+ # you can then use this, eg. github.pr_author, later in the spec
21
+ json = File.read(fixture_path + "github_pr.json")
22
+ allow(@my_plugin.github).to receive(:pr_json).and_return(json)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../spec_helper"
4
+
5
+ module CheckstyleReports::Entity
6
+ ERROR_NODE_SAMPLE_1 = <<NODE
7
+ <error
8
+ line="144"
9
+ column="108"
10
+ severity="error"
11
+ message="&apos;+&apos; should be on a new line."
12
+ source="com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck"
13
+ />
14
+ NODE
15
+
16
+ ERROR_NODE_SAMPLE_2 = <<NODE
17
+ <error
18
+ line="296"
19
+ severity="error"
20
+ message="Line has trailing spaces."
21
+ source="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck"
22
+ />
23
+ NODE
24
+
25
+ describe CheckstyleReports::Entity::FoundError do
26
+ let(:error) { FoundError.new(REXML::Document.new(node).root) }
27
+
28
+ context "sample1" do
29
+ let(:node) { ERROR_NODE_SAMPLE_1 }
30
+
31
+ it "should read it successfully" do
32
+ expect(error.line_number).to eq(144)
33
+ expect(error.column_number).to eq(108)
34
+ expect(error.severity).to eq("error")
35
+ expect(error.html_unescaped_message).to eq("'+' should be on a new line.")
36
+ expect(error.source).to eq("com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck")
37
+ end
38
+ end
39
+
40
+ context "sample2" do
41
+ let(:node) { ERROR_NODE_SAMPLE_2 }
42
+
43
+ it "should read it successfully" do
44
+ expect(error.line_number).to eq(296)
45
+ expect(error.column_number).to be_nil
46
+ expect(error.severity).to eq("error")
47
+ expect(error.html_unescaped_message).to eq("Line has trailing spaces.")
48
+ expect(error.source).to eq("com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck")
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../spec_helper"
4
+
5
+ module CheckstyleReports::Entity
6
+ FILE_NODE_SAMPLE_1 = <<NODE
7
+ <file
8
+ name="/Users/jmatsu/Workspace/sample/src/main/java/io/github/jmatsu/Sample.java" >
9
+ #{ERROR_NODE_SAMPLE_1}
10
+ </file>
11
+ NODE
12
+
13
+ FILE_NODE_SAMPLE_2 = <<NODE
14
+ <file
15
+ name="/Users/jmatsu/Workspace/sample/src/test/java/io/github/jmatsu/Sample2.java" >
16
+ #{ERROR_NODE_SAMPLE_1}
17
+ #{ERROR_NODE_SAMPLE_2}
18
+ </file>
19
+ NODE
20
+
21
+ FILE_NODE_SAMPLE_EMPTY = <<NODE
22
+ <file
23
+ name="/Users/jmatsu/Workspace/sample/src/main/java/io/github/jmatsu/Sample.java" />
24
+ NODE
25
+
26
+ describe CheckstyleReports::Entity::FoundFile do
27
+ let(:file) { FoundFile.new(REXML::Document.new(node).root, prefix: "/Users/jmatsu/Workspace/sample") }
28
+
29
+ context "sample1" do
30
+ let(:node) { FILE_NODE_SAMPLE_1 }
31
+
32
+ it "should read it successfully" do
33
+ expect(file.path).to eq("/Users/jmatsu/Workspace/sample/src/main/java/io/github/jmatsu/Sample.java")
34
+ expect(file.errors.size).to eq(1)
35
+ expect(file.relative_path).to eq("src/main/java/io/github/jmatsu/Sample.java")
36
+ end
37
+ end
38
+
39
+ context "sample2" do
40
+ let(:node) { FILE_NODE_SAMPLE_2 }
41
+
42
+ it "should read it successfully" do
43
+ expect(file.path).to eq("/Users/jmatsu/Workspace/sample/src/test/java/io/github/jmatsu/Sample2.java")
44
+ expect(file.errors.size).to eq(2)
45
+ expect(file.relative_path).to eq("src/test/java/io/github/jmatsu/Sample2.java")
46
+ end
47
+ end
48
+
49
+ context "sample empty" do
50
+ let(:node) { FILE_NODE_SAMPLE_EMPTY }
51
+
52
+ it "should read it successfully" do
53
+ expect(file.path).to eq("/Users/jmatsu/Workspace/sample/src/main/java/io/github/jmatsu/Sample.java")
54
+ expect(file.errors.size).to eq(0)
55
+ expect(file.relative_path).to eq("src/main/java/io/github/jmatsu/Sample.java")
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../spec_helper"
4
+
5
+ module CheckstyleReports
6
+ describe CheckstyleReports::Severity do
7
+ let(:data) do
8
+ [
9
+ [:ignore, :ignore, true],
10
+ [:ignore, :info, true],
11
+ [:ignore, :warning, true],
12
+ [:ignore, :error, true],
13
+ [:info, :ignore, false],
14
+ [:info, :info, true],
15
+ [:info, :warning, true],
16
+ [:info, :error, true],
17
+ [:warning, :ignore, false],
18
+ [:warning, :info, false],
19
+ [:warning, :warning, true],
20
+ [:warning, :error, true],
21
+ [:error, :ignore, false],
22
+ [:error, :info, false],
23
+ [:error, :warning, false],
24
+ [:error, :error, true],
25
+ ]
26
+ end
27
+
28
+ context "<=" do
29
+ it do
30
+ data.each do |d|
31
+ base, other, expected = d
32
+
33
+ severity = CheckstyleReports::Severity.new(base)
34
+
35
+ expect(severity <= other).to eq(expected)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,71 @@
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
+ def fixture_path
9
+ "#{(ROOT + 'fixture')}/"
10
+ end
11
+
12
+ require "bundler/setup"
13
+ require "pry"
14
+
15
+ require "rspec"
16
+ require "danger"
17
+
18
+ if `git remote -v` == ""
19
+ puts "You cannot run tests without setting a local git remote on this repo"
20
+ puts "It's a weird side-effect of Danger's internals."
21
+ exit(0)
22
+ end
23
+
24
+ # Use coloured output, it's the best.
25
+ RSpec.configure do |config|
26
+ config.filter_gems_from_backtrace "bundler"
27
+ config.color = true
28
+ config.tty = true
29
+ end
30
+
31
+ require "danger_plugin"
32
+
33
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
34
+ # If you are expanding these files, see if it's already been done ^.
35
+
36
+ # A silent version of the user interface,
37
+ # it comes with an extra function `.string` which will
38
+ # strip all ANSI colours from the string.
39
+
40
+ # rubocop:disable Lint/NestedMethodDefinition
41
+ def testing_ui
42
+ @output = StringIO.new
43
+ def @output.winsize
44
+ [20, 9999]
45
+ end
46
+
47
+ cork = Cork::Board.new(out: @output)
48
+ def cork.string
49
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
50
+ end
51
+ cork
52
+ end
53
+ # rubocop:enable Lint/NestedMethodDefinition
54
+
55
+ # Example environment (ENV) that would come from
56
+ # running a PR on TravisCI
57
+ def testing_env
58
+ {
59
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
60
+ "TRAVIS_PULL_REQUEST" => "800",
61
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
62
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
63
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
64
+ }
65
+ end
66
+
67
+ # A stubbed out Dangerfile for use in tests
68
+ def testing_dangerfile
69
+ env = Danger::EnvironmentManager.new(testing_env)
70
+ Danger::Dangerfile.new(env, testing_ui)
71
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ktlint_reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tedo Manvelidze
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-17 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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: listen
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.7
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.7
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: To report checkstyle results via danger.
154
+ email:
155
+ - tedex.manvelidze@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".bundle/config"
161
+ - ".gitignore"
162
+ - ".rubocop.yml"
163
+ - ".ruby-version"
164
+ - ".travis.yml"
165
+ - Dangerfile.sample
166
+ - Gemfile
167
+ - Gemfile.lock
168
+ - Guardfile
169
+ - LICENSE.txt
170
+ - README.md
171
+ - Rakefile
172
+ - danger-checkstyle_reports.gemspec
173
+ - lib/checkstyle_reports/entity/found_error.rb
174
+ - lib/checkstyle_reports/entity/found_file.rb
175
+ - lib/checkstyle_reports/gem_version.rb
176
+ - lib/checkstyle_reports/lib/severity.rb
177
+ - lib/checkstyle_reports/plugin.rb
178
+ - lib/danger_checkstyle_reports.rb
179
+ - lib/danger_plugin.rb
180
+ - spec/checkstyle_reports_spec.rb
181
+ - spec/entity/found_error_spec.rb
182
+ - spec/entity/found_file_spec.rb
183
+ - spec/lib/severity_spec.rb
184
+ - spec/spec_helper.rb
185
+ homepage: https://github.com/ted3x/danger-checkstyle_reports
186
+ licenses:
187
+ - MIT
188
+ metadata: {}
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubygems_version: 3.4.10
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: This is a danger plugin to report checkstyle results with line filtering.
208
+ test_files:
209
+ - spec/checkstyle_reports_spec.rb
210
+ - spec/entity/found_error_spec.rb
211
+ - spec/entity/found_file_spec.rb
212
+ - spec/lib/severity_spec.rb
213
+ - spec/spec_helper.rb