Skip to content

Support nocov comment at the end of a line - #1068

Closed
cyberdelia wants to merge 2 commits into
simplecov-ruby:mainfrom
cyberdelia:one-liners
Closed

cyberdelia wants to merge 2 commits into
simplecov-ruby:mainfrom
cyberdelia:one-liners

Conversation

@cyberdelia

@cyberdelia cyberdelia commented Aug 28, 2023 •

Copy link
Copy Markdown

Support nocov comments at the end of a line to mark it as irrelevant, it's a bit less verbose than blocks to ignore some benign things, i.e:

case value
when String
  StringFilter
when Array
  ArrayFilter
else
  raise "Absurd case" # :nocov: 
end

@cyberdelia

cyberdelia commented Aug 29, 2023 •

Copy link
Copy Markdown
Author

Fixed the build failure in #1069.

@cyberdelia

Copy link
Copy Markdown
Author

Freshly rebased!

cc/ @PragTob

@will

will commented Oct 30, 2024

Copy link
Copy Markdown

@amatsuda please consider this pull request

@sferik
sferik force-pushed the main branch 2 times, most recently from 3422349 to 4f8fece Compare April 3, 2026 19:51

@sferik sferik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have a bit of feedback but support this feature overall.

Somewhat related: as we approach a 1.0.0 release, I was considering changing the block syntax to be more explicit. Something like:

case coverage_criterion
when :line   then compute_line
when :branch then compute_branch
when :method then compute_method
else
  # coverage:disable
  raise "Unknown criterion: #{coverage_criterion}"
  # coverage:enable
end

If that was the block syntax, presumably we’d want the inline syntax to match:

case coverage_criterion
when :line   then compute_line
when :branch then compute_branch
when :method then compute_method
else
  raise "Unknown criterion: #{coverage_criterion}" # coverage:disable
end

This seems as good a place as any to debate making this change.

Comment thread lib/simplecov/lines_classifier.rb Resolved
Comment thread lib/simplecov/lines_classifier.rb Resolved
"puts 'Still relevant'",
"# :nocov:",
"puts 'Not relevant till the end'",
"puts 'Not relevant till the end' # :nocov:",

@sferik sferik Apr 4, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would add a separate, focused test for interactions between inline markers and blocks, instead of making this (already complex) test more complex. There are also a few other edge cases worth testing (e.g. inline # :nocov: comment inside a block).

@PragTob

PragTob commented Apr 4, 2026

Copy link
Copy Markdown
Collaborator

@sferik I like the idea of beginning and end comments, makes diagnosis easier 👌

As for one line/in-line comments I can see the appeal but there's a lot of edge cases to consider (as Erik pointed out) and iirc the lines classifier has been a source of performance degradation in the past - those together make me wonder how much of this we need.

The other thing to consider here is how this plays with branch coverage/other coverage types in general.

@sferik

sferik commented Apr 4, 2026 •

Copy link
Copy Markdown
Collaborator

The other thing to consider here is how this plays with branch coverage/other coverage types in general.

Yes. Since #1161 we also now support method coverage, in addition to line and branch coverage.

Perhaps we should have more granular disabling like:

# coverage:disable:line
# coverage:disable:branch
# coverage:disable:method
# coverage:disable (disables all three)

These should work in both block and inline form.

@PragTob What do you think?

PS: I realize we’re bikeshedding the heck out of this PR, which is more narrowly scoped, but—if we’re going to make API changes before the 1.0 release—I want to make sure we get this right.

@PragTob

PragTob commented May 1, 2026

Copy link
Copy Markdown
Collaborator

@sferik yeah, changes live on in the API and for future support so I believe it's worth considering/talking about.

I don't think we need different sub types of coverage disable/enable. The most common use case for coverage disable is "these lines of code do not matter" and I don't think the type of coverage makes a difference there. I should have been more explicit, but the question of how does it play with other types of coverage is mote like:

I'm ignoring one line of code inside a branch - will the branch be counted? I'm ignoring all but one line of code inside a branch - will it be counted? I'm ignoring the condition that causes a branch, will the branch be counted?

I personally think it's fine to say: Undefined behavior, you did this to yourself. If I'd wish for anything, as long as any line inside a branch is not ignored, the branch shouldn't be ignored. But I'm not sure how much code would be needed to support that or in fact not sure what the current behavior is.

But people will complain that it works different from what they imagine :)

@sferik

sferik commented May 4, 2026 •

Copy link
Copy Markdown
Collaborator

I just chatted with @PragTob and we decided on the following comment syntax:

# simplecov:disable line
# simplecov:disable method
# simplecov:disable branch
# simplecov:disable method,branch         <- disables method and branch coverage
# simplecov:disable                       <- disables all three
# simplecov:enable                        <- enables all three
raise "Absurd case" # simplecov:disable   <- just disables this line, no need to re-enable

@sferik

sferik commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Resolved by #1179.

@sferik sferik closed this May 5, 2026
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.

4 participants