danger-checkstyle_formatter 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: 2fa439c0c2eacb8943b28f8620970be83bf74702710da4c22f39100af3cb9174
4
+ data.tar.gz: b08d08d063db89ddf5dd2c52f0fda97f14cb9e16e9c5b8f5dd0ee8b59a95f6f2
5
+ SHA512:
6
+ metadata.gz: 75f20cc610cc65ba1e82a085d7fc53b03b2f1a7dc45529b3aea381e832d18046ec211aa24c3633443acd8c5bdf54219cb42e36f3713d04e46cc724205eaff9cb
7
+ data.tar.gz: 6321330dd3d017ea3f604ad3f347b4be18467065d7af96ad054e1edbfb982500b0894e68b7226dfa40e2c65cd145f540d5a4b26dbaba7637345a4ea6f4c01058
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
5
+
6
+ ## Environment normalization:
7
+ /.bundle/
8
+ /vendor/bundle
9
+ /lib/bundler/man/
@@ -0,0 +1,150 @@
1
+ # Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.1
5
+
6
+ Style/StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+ Enabled: true
9
+
10
+ # kind_of? is a good way to check a type
11
+ Style/ClassCheck:
12
+ EnforcedStyle: kind_of?
13
+
14
+ # It's better to be more explicit about the type
15
+ Style/BracesAroundHashParameters:
16
+ Enabled: false
17
+
18
+ # specs sometimes have useless assignments, which is fine
19
+ Lint/UselessAssignment:
20
+ Exclude:
21
+ - '**/spec/**/*'
22
+
23
+ # We could potentially enable the 2 below:
24
+ Layout/IndentHash:
25
+ Enabled: false
26
+
27
+ Layout/AlignHash:
28
+ Enabled: false
29
+
30
+ # HoundCI doesn't like this rule
31
+ Layout/DotPosition:
32
+ Enabled: false
33
+
34
+ # We allow !! as it's an easy way to convert ot boolean
35
+ Style/DoubleNegation:
36
+ Enabled: false
37
+
38
+ # Cop supports --auto-correct.
39
+ Lint/UnusedBlockArgument:
40
+ Enabled: false
41
+
42
+ # We want to allow class Fastlane::Class
43
+ Style/ClassAndModuleChildren:
44
+ Enabled: false
45
+
46
+ Metrics/AbcSize:
47
+ Max: 60
48
+
49
+ # The %w might be confusing for new users
50
+ Style/WordArray:
51
+ MinSize: 19
52
+
53
+ # raise and fail are both okay
54
+ Style/SignalException:
55
+ Enabled: false
56
+
57
+ # Better too much 'return' than one missing
58
+ Style/RedundantReturn:
59
+ Enabled: false
60
+
61
+ # Having if in the same line might not always be good
62
+ Style/IfUnlessModifier:
63
+ Enabled: false
64
+
65
+ # and and or is okay
66
+ Style/AndOr:
67
+ Enabled: false
68
+
69
+ # Configuration parameters: CountComments.
70
+ Metrics/ClassLength:
71
+ Max: 350
72
+
73
+ Metrics/CyclomaticComplexity:
74
+ Max: 17
75
+
76
+ # Configuration parameters: AllowURI, URISchemes.
77
+ Metrics/LineLength:
78
+ Max: 370
79
+
80
+ # Configuration parameters: CountKeywordArgs.
81
+ Metrics/ParameterLists:
82
+ Max: 10
83
+
84
+ Metrics/PerceivedComplexity:
85
+ Max: 18
86
+
87
+ # Sometimes it's easier to read without guards
88
+ Style/GuardClause:
89
+ Enabled: false
90
+
91
+ # something = if something_else
92
+ # that's confusing
93
+ Style/ConditionalAssignment:
94
+ Enabled: false
95
+
96
+ # Better to have too much self than missing a self
97
+ Style/RedundantSelf:
98
+ Enabled: false
99
+
100
+ Metrics/MethodLength:
101
+ Max: 60
102
+
103
+ # We're not there yet
104
+ Style/Documentation:
105
+ Enabled: false
106
+
107
+ # Adds complexity
108
+ Style/IfInsideElse:
109
+ Enabled: false
110
+
111
+ # danger specific
112
+
113
+ Style/BlockComments:
114
+ Enabled: false
115
+
116
+ Layout/MultilineMethodCallIndentation:
117
+ EnforcedStyle: indented
118
+
119
+ # FIXME: 25
120
+ Metrics/BlockLength:
121
+ Max: 345
122
+ Exclude:
123
+ - "**/*_spec.rb"
124
+
125
+ Style/MixinGrouping:
126
+ Enabled: false
127
+
128
+ Style/FileName:
129
+ Enabled: false
130
+
131
+ Layout/IndentHeredoc:
132
+ Enabled: false
133
+
134
+ Style/SpecialGlobalVars:
135
+ Enabled: false
136
+
137
+ PercentLiteralDelimiters:
138
+ PreferredDelimiters:
139
+ "%": ()
140
+ "%i": ()
141
+ "%q": ()
142
+ "%Q": ()
143
+ "%r": "{}"
144
+ "%s": ()
145
+ "%w": ()
146
+ "%W": ()
147
+ "%x": ()
148
+
149
+ Security/YAMLLoad:
150
+ Enabled: false
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.2.7
8
+ - 2.3.3
9
+ - 2.4.1
10
+
11
+ script:
12
+ - 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-checkstyle_formatter.gemspec
4
+ gemspec
@@ -0,0 +1,148 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-checkstyle_formatter (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+ ox (~> 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.1)
14
+ claide (1.0.3)
15
+ claide-plugins (0.9.2)
16
+ cork
17
+ nap
18
+ open4 (~> 1.3)
19
+ coderay (1.1.3)
20
+ colored2 (3.1.2)
21
+ cork (0.3.0)
22
+ colored2 (~> 3.1)
23
+ danger (8.0.5)
24
+ claide (~> 1.0)
25
+ claide-plugins (>= 0.9.2)
26
+ colored2 (~> 3.1)
27
+ cork (~> 0.1)
28
+ faraday (>= 0.9.0, < 2.0)
29
+ faraday-http-cache (~> 2.0)
30
+ git (~> 1.7)
31
+ kramdown (~> 2.3)
32
+ kramdown-parser-gfm (~> 1.0)
33
+ no_proxy_fix
34
+ octokit (~> 4.7)
35
+ terminal-table (~> 1)
36
+ danger-plugin-api (1.0.0)
37
+ danger (> 2.0)
38
+ diff-lcs (1.4.4)
39
+ faraday (1.0.1)
40
+ multipart-post (>= 1.2, < 3)
41
+ faraday-http-cache (2.2.0)
42
+ faraday (>= 0.8)
43
+ ffi (1.13.1)
44
+ formatador (0.2.5)
45
+ git (1.7.0)
46
+ rchardet (~> 1.8)
47
+ guard (2.16.2)
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
+ kramdown (2.3.0)
62
+ rexml
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.2.8)
69
+ method_source (1.0.0)
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.18.0)
78
+ faraday (>= 0.9)
79
+ sawyer (~> 0.8.0, >= 0.5.3)
80
+ open4 (1.3.4)
81
+ ox (2.13.4)
82
+ parallel (1.19.2)
83
+ parser (2.7.1.4)
84
+ ast (~> 2.4.1)
85
+ pry (0.13.1)
86
+ coderay (~> 1.1)
87
+ method_source (~> 1.0)
88
+ public_suffix (4.0.6)
89
+ rainbow (3.0.0)
90
+ rake (10.5.0)
91
+ rb-fsevent (0.10.4)
92
+ rb-inotify (0.10.1)
93
+ ffi (~> 1.0)
94
+ rchardet (1.8.0)
95
+ regexp_parser (1.7.1)
96
+ rexml (3.2.4)
97
+ rspec (3.9.0)
98
+ rspec-core (~> 3.9.0)
99
+ rspec-expectations (~> 3.9.0)
100
+ rspec-mocks (~> 3.9.0)
101
+ rspec-core (3.9.2)
102
+ rspec-support (~> 3.9.3)
103
+ rspec-expectations (3.9.2)
104
+ diff-lcs (>= 1.2.0, < 2.0)
105
+ rspec-support (~> 3.9.0)
106
+ rspec-mocks (3.9.1)
107
+ diff-lcs (>= 1.2.0, < 2.0)
108
+ rspec-support (~> 3.9.0)
109
+ rspec-support (3.9.3)
110
+ rubocop (0.90.0)
111
+ parallel (~> 1.10)
112
+ parser (>= 2.7.1.1)
113
+ rainbow (>= 2.2.2, < 4.0)
114
+ regexp_parser (>= 1.7)
115
+ rexml
116
+ rubocop-ast (>= 0.3.0, < 1.0)
117
+ ruby-progressbar (~> 1.7)
118
+ unicode-display_width (>= 1.4.0, < 2.0)
119
+ rubocop-ast (0.4.0)
120
+ parser (>= 2.7.1.4)
121
+ ruby-progressbar (1.10.1)
122
+ sawyer (0.8.2)
123
+ addressable (>= 2.3.5)
124
+ faraday (> 0.8, < 2.0)
125
+ shellany (0.0.1)
126
+ terminal-table (1.8.0)
127
+ unicode-display_width (~> 1.1, >= 1.1.1)
128
+ thor (1.0.1)
129
+ unicode-display_width (1.7.0)
130
+ yard (0.9.25)
131
+
132
+ PLATFORMS
133
+ ruby
134
+
135
+ DEPENDENCIES
136
+ bundler (~> 1.3)
137
+ danger-checkstyle_formatter!
138
+ guard (~> 2.14)
139
+ guard-rspec (~> 4.7)
140
+ listen (= 3.0.7)
141
+ pry
142
+ rake (~> 10.0)
143
+ rspec (~> 3.4)
144
+ rubocop (~> 0.52)
145
+ yard (~> 0.9.11)
146
+
147
+ BUNDLED WITH
148
+ 1.16.1
@@ -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) 2017 noboru-i <ishikura.noboru@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,31 @@
1
+ [![Build Status](https://travis-ci.org/noboru-i/danger-checkstyle_format.svg?branch=master)](https://travis-ci.org/noboru-i/danger-checkstyle_format)
2
+
3
+ # danger-checkstyle_formatter
4
+
5
+ Danger plugin for checkstyle formatted xml file.
6
+
7
+ ## Installation
8
+
9
+ $ gem install danger-checkstyle_formatter
10
+
11
+ ## Usage
12
+
13
+ <blockquote>Parse the XML file, and let the plugin do your reporting
14
+ <pre>
15
+ checkstyle_format.base_path = Dir.pwd
16
+ checkstyle_format.report 'app/build/reports/checkstyle/checkstyle.xml'</pre>
17
+ </blockquote>
18
+
19
+ <blockquote>Parse the XML text, and let the plugin do your reporting
20
+ <pre>
21
+ checkstyle_format.base_path = Dir.pwd
22
+ checkstyle_format.report_by_text '<?xml ...'</pre>
23
+ </blockquote>
24
+
25
+ ## Development
26
+
27
+ 1. Clone this repo
28
+ 2. Run `bundle install` to setup dependencies.
29
+ 3. Run `bundle exec rake spec` to run the tests.
30
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
31
+ 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 = ['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 'checkstyle_formatter/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-checkstyle_formatter'
8
+ spec.version = CheckstyleFormatter::VERSION
9
+ spec.authors = ['noboru-i', 'Sergio Fierro']
10
+ spec.email = ['ishikura.noboru@gmail.com']
11
+ spec.description = %q{Danger plugin for checkstyle formatted xml file.}
12
+ spec.summary = %q{Danger plugin for checkstyle formatted xml file.}
13
+ spec.homepage = 'https://github.com/SergioFierro/danger-checkstyle_format'
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 'ox', '~> 2.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", "~> 0.52"
33
+ spec.add_development_dependency "yard", "~> 0.9.11"
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
+ module CheckstyleFormatter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,80 @@
1
+ require_relative "checkstyle_error"
2
+
3
+ module Danger
4
+ # Danger plugin for checkstyle formatted xml file.
5
+ #
6
+ # @example Parse the XML file, and let the plugin do your reporting
7
+ #
8
+ # checkstyle_format.base_path = Dir.pwd
9
+ # checkstyle_format.report 'app/build/reports/checkstyle/checkstyle.xml'
10
+ #
11
+ # @example Parse the XML text, and let the plugin do your reporting
12
+ #
13
+ # checkstyle_format.base_path = Dir.pwd
14
+ # checkstyle_format.report_by_text '<?xml ...'
15
+ #
16
+ # @see noboru-i/danger-checkstyle_format
17
+ # @tags lint, reporting
18
+ #
19
+ class DangerCheckstyleFormatter < Plugin
20
+ # Base path of `name` attributes in `file` tag.
21
+ # Defaults to nil.
22
+ # @return [String]
23
+ attr_accessor :base_path
24
+
25
+ # Report checkstyle warnings
26
+ #
27
+ # @return [void]
28
+ def report(file, inline_mode = true)
29
+ raise "Please specify file name." if file.empty?
30
+ raise "No checkstyle file was found at #{file}" unless File.exist? file
31
+ errors = parse(File.read(file))
32
+
33
+ send_comment(errors, inline_mode)
34
+ end
35
+
36
+ # Report checkstyle warnings by XML text
37
+ #
38
+ # @return [void]
39
+ def report_by_text(text, inline_mode = true)
40
+ raise "Please specify xml text." if text.empty?
41
+ errors = parse(text)
42
+
43
+ send_comment(errors, inline_mode)
44
+ end
45
+
46
+ private
47
+
48
+ def parse(text)
49
+ require "ox"
50
+
51
+ doc = Ox.parse(text)
52
+ present_elements = doc.nodes.first.nodes.reject do |test|
53
+ test.nodes.empty?
54
+ end
55
+ base_path_suffix = @base_path.end_with?("/") ? "" : "/"
56
+ base_path = @base_path + base_path_suffix
57
+ elements = present_elements.flat_map do |parent|
58
+ parent.nodes.map do |child|
59
+ CheckstyleError.generate(child, parent, base_path)
60
+ end
61
+ end
62
+
63
+ elements
64
+ end
65
+
66
+ def send_comment(errors, inline_mode)
67
+ if inline_mode
68
+ send_inline_comment(errors)
69
+ else
70
+ raise "not implemented." # TODO: not implemented.
71
+ end
72
+ end
73
+
74
+ def send_inline_comment(errors)
75
+ errors.each do |error|
76
+ fail(error.message, file: error.file_name, line: error.line)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,12 @@
1
+ CheckstyleError = Struct.new(:file_name, :line, :column, :severity, :message, :source) do
2
+ def self.generate(node, parent_node, base_path)
3
+ CheckstyleError.new(
4
+ parent_node[:name].sub(/^#{base_path}/, ""),
5
+ node[:line].to_i,
6
+ node[:column].nil? ? nil : node[:column].to_i,
7
+ node[:severity],
8
+ node[:message],
9
+ node[:source]
10
+ )
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module CheckstyleFormatter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,80 @@
1
+ require_relative "checkstyle_error"
2
+
3
+ module Danger
4
+ # Danger plugin for checkstyle formatted xml file.
5
+ #
6
+ # @example Parse the XML file, and let the plugin do your reporting
7
+ #
8
+ # checkstyle_format.base_path = Dir.pwd
9
+ # checkstyle_format.report 'app/build/reports/checkstyle/checkstyle.xml'
10
+ #
11
+ # @example Parse the XML text, and let the plugin do your reporting
12
+ #
13
+ # checkstyle_format.base_path = Dir.pwd
14
+ # checkstyle_format.report_by_text '<?xml ...'
15
+ #
16
+ # @see noboru-i/danger-checkstyle_format
17
+ # @tags lint, reporting
18
+ #
19
+ class DangerCheckstyleFormatter < Plugin
20
+ # Base path of `name` attributes in `file` tag.
21
+ # Defaults to nil.
22
+ # @return [String]
23
+ attr_accessor :base_path
24
+
25
+ # Report checkstyle warnings
26
+ #
27
+ # @return [void]
28
+ def report(file, inline_mode = true)
29
+ raise "Please specify file name." if file.empty?
30
+ raise "No checkstyle file was found at #{file}" unless File.exist? file
31
+ errors = parse(File.read(file))
32
+
33
+ send_comment(errors, inline_mode)
34
+ end
35
+
36
+ # Report checkstyle warnings by XML text
37
+ #
38
+ # @return [void]
39
+ def report_by_text(text, inline_mode = true)
40
+ raise "Please specify xml text." if text.empty?
41
+ errors = parse(text)
42
+
43
+ send_comment(errors, inline_mode)
44
+ end
45
+
46
+ private
47
+
48
+ def parse(text)
49
+ require "ox"
50
+
51
+ doc = Ox.parse(text)
52
+ present_elements = doc.nodes.first.nodes.reject do |test|
53
+ test.nodes.empty?
54
+ end
55
+ base_path_suffix = @base_path.end_with?("/") ? "" : "/"
56
+ base_path = @base_path + base_path_suffix
57
+ elements = present_elements.flat_map do |parent|
58
+ parent.nodes.map do |child|
59
+ CheckstyleError.generate(child, parent, base_path)
60
+ end
61
+ end
62
+
63
+ elements
64
+ end
65
+
66
+ def send_comment(errors, inline_mode)
67
+ if inline_mode
68
+ send_inline_comment(errors)
69
+ else
70
+ raise "not implemented." # TODO: not implemented.
71
+ end
72
+ end
73
+
74
+ def send_inline_comment(errors)
75
+ errors.each do |error|
76
+ fail(error.message, file: error.file_name, line: error.line)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1 @@
1
+ require "checkstyle_formatter/gem_version"
@@ -0,0 +1 @@
1
+ require "checkstyle_formatter/plugin"
@@ -0,0 +1,57 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerCheckstyleFormatter do
5
+ it "should be a plugin" do
6
+ expect(Danger::DangerCheckstyleFormatter.new(nil)).to be_a Danger::Plugin
7
+ end
8
+
9
+ describe "with Dangerfile" do
10
+ before do
11
+ @dangerfile = testing_dangerfile
12
+ @checkstyle_formatter = @dangerfile.checkstyle_formatter
13
+ end
14
+
15
+ describe ".send_inline_comment" do
16
+ it "calls certain argument" do
17
+ errors = [
18
+ CheckstyleError.new("XXX.java", 1, nil, "error", "test message1.", "source"),
19
+ CheckstyleError.new("YYY.java", 2, nil, "error", "test message2.", "source")
20
+ ]
21
+ @checkstyle_formatter.send(:send_inline_comment, errors)
22
+ expect(@checkstyle_formatter.status_report[:warnings]).to eq(["test message1.", "test message2."])
23
+ expect(@checkstyle_formatter.violation_report[:warnings][0]).to eq(Violation.new("test message1.", false, "XXX.java", 1))
24
+ expect(@checkstyle_formatter.violation_report[:warnings][1]).to eq(Violation.new("test message2.", false, "YYY.java", 2))
25
+ end
26
+ end
27
+
28
+ describe ".parse" do
29
+ subject(:errors) do
30
+ @checkstyle_formatter.base_path = "/path/to"
31
+ @checkstyle_formatter.send(:parse, File.read("spec/fixtures/checkstyle.xml"))
32
+ end
33
+ it "have 4 items" do
34
+ expect(errors.size).to be 4
35
+ end
36
+
37
+ it "is mapped CheckstyleError about index is 0" do
38
+ expect(errors[0].file_name).to eq("XXX.java")
39
+ expect(errors[0].line).to eq(0)
40
+ expect(errors[0].column).to be_nil
41
+ expect(errors[0].severity).to eq("error")
42
+ expect(errors[0].message).to eq("File does not end with a newline.")
43
+ expect(errors[0].source).to eq("com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck")
44
+ end
45
+
46
+ it "is mapped CheckstyleError about index is 2" do
47
+ expect(errors[2].file_name).to eq("YYY.java")
48
+ expect(errors[2].line).to eq(12)
49
+ expect(errors[2].column).to eq(13)
50
+ expect(errors[2].severity).to eq("error")
51
+ expect(errors[2].message).to eq("Name 'enableOcr' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.")
52
+ expect(errors[2].source).to eq("com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <checkstyle version="5.9">
3
+ <file name="/path/to/XXX.java">
4
+ <error line="0" severity="error" message="File does not end with a newline." source="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
5
+ </file>
6
+ <file name="/path/to/YYY.java">
7
+ <error line="9" severity="error" message="interfaces should describe a type and hence have methods." source="com.puppycrawl.tools.checkstyle.checks.design.InterfaceIsTypeCheck"/>
8
+ <error line="12" column="13" severity="error" message="Name &apos;enableOcr&apos; must match pattern &apos;^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$&apos;." source="com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck"/>
9
+ <error line="15" column="12" severity="error" message="Name &apos;selectedLanguage&apos; must match pattern &apos;^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$&apos;." source="com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck"/>
10
+ </file>
11
+ <file name="/path/to/ZZZ.java">
12
+ </file>
13
+ </checkstyle>
@@ -0,0 +1,65 @@
1
+ require "pathname"
2
+ ROOT = Pathname.new(File.expand_path("../../", __FILE__))
3
+ $:.unshift((ROOT + "lib").to_s)
4
+ $:.unshift((ROOT + "spec").to_s)
5
+
6
+ require "bundler/setup"
7
+ require "pry"
8
+
9
+ require "rspec"
10
+ require "danger"
11
+
12
+ if `git remote -v` == ""
13
+ puts "You cannot run tests without setting a local git remote on this repo"
14
+ puts "It's a weird side-effect of Danger's internals."
15
+ exit(0)
16
+ end
17
+
18
+ # Use coloured output, it's the best.
19
+ RSpec.configure do |config|
20
+ config.filter_gems_from_backtrace "bundler"
21
+ config.color = true
22
+ config.tty = true
23
+ end
24
+
25
+ require "danger_plugin"
26
+
27
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
28
+ # If you are expanding these files, see if it's already been done ^.
29
+
30
+ # A silent version of the user interface,
31
+ # it comes with an extra function `.string` which will
32
+ # strip all ANSI colours from the string.
33
+
34
+ # rubocop:disable Lint/NestedMethodDefinition
35
+ def testing_ui
36
+ @output = StringIO.new
37
+ def @output.winsize
38
+ [20, 9999]
39
+ end
40
+
41
+ cork = Cork::Board.new(out: @output)
42
+ def cork.string
43
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
44
+ end
45
+ cork
46
+ end
47
+ # rubocop:enable Lint/NestedMethodDefinition
48
+
49
+ # Example environment (ENV) that would come from
50
+ # running a PR on TravisCI
51
+ def testing_env
52
+ {
53
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
54
+ "TRAVIS_PULL_REQUEST" => "800",
55
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
56
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
57
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
58
+ }
59
+ end
60
+
61
+ # A stubbed out Dangerfile for use in tests
62
+ def testing_dangerfile
63
+ env = Danger::EnvironmentManager.new(testing_env)
64
+ Danger::Dangerfile.new(env, testing_ui)
65
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-checkstyle_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - noboru-i
8
+ - Sergio Fierro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-09-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: danger-plugin-api
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: ox
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.4'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.4'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.52'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.52'
98
+ - !ruby/object:Gem::Dependency
99
+ name: yard
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 0.9.11
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 0.9.11
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2.14'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.14'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '4.7'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '4.7'
140
+ - !ruby/object:Gem::Dependency
141
+ name: listen
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '='
145
+ - !ruby/object:Gem::Version
146
+ version: 3.0.7
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '='
152
+ - !ruby/object:Gem::Version
153
+ version: 3.0.7
154
+ - !ruby/object:Gem::Dependency
155
+ name: pry
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: Danger plugin for checkstyle formatted xml file.
169
+ email:
170
+ - ishikura.noboru@gmail.com
171
+ executables: []
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".rubocop.yml"
177
+ - ".travis.yml"
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - Guardfile
181
+ - LICENSE.txt
182
+ - README.md
183
+ - Rakefile
184
+ - danger-checkstyle_format.gemspec
185
+ - lib/checkstyle_format/gem_version.rb
186
+ - lib/checkstyle_format/plugin.rb
187
+ - lib/checkstyle_formatter/checkstyle_error.rb
188
+ - lib/checkstyle_formatter/gem_version.rb
189
+ - lib/checkstyle_formatter/plugin.rb
190
+ - lib/danger_checkstyle_format.rb
191
+ - lib/danger_plugin.rb
192
+ - spec/checkstyle_format_spec.rb
193
+ - spec/fixtures/checkstyle.xml
194
+ - spec/spec_helper.rb
195
+ homepage: https://github.com/SergioFierro/danger-checkstyle_format
196
+ licenses:
197
+ - MIT
198
+ metadata: {}
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubygems_version: 3.1.2
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: Danger plugin for checkstyle formatted xml file.
218
+ test_files:
219
+ - spec/checkstyle_format_spec.rb
220
+ - spec/fixtures/checkstyle.xml
221
+ - spec/spec_helper.rb