Skip to content

Consider prism in coverage results #2079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Earlopain
Copy link
Contributor

In #2077, I want to add prism-only logic that won't be executed by the parser gem. Coverage complains, because it thinks some code is unreachable.

This PR fixes this by making a few changes to CI, with the goal to merge the coverage results so it can get back to 100%.

I made the following changes:

  • Move internal_investigation out of the matrix and run it only once. internal_investigtion is not really for catching rubocop-rspec errors, there's the test suite for that. So running it only once is ok (I made the same change in rubocop a while ago). Doing this simplifies merging since only a single task is executed.
  • Move prism to the main workflow. There's nothing that needs to be considered separately anymore, rubocop-ast pulls prism in. Also simplifies merging coverage
  • Add a new rake task to merge coverage results. These are uploaded per each matrix job, and when all is done a separate job merges them and checks for coverage drops etc.

If this is merged, I can rebase #2077 and CI should be green there. I tested this locally with coverage results from the different parser engines and it reports 100% coverage after merging and behaves like I would expect it to.

Makes it so that the main matrix only runs a single task
rubocop-ast depends on prism, so no need to add it to the gemfile anymore
@Earlopain Earlopain requested a review from a team as a code owner April 14, 2025 10:53
@Earlopain Earlopain force-pushed the prism-coverage-merge branch 2 times, most recently from 60a5c3e to 11b6f48 Compare April 14, 2025 11:22
with:
ruby-version: ruby # Latest stable CRuby version
bundler-cache: true
- run: NO_COVERAGE=true bundle exec rake internal_investigation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal investigation shouldn't be bothered by NO_COVERAGE, or why is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I had this from the main job where I extracted this from. Will remove

- run: bundle exec rake spec
env:
PARSER_ENGINE: ${{ matrix.parser_engine }}
- name: Upload Coverage Artifact
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're quite fine if it just fails.
Also, it's fine if it runs for just one Ruby version, which is done below in the "coverage" job (line 50)

@rubocop/rubocop-rspec WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're quite fine if it just fails.

Yeah, I can do that. if-no-files-found was a bit nice during debuging but not really necessary anymore (plus jruby kinda needs that, or something similar)

- parser_whitequark
include:
- ruby: "2.7" # Minimum version required for Prism to run.
parser_engine: parser_prism
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/rubocop/rubocop/blob/d8448a3790a78f16536e267ed7ea5ffc2e03561b/docs/modules/ROOT/pages/compatibility.adoc#L44

Starting from RuboCop 1.75, the prism translation layer is used by default when analyzing Ruby 3.4+.

What is the point for us to run this job on 2.7, and tell the Prism to analyze the code as it was Ruby 3.4? Don't we have those 3.4-specific (eg it-block) specs disabled when running on Ruby 2.7?

Is it just my OCD, or we need two Prism jobs, one on 2.7, to ensure it runs on older rubies, and one on 3.4, to ensure cops do what we expect them to, including new features, with Prism?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point for us to run this job on 2.7, and tell the Prism to analyze the code as it was Ruby 3.4?

It's just the ruby version that it is being run on. So even with a runtime of Ruby 2.7 it will analyze it as syntax from those ruby versions like parser would do it (in practise it will "upgrade" 2.7 and other versions it can't anaylze to 3.3, which is the lowest ruby version that prism understands)

Is it just my OCD, or we need two Prism jobs, one on 2.7, to ensure it runs on older rubies, and one on 3.4, to ensure cops do what we expect them to, including new features, with Prism?

It's the lowest to not accidentally use newer ruby features like you mentioned. It will still analyze such newer ruby versions even with a lower runtime ruby.

task :ci do
require 'simplecov'

SimpleCov.collate Dir['coverage-*/.resultset.json']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this combine results from different Ruby versions, and Parser results with Prism results?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Different ruby versions aren't really needed since it will be at 100% with just two jobs right now (one prism, one parser) but limiting it in the workflow adds complexity which I don't think is really needed.

Just doing it will all runs seems ok to me for simplicity.

parser and prism will differ in what they do,
so merge them together.

jruby doesn't seem to support coverage (maybe jruby bug?):
> KeyError: key not found: :branch
@Earlopain Earlopain force-pushed the prism-coverage-merge branch from 11b6f48 to 4f91894 Compare April 14, 2025 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants