SimpleCov Linter Formatter
Linter formatter for SimpleCov code coverage tool
Note: To learn more about SimpleCov, check out the main repo at https://github.com/simplecov-ruby/simplecov
This formatter has two features:
1) It generates a json file to feed the VSCode SimpleCov plugin.
The plugin uses by default the json file produced by simplecov but, with this gem, we can filter the file to show code coverage related to our changes.
2) It shows a code coverage report on screen.
Installation
- Install reviewdog
brew install reviewdog/tap/reviewdog
You can avoid this step and
git status
will be used to filter results instead.
- Install VSCode SimpleCov plugin
You need to configure SimpleCovLinterFormatter.json_filename = '.resultset.json'
to use the extension's default configuration.
If you want yo keep the .resultset.json
file intact you must change the plugin's "Path" option to point another file.
Add to your Gemfile:
gem 'simplecov' gem 'simplecov_linter_formatter'
bundle install
Usage
Add the formatter to your spec/spec_helper.rb
.
require 'simplecov'
require 'simplecov_linter_formatter'
SimpleCovLinterFormatter.setup do |config|
config.json_filename = '.resultset.json'
config.scope = :all
end
SimpleCov.start 'rails' do
# ...
formatter SimpleCov::Formatter::MultiFormatter.new(
[
SimpleCov::Formatter::LinterFormatter,
SimpleCov::Formatter::HTMLFormatter
]
)
end
If you configure SimpleCovLinterFormatter.scope = :own_changes
instead of :all
you will see coverage warnings related to your changes only (it uses git diff
).
Summary Report
- Turn on the on screen report with option:
SimpleCovLinterFormatter.summary_enabled = true
Scope variation will affect the report:
SimpleCovLinterFormatter.scope = :all
SimpleCovLinterFormatter.scope = :own_changes
Sort by
:alphabet
or, the default,:coverage
option withSimpleCovLinterFormatter.summary_files_sorting = :alphabet
Change the look of the report:
- Turn off the background with
SimpleCovLinterFormatter.summary_enabled_bg = false
- Change colors:
SimpleCovLinterFormatter.setup do |config| config.summary_enabled_bg = true # you need enabled background config.summary_covered_bg_color = :lightblue config.summary_not_covered_bg_color = :pink config.summary_text_color = :black end
- Turn off the background with
Testing
To run the specs you need to execute, in the root path of the gem, the following command:
bundle exec guard
You need to put all your tests in the /simplecov_linter_formatter/spec/
directory.
Publishing
On master/main branch...
- Change
VERSION
inlib/simplecov_linter_formatter/version.rb
. - Change
Unreleased
title to current version inCHANGELOG.md
. - Run
bundle install
. - Commit new release. For example:
Releasing v0.1.0
. - Create tag. For example:
git tag v0.1.0
. - Push tag. For example:
git push origin v0.1.0
.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Credits
Thank you contributors!
SimpleCov Linter Formatter is maintained by platanus.
License
SimpleCov Linter Formatter is © 2021 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.