├── .gitignore ├── .rubocop.yml ├── .travis.yml ├── Gemfile ├── Gemfile.lock ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── danger-checkstyle_format.gemspec ├── lib ├── checkstyle_format │ ├── checkstyle_error.rb │ ├── gem_version.rb │ └── plugin.rb ├── danger_checkstyle_format.rb └── danger_plugin.rb └── spec ├── checkstyle_format_spec.rb ├── fixtures └── checkstyle.xml └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | pkg 3 | .idea/ 4 | .yardoc 5 | 6 | ## Environment normalization: 7 | /.bundle/ 8 | /vendor/bundle 9 | /lib/bundler/man/ 10 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 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 151 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 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 13 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in danger-checkstyle_format.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | danger-checkstyle_format (0.1.1) 5 | danger-plugin-api (~> 1.0) 6 | ox (~> 2.0) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | addressable (2.5.2) 12 | public_suffix (>= 2.0.2, < 4.0) 13 | ast (2.3.0) 14 | claide (1.0.2) 15 | claide-plugins (0.9.2) 16 | cork 17 | nap 18 | open4 (~> 1.3) 19 | coderay (1.1.2) 20 | colored2 (3.1.2) 21 | cork (0.3.0) 22 | colored2 (~> 3.1) 23 | danger (5.5.5) 24 | claide (~> 1.0) 25 | claide-plugins (>= 0.9.2) 26 | colored2 (~> 3.1) 27 | cork (~> 0.1) 28 | faraday (~> 0.9) 29 | faraday-http-cache (~> 1.0) 30 | git (~> 1) 31 | kramdown (~> 1.5) 32 | no_proxy_fix 33 | octokit (~> 4.7) 34 | terminal-table (~> 1) 35 | danger-plugin-api (1.0.0) 36 | danger (> 2.0) 37 | diff-lcs (1.3) 38 | faraday (0.13.1) 39 | multipart-post (>= 1.2, < 3) 40 | faraday-http-cache (1.3.1) 41 | faraday (~> 0.8) 42 | ffi (1.9.18) 43 | formatador (0.2.5) 44 | git (1.3.0) 45 | guard (2.14.1) 46 | formatador (>= 0.2.4) 47 | listen (>= 2.7, < 4.0) 48 | lumberjack (~> 1.0) 49 | nenv (~> 0.1) 50 | notiffany (~> 0.0) 51 | pry (>= 0.9.12) 52 | shellany (~> 0.0) 53 | thor (>= 0.18.1) 54 | guard-compat (1.2.1) 55 | guard-rspec (4.7.3) 56 | guard (~> 2.1) 57 | guard-compat (~> 1.1) 58 | rspec (>= 2.99.0, < 4.0) 59 | kramdown (1.16.2) 60 | listen (3.0.7) 61 | rb-fsevent (>= 0.9.3) 62 | rb-inotify (>= 0.9.7) 63 | lumberjack (1.0.12) 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.8.0) 73 | sawyer (~> 0.8.0, >= 0.5.3) 74 | open4 (1.3.4) 75 | ox (2.8.2) 76 | parallel (1.12.1) 77 | parser (2.4.0.2) 78 | ast (~> 2.3) 79 | powerpack (0.1.1) 80 | pry (0.11.3) 81 | coderay (~> 1.1.0) 82 | method_source (~> 0.9.0) 83 | public_suffix (3.0.1) 84 | rainbow (3.0.0) 85 | rake (10.5.0) 86 | rb-fsevent (0.10.2) 87 | rb-inotify (0.9.10) 88 | ffi (>= 0.5.0, < 2) 89 | rspec (3.7.0) 90 | rspec-core (~> 3.7.0) 91 | rspec-expectations (~> 3.7.0) 92 | rspec-mocks (~> 3.7.0) 93 | rspec-core (3.7.0) 94 | rspec-support (~> 3.7.0) 95 | rspec-expectations (3.7.0) 96 | diff-lcs (>= 1.2.0, < 2.0) 97 | rspec-support (~> 3.7.0) 98 | rspec-mocks (3.7.0) 99 | diff-lcs (>= 1.2.0, < 2.0) 100 | rspec-support (~> 3.7.0) 101 | rspec-support (3.7.0) 102 | rubocop (0.52.0) 103 | parallel (~> 1.10) 104 | parser (>= 2.4.0.2, < 3.0) 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.3.0) 118 | yard (0.9.12) 119 | 120 | PLATFORMS 121 | ruby 122 | 123 | DEPENDENCIES 124 | bundler (~> 1.3) 125 | danger-checkstyle_format! 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 (~> 0.52) 133 | yard (~> 0.9.11) 134 | 135 | BUNDLED WITH 136 | 1.16.1 137 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 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 20 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 noboru-i 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. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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_format 4 | 5 | Danger plugin for checkstyle formatted xml file. 6 | 7 | ## Installation 8 | 9 | $ gem install danger-checkstyle_format 10 | 11 | ## Usage 12 | 13 |
Parse the XML file, and let the plugin do your reporting 14 |
15 | checkstyle_format.base_path = Dir.pwd
16 | checkstyle_format.report 'app/build/reports/checkstyle/checkstyle.xml'
17 |
18 | 19 |
Parse the XML text, and let the plugin do your reporting 20 |
21 | checkstyle_format.base_path = Dir.pwd
22 | checkstyle_format.report_by_text '
23 | 
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. 32 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 24 | -------------------------------------------------------------------------------- /danger-checkstyle_format.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'checkstyle_format/gem_version.rb' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'danger-checkstyle_format' 8 | spec.version = CheckstyleFormat::VERSION 9 | spec.authors = ['noboru-i'] 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/noboru-i/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 51 | -------------------------------------------------------------------------------- /lib/checkstyle_format/checkstyle_error.rb: -------------------------------------------------------------------------------- 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 13 | -------------------------------------------------------------------------------- /lib/checkstyle_format/gem_version.rb: -------------------------------------------------------------------------------- 1 | module CheckstyleFormat 2 | VERSION = "0.1.1".freeze 3 | end 4 | -------------------------------------------------------------------------------- /lib/checkstyle_format/plugin.rb: -------------------------------------------------------------------------------- 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 ' 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 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 66 | --------------------------------------------------------------------------------