undercover-checkstyle 0.2.0

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: 5bb973c988f9367c91a266fe9f0f41f60aff4d2c0ebc5f8a2dd3b02e65e7d0c1
4
+ data.tar.gz: bb5dab6911a669557e3086cb18bd20099288ad62992b4a09bd2b9ba1d43bed95
5
+ SHA512:
6
+ metadata.gz: eeef65f9631b5577523be2b873d93520592c7214a6e16dd3e7cdaf62ce00749c430ee3395d558caa76fc7a33573b2f1016f26b4b052da83c4cda8e2a96b4ef4b
7
+ data.tar.gz: 7f7ac8c5ba35dd373f023c9a9b9f4d32912527669dd5ae820eb7c36a95114820475483833546c1572153f5abb0cb268371fe13bcce4c8d0632f45765bb99bd27
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at lala.akira@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in undercover-checkstyle.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 aki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # undercover-checkstyle
2
+
3
+ ![Actions Demo](https://i.gyazo.com/881890dcba76cf30a8db86d9635ba38a.png)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'undercover-checkstyle'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ ## Usage
18
+
19
+ [Setting up required LCOV reporting](https://github.com/grodowski/undercover#setting-up-required-lcov-reporting)
20
+
21
+ ```
22
+ bundle exec undercover-checkstyle
23
+ ```
24
+
25
+ ### GitHub Actions Example
26
+
27
+ *reviewdog.yml*
28
+ ```yaml
29
+ runner:
30
+ undercover:
31
+ cmd: bundle exec undercover-checkstyle --compare origin/master
32
+ level: warning
33
+ format: checkstyle
34
+ ```
35
+
36
+ *.github/workflows/ruby.yml*
37
+ ```yaml
38
+ name: Ruby
39
+
40
+ on:
41
+ pull_request:
42
+
43
+ jobs:
44
+ rspec:
45
+ runs-on: ubuntu-latest
46
+
47
+ env:
48
+ RUBYOPT: -EUTF-8
49
+
50
+ steps:
51
+ - uses: actions/checkout@v2
52
+
53
+ - name: Set up Ruby
54
+ uses: ruby/setup-ruby@v1
55
+
56
+ - name: Bundle install
57
+ run: |
58
+ bundle config path vendor/bundle
59
+ bundle install --jobs 4 --retry 3
60
+
61
+ - name: Rspec
62
+ run: bundle exec rspec
63
+
64
+ - name: Setup reviewdog
65
+ run: |
66
+ mkdir -p $HOME/bin && curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $HOME/bin
67
+ echo ::add-path::$HOME/bin
68
+ echo ::add-path::$(go env GOPATH)/bin # for Go projects
69
+
70
+ - name: Run reviewdog
71
+ env:
72
+ REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73
+ run: |
74
+ git fetch
75
+ reviewdog -reporter=github-pr-review -runners=undercover
76
+ ```
77
+
78
+ ## Thanks
79
+
80
+ - [grodowski/undercover: Actionable code coverage \- detects untested code blocks in recent changes](https://github.com/grodowski/undercover)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "undercover/checkstyle"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
5
+ $VERBOSE = nil
6
+
7
+ require 'undercover/checkstyle'
8
+
9
+ result = Undercover::Checkstyle::CLI.run(ARGV)
10
+ exit result
@@ -0,0 +1,7 @@
1
+ require "undercover/checkstyle/version"
2
+ require "undercover/checkstyle/cli"
3
+
4
+ module Undercover
5
+ module Checkstyle
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'undercover'
4
+ require 'undercover/checkstyle/formatter'
5
+
6
+ module Undercover
7
+ module Checkstyle
8
+ module CLI
9
+ def self.run(args)
10
+ opts = Undercover::Options.new.parse(args)
11
+ syntax_version(opts.syntax_version)
12
+
13
+ run_report(opts)
14
+ end
15
+
16
+ def self.run_report(opts)
17
+ report = Undercover::Report.new(changeset(opts), opts).build
18
+ flagged = report.flagged_results
19
+ puts Undercover::Checkstyle::Formatter.new(flagged)
20
+ flagged.any? ? 1 : 0
21
+ end
22
+
23
+ def self.syntax_version(version)
24
+ return unless version
25
+
26
+ Imagen.parser_version = version
27
+ end
28
+
29
+ def self.changeset(opts)
30
+ git_dir = File.join(opts.path, opts.git_dir)
31
+ Undercover::Changeset.new(git_dir, opts.compare)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+ require 'stringio'
3
+ require 'rexml/document'
4
+ require 'rexml/formatters/pretty'
5
+
6
+ module Undercover
7
+ module Checkstyle
8
+ class Formatter
9
+ def initialize(results)
10
+ @results = results
11
+ end
12
+
13
+ def to_s
14
+ file_annotations = warnings_to_annotations.group_by { |annotation| annotation[:path] }
15
+
16
+ doc = REXML::Document.new
17
+ doc << REXML::XMLDecl.new('1.0', 'UTF-8')
18
+ checkstyle = REXML::Element.new('checkstyle', doc)
19
+ file_annotations.each do |path, annotations|
20
+ checkstyle << file_element(path, annotations)
21
+ end
22
+
23
+ output = StringIO.new
24
+ pretty_formatter = REXML::Formatters::Pretty.new
25
+ pretty_formatter.write(doc, output)
26
+ output.string
27
+ end
28
+
29
+ private
30
+
31
+ def format_lines(lines)
32
+ prev = lines[0]
33
+ slices = lines.slice_before do |e|
34
+ (prev + 1 != e).tap { prev = e }
35
+ end
36
+ slices.map { |slice_first, *, slice_last| slice_last ? (slice_first..slice_last) : slice_first }
37
+ end
38
+
39
+ def file_element(path, annotations)
40
+ file = REXML::Element.new('file')
41
+ file.attributes['name'] = path
42
+ annotations.each do |annotation|
43
+ error = REXML::Element.new('error', file)
44
+ error.attributes['line'] = annotation[:end_line]
45
+ error.attributes['column'] = 0
46
+ error.attributes['severity'] = 'warning'
47
+ error.attributes['message'] = annotation[:message]
48
+ error.attributes['source'] = annotation[:title]
49
+ end
50
+ file
51
+ end
52
+
53
+ # SEE: https://github.com/grodowski/undercover-ci/blob/master/lib/check_runs/complete.rb
54
+ def warnings_to_annotations
55
+ @results.map do |result|
56
+ # TODO: duplicates pronto-undercover logic, move to Undercover::Result
57
+ lines = result.coverage.map { |ln, _cov| ln if result.uncovered?(ln) }.compact
58
+ message = "#{result.node.human_name.capitalize} `#{result.node.name}` is missing" \
59
+ " coverage for line#{'s' if lines.size > 1} #{format_lines(lines).join(',')}" \
60
+ " (node coverage: #{result.coverage_f})"
61
+ {
62
+ path: result.file_path,
63
+ start_line: result.first_line,
64
+ end_line: result.last_line,
65
+ annotation_level: "warning",
66
+ title: "Untested #{result.node.human_name}",
67
+ message: message
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ module Undercover
2
+ module Checkstyle
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/undercover/checkstyle/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "undercover-checkstyle"
5
+ spec.version = Undercover::Checkstyle::VERSION
6
+ spec.authors = ["aki77"]
7
+ spec.email = ["aki77@users.noreply.github.com"]
8
+
9
+ spec.summary = %q{Undercover checkstyle reporter.}
10
+ spec.description = %q{Undercover checkstyle reporter.}
11
+ spec.homepage = "https://github.com/aki77/undercover-checkstyle"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency 'undercover', '>= 0.3.4'
28
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: undercover-checkstyle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - aki77
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: undercover
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.4
27
+ description: Undercover checkstyle reporter.
28
+ email:
29
+ - aki77@users.noreply.github.com
30
+ executables:
31
+ - undercover-checkstyle
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - exe/undercover-checkstyle
46
+ - lib/undercover/checkstyle.rb
47
+ - lib/undercover/checkstyle/cli.rb
48
+ - lib/undercover/checkstyle/formatter.rb
49
+ - lib/undercover/checkstyle/version.rb
50
+ - undercover-checkstyle.gemspec
51
+ homepage: https://github.com/aki77/undercover-checkstyle
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/aki77/undercover-checkstyle
56
+ source_code_uri: https://github.com/aki77/undercover-checkstyle
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.3.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.1.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Undercover checkstyle reporter.
76
+ test_files: []