From 8429c464125dd1bfc36b4902dd7d5ca4f9e0a02d Mon Sep 17 00:00:00 2001 From: Dave Corson-Knowles Date: Sun, 9 Feb 2025 07:30:48 -0800 Subject: [PATCH] Update `CONTRIBUTING.md` to include `Simplecov` --- .github/CONTRIBUTING.md | 45 ++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 56d27053b..8a55ac4a8 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -15,13 +15,13 @@ If you encounter problems or have ideas for improvements or new features, please ## Pull requests 1. Fork the project. -2. Create a feature branch. -3. Make sure to add tests. -4. Make sure the test suite passes (run `rake`). -5. Add a [changelog](https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md) entry. -6. Commit your changes. -7. Push to the branch. -8. Create new Pull Request. +1. Create a feature branch. +1. Make sure to add tests. +1. Make sure the test suite passes (run `rake`). +1. Add a [changelog](https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md) entry. +1. Commit your changes. +1. Push to the branch. +1. Create new Pull Request. ### Spell Checking @@ -51,6 +51,37 @@ We are running [mdformat](https://github.com/executablebooks/mdformat) for forma $ mdformat . --number ``` +### Test Coverage - Line and Branch + +We are using [Simplecov](https://github.com/colszowka/simplecov) to track test coverage. + +It is included and reported when you run `bundle exec rake` or `bundle exec rspec`. + +To view the coverage report, open the `coverage/index.html` file in your browser. + +E.g. on macOS: + +```console +$ open coverage/index.html +``` + +If you have unreachable lines, you can add `# :nocov` around those lines. The code itself or a comment should explain why the line is unreachable. + +Example: + +```ruby +# :nocov: +raise ArgumentError("Unsupported style :#{style}") +# :nocov: +``` + +This can happen for a few reasons, including: + +1. When you handle config with a case statement and there is no else block. +1. When matching with a node pattern even when you handle all cases: all other node types will be excluded before reaching your handler, because the node pattern will not match them. + +You will need full line and branch coverage to merge. This helps detect edge cases and prevent errors. + ## Creating new cops - Document examples of good and bad code in your cop.