simplecov_linter_formatter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock ADDED
@@ -0,0 +1,123 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simplecov_linter_formatter (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.1.4.1)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ zeitwerk (~> 2.3)
15
+ ast (2.4.2)
16
+ coderay (1.1.3)
17
+ concurrent-ruby (1.1.9)
18
+ diff-lcs (1.4.4)
19
+ docile (1.4.0)
20
+ ffi (1.15.4)
21
+ formatador (0.3.0)
22
+ guard (2.18.0)
23
+ formatador (>= 0.2.4)
24
+ listen (>= 2.7, < 4.0)
25
+ lumberjack (>= 1.0.12, < 2.0)
26
+ nenv (~> 0.1)
27
+ notiffany (~> 0.0)
28
+ pry (>= 0.13.0)
29
+ shellany (~> 0.0)
30
+ thor (>= 0.18.1)
31
+ guard-compat (1.2.1)
32
+ guard-rspec (4.7.3)
33
+ guard (~> 2.1)
34
+ guard-compat (~> 1.1)
35
+ rspec (>= 2.99.0, < 4.0)
36
+ i18n (1.8.10)
37
+ concurrent-ruby (~> 1.0)
38
+ listen (3.7.0)
39
+ rb-fsevent (~> 0.10, >= 0.10.3)
40
+ rb-inotify (~> 0.9, >= 0.9.10)
41
+ lumberjack (1.2.8)
42
+ method_source (1.0.0)
43
+ minitest (5.14.4)
44
+ nenv (0.3.0)
45
+ notiffany (0.1.3)
46
+ nenv (~> 0.1)
47
+ shellany (~> 0.0)
48
+ parallel (1.21.0)
49
+ parser (3.0.2.0)
50
+ ast (~> 2.4.1)
51
+ pry (0.14.1)
52
+ coderay (~> 1.1)
53
+ method_source (~> 1.0)
54
+ rack (2.2.3)
55
+ rainbow (3.0.0)
56
+ rake (12.3.3)
57
+ rb-fsevent (0.11.0)
58
+ rb-inotify (0.10.1)
59
+ ffi (~> 1.0)
60
+ regexp_parser (2.1.1)
61
+ rexml (3.2.5)
62
+ rspec (3.10.0)
63
+ rspec-core (~> 3.10.0)
64
+ rspec-expectations (~> 3.10.0)
65
+ rspec-mocks (~> 3.10.0)
66
+ rspec-core (3.10.1)
67
+ rspec-support (~> 3.10.0)
68
+ rspec-expectations (3.10.1)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.10.0)
71
+ rspec-mocks (3.10.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.10.0)
74
+ rspec-support (3.10.2)
75
+ rspec_junit_formatter (0.4.1)
76
+ rspec-core (>= 2, < 4, != 2.12.0)
77
+ rubocop (1.21.0)
78
+ parallel (~> 1.10)
79
+ parser (>= 3.0.0.0)
80
+ rainbow (>= 2.2.2, < 4.0)
81
+ regexp_parser (>= 1.8, < 3.0)
82
+ rexml
83
+ rubocop-ast (>= 1.9.1, < 2.0)
84
+ ruby-progressbar (~> 1.7)
85
+ unicode-display_width (>= 1.4.0, < 3.0)
86
+ rubocop-ast (1.11.0)
87
+ parser (>= 3.0.1.1)
88
+ rubocop-rails (2.12.2)
89
+ activesupport (>= 4.2.0)
90
+ rack (>= 1.1)
91
+ rubocop (>= 1.7.0, < 2.0)
92
+ ruby-progressbar (1.11.0)
93
+ shellany (0.0.1)
94
+ simplecov (0.21.2)
95
+ docile (~> 1.1)
96
+ simplecov-html (~> 0.11)
97
+ simplecov_json_formatter (~> 0.1)
98
+ simplecov-html (0.12.3)
99
+ simplecov_json_formatter (0.1.3)
100
+ thor (0.18.1)
101
+ tzinfo (2.0.4)
102
+ concurrent-ruby (~> 1.0)
103
+ unicode-display_width (2.1.0)
104
+ zeitwerk (2.4.2)
105
+
106
+ PLATFORMS
107
+ x86_64-darwin-20
108
+ x86_64-linux
109
+
110
+ DEPENDENCIES
111
+ bundler (~> 2.2.15)
112
+ guard-rspec
113
+ pry
114
+ rake (~> 12.0)
115
+ rspec (~> 3.0)
116
+ rspec_junit_formatter
117
+ rubocop (~> 1.9)
118
+ rubocop-rails
119
+ simplecov (~> 0.21)
120
+ simplecov_linter_formatter!
121
+
122
+ BUNDLED WITH
123
+ 2.2.15
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2021 Platanus
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.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # SimpleCov Linter Formatter
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/simplecov_linter_formatter.svg)](https://badge.fury.io/rb/simplecov_linter_formatter)
4
+ [![CircleCI](https://circleci.com/gh/platanus/simplecov_linter_formatter.svg?style=shield)](https://app.circleci.com/pipelines/github/platanus/simplecov_linter_formatter)
5
+
6
+ Linter formatter for SimpleCov code coverage tool
7
+
8
+ <img src="./docs/assets/not-covered.png" witdh="300" />
9
+ <img src="./docs/assets/partial-cov.png" witdh="300" />
10
+ <img src="./docs/assets/covered.png" witdh="300" />
11
+
12
+ ## Installation
13
+
14
+ - Install [reviewdog](https://github.com/reviewdog/reviewdog)
15
+
16
+ ```bash
17
+ brew install reviewdog/tap/reviewdog
18
+ ```
19
+
20
+ - Install [VSCode SimpleCov plugin](https://github.com/anykeyh/simplecov-vscode)
21
+
22
+ You need to configure `SimpleCovLinterFormatter.json_filename = '.resultset.json'` to use the extension's default configuration.
23
+ If you want yo keep the `.resultset.json` file intact you must change the plugin's "Path" option to point another file.
24
+
25
+ - Add to your Gemfile:
26
+
27
+ ```ruby
28
+ gem 'simplecov'
29
+ gem 'simplecov_linter_formatter'
30
+ ```
31
+
32
+ ```bash
33
+ bundle install
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ Add the formatter to your `spec/spec_helper.rb`.
39
+
40
+ ```ruby
41
+ require 'simplecov'
42
+ require 'simplecov_linter_formatter'
43
+
44
+ SimpleCovLinterFormatter.json_filename = '.resultset.json'
45
+ SimpleCovLinterFormatter.scope = :all
46
+
47
+ SimpleCov.start 'rails' do
48
+ # ...
49
+
50
+ formatter SimpleCov::Formatter::MultiFormatter.new(
51
+ [
52
+ SimpleCov::Formatter::LinterFormatter,
53
+ SimpleCov::Formatter::HTMLFormatter
54
+ ]
55
+ )
56
+ end
57
+ ```
58
+
59
+ If you configure `SimpleCovLinterFormatter.scope = :own_changes` instead of `:all` you will see coverage warnings related to your changes only (it uses `git diff`).
60
+
61
+ ## Testing
62
+
63
+ To run the specs you need to execute, **in the root path of the gem**, the following command:
64
+
65
+ ```bash
66
+ bundle exec guard
67
+ ```
68
+
69
+ You need to put **all your tests** in the `/simplecov_linter_formatter/spec/` directory.
70
+
71
+ ## Publishing
72
+
73
+ On master/main branch...
74
+
75
+ 1. Change `VERSION` in `lib/simplecov_linter_formatter/version.rb`.
76
+ 2. Change `Unreleased` title to current version in `CHANGELOG.md`.
77
+ 3. Run `bundle install`.
78
+ 4. Commit new release. For example: `Releasing v0.1.0`.
79
+ 5. Create tag. For example: `git tag v0.1.0`.
80
+ 6. Push tag. For example: `git push origin v0.1.0`.
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create new Pull Request
89
+
90
+ ## Credits
91
+
92
+ Thank you [contributors](https://github.com/platanus/simplecov_linter_formatter/graphs/contributors)!
93
+
94
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
95
+
96
+ SimpleCov Linter Formatter is maintained by [platanus](http://platan.us).
97
+
98
+ ## License
99
+
100
+ SimpleCov Linter Formatter is © 2021 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simplecov_linter_formatter"
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__)
data/bin/setup ADDED
@@ -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
Binary file
Binary file
Binary file
@@ -0,0 +1,23 @@
1
+ module SimpleCovLinterFormatter
2
+ class JsonResultExporter
3
+ def initialize(result_hash)
4
+ @result = result_hash
5
+ end
6
+
7
+ def export
8
+ File.open(export_path, 'w') do |file|
9
+ file << json_result
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def json_result
16
+ JSON.pretty_generate(@result)
17
+ end
18
+
19
+ def export_path
20
+ File.join(SimpleCov.coverage_path, SimpleCovLinterFormatter.json_filename)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module SimpleCovLinterFormatter
2
+ class ResultFormatter
3
+ def initialize(result)
4
+ @result = result
5
+ end
6
+
7
+ def format
8
+ formatted_result = []
9
+
10
+ @result.files.each do |source_file|
11
+ messages = format_source_file(source_file)
12
+ formatted_result += messages if messages
13
+ end
14
+
15
+ formatted_result
16
+ end
17
+
18
+ private
19
+
20
+ def format_source_file(source_file)
21
+ source_file_formatter = SourceFileFormatter.new(source_file)
22
+ source_file_formatter.format
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ module SimpleCovLinterFormatter
2
+ class SourceFileFormatter
3
+ FILE_COLUMN = 1
4
+
5
+ def initialize(source_file)
6
+ @source_file = source_file
7
+ end
8
+
9
+ def format
10
+ lines.map do |line|
11
+ build_message(line)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def build_message(line)
18
+ [
19
+ @source_file.filename,
20
+ line.line_number,
21
+ FILE_COLUMN,
22
+ "#{line.status}-#{lines_count}"
23
+ ].map(&:to_s).join(":")
24
+ end
25
+
26
+ def lines_count
27
+ @lines_count ||= lines.count
28
+ end
29
+
30
+ def lines
31
+ @lines ||= @source_file.lines
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ module SimpleCovLinterFormatter
2
+ class TextLinesFormatter
3
+ def initialize(command_name, lines)
4
+ @command_name = command_name
5
+ @lines = lines
6
+ end
7
+
8
+ def format
9
+ {
10
+ @command_name.to_sym => {
11
+ coverage: group_lines_by_file
12
+ }
13
+ }
14
+ end
15
+
16
+ private
17
+
18
+ def group_lines_by_file
19
+ result = {}
20
+
21
+ @lines.each do |line|
22
+ file_name, line_number, _column, status_lines_count = line.split(":")
23
+ status, lines_count = status_lines_count.split("-")
24
+ result[file_name] ||= { lines: [nil] * lines_count.to_i }
25
+ result[file_name][:lines][line_number.to_i - 1] = status.to_sym == :missed ? 0 : nil
26
+ end
27
+
28
+ result
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module SimpleCovLinterFormatter
2
+ class TextLinesFilter
3
+ def initialize(text_lines)
4
+ @text_lines = text_lines
5
+ end
6
+
7
+ def filter
8
+ file_content = filter_result
9
+ format_result(file_content)
10
+ end
11
+
12
+ private
13
+
14
+ def filter_result
15
+ return "" if text_content == ""
16
+
17
+ `echo "#{text_content}" | reviewdog -efm="%f:%l:%c:%m" -diff="git diff"`
18
+ end
19
+
20
+ def text_content
21
+ @text_content ||= @text_lines.join('\n')
22
+ end
23
+
24
+ def format_result(file_content)
25
+ file_content.to_s.split("\n")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleCovLinterFormatter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,72 @@
1
+ require 'simplecov_linter_formatter/version'
2
+ require 'simplecov_linter_formatter/formatters/result_formatter'
3
+ require 'simplecov_linter_formatter/formatters/source_file_formatter'
4
+ require 'simplecov_linter_formatter/formatters/text_lines_formatter'
5
+ require 'simplecov_linter_formatter/exporters/json_result_exporter'
6
+ require 'simplecov_linter_formatter/text_lines_filter'
7
+
8
+ module SimpleCovLinterFormatter
9
+ SCOPES = [:all, :own_changes]
10
+
11
+ def self.json_filename=(value)
12
+ @json_filename = value
13
+ end
14
+
15
+ def self.json_filename
16
+ @json_filename || 'coverage.linter.json'
17
+ end
18
+
19
+ def self.cover_all?
20
+ scope == :all
21
+ end
22
+
23
+ def self.scope=(value)
24
+ if !SCOPES.include?(value)
25
+ raise "Invalid scope. Must be one of: #{SCOPES.map(&:to_s).join('', '')}"
26
+ end
27
+
28
+ @scope = value
29
+ end
30
+
31
+ def self.scope
32
+ @scope || :all
33
+ end
34
+ end
35
+
36
+ module SimpleCov
37
+ module Formatter
38
+ class LinterFormatter
39
+ def format(simplecov_result)
40
+ text_lines = get_text_lines(simplecov_result)
41
+ hash_result = format_text_lines(simplecov_result.command_name, text_lines)
42
+ export_to_json(hash_result)
43
+ nil
44
+ end
45
+
46
+ private
47
+
48
+ def get_text_lines(simplecov_result)
49
+ text_lines = format_result(simplecov_result)
50
+ return text_lines if SimpleCovLinterFormatter.cover_all?
51
+
52
+ filter_text_lines(text_lines)
53
+ end
54
+
55
+ def filter_text_lines(text_lines)
56
+ SimpleCovLinterFormatter::TextLinesFilter.new(text_lines).filter
57
+ end
58
+
59
+ def format_result(simplecov_result)
60
+ SimpleCovLinterFormatter::ResultFormatter.new(simplecov_result).format
61
+ end
62
+
63
+ def format_text_lines(command_name, text_lines)
64
+ SimpleCovLinterFormatter::TextLinesFormatter.new(command_name, text_lines).format
65
+ end
66
+
67
+ def export_to_json(hash_result)
68
+ SimpleCovLinterFormatter::JsonResultExporter.new(hash_result).export
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "simplecov_linter_formatter/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "simplecov_linter_formatter"
7
+ spec.version = SimpleCovLinterFormatter::VERSION
8
+ spec.authors = ["Platanus", "Leandro Segovia"]
9
+ spec.email = ["rubygems@platan.us", "leandro@platan.us"]
10
+ spec.homepage = "https://github.com/platanus/simplecov_linter_formatter"
11
+ spec.summary = "Linter formatter for SimpleCov"
12
+ spec.description = "Linter formatter for SimpleCov code coverage tool"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 2.2.15"
21
+ spec.add_development_dependency "guard-rspec"
22
+ spec.add_development_dependency "pry"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec_junit_formatter"
26
+ spec.add_development_dependency "rubocop", "~> 1.9"
27
+ spec.add_development_dependency "rubocop-rails"
28
+ spec.add_development_dependency "simplecov", "~> 0.21"
29
+ end