Skip to content

unreachable_code_linter carve-out for 'nolint end' should also apply to 'nocov end' #2327

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

Closed
MichaelChirico opened this issue Nov 21, 2023 · 5 comments · Fixed by #2367
Closed
Labels
false-positive code that shouldn't lint, but does

Comments

@MichaelChirico
Copy link
Collaborator

This is currently linted:

# nocov end

@MichaelChirico MichaelChirico added the false-positive code that shouldn't lint, but does label Nov 21, 2023
@AshesITR
Copy link
Collaborator

Maybe allow comments in general?

@MichaelChirico
Copy link
Collaborator Author

I guess optionally, but they're specifically included:

drop_nolint_end_comment <- function(expr) {
is_nolint_end_comment <- xml2::xml_name(expr) == "COMMENT" &
re_matches(xml_text(expr), settings$exclude_end)
expr[!is_nolint_end_comment]
}

Often come across things like

return(x)
# debugging
# print(x)

commented_code_linter() helps a little bit here but TBH that linter is far from a place where I'd apply it to my own code or to code at scale.

@AshesITR
Copy link
Collaborator

I see. Is there a similar way to find what # nocov end is configured to be?

@MichaelChirico
Copy link
Collaborator Author

@AshesITR
Copy link
Collaborator

Looks like we can simply read options():

https://github.com/r-lib/covr/blob/54de614f5c17a42bfaef2c87dbf5723ca701326a/R/exclusions.R#L55-L57

Sweet, and it's a regex too.
Might extend the linter to allow for a comment regex whitelist later? We can default it to nolint end and nocov end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants