Skip to content
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

Add parsable-roxygen hook #563

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

Conversation

owenjonesuob
Copy link

As discussed in #562.

Things to note:

  • Since roxygen2::parse_file() does actually parse the file, I think we have to allow this hook to fail in two ways:
    • If it catches a warning, it fails and explains that it's due to a roxygen error
    • If it catches an error, it fails in the same way as parsable-R
  • I don't think we need to actually evaluate the code though, hence roxygen2::parse_file(..., env = NULL) - unless you can think of some reason why we would need to evaluate?
  • Do we need to do anything to ensure that {roxygen2} is available?

Closes #562.

@lorenzwalthert
Copy link
Owner

Sorry @owenjonesuob for the delay. Here's my review:

If it catches a warning, it fails and explains that it's due to a roxygen error.

Can you tell me when a warning would be issued? Depending on that, maybe a flag --allow-warnings could govern the behaviour of whether or not a warning is elevated to an error. If unset, warnings are errors, as you suggest.

I don't think we need to actually evaluate the code though,

What speaks against it? Is it slower? I guess it requires the package to be loadable with pkgload::load_all()? This would imply that development dependencies need to be available. Also, parsing errors in code to be evaluated does not seem to get caught with roxygen2::parse_file('file.R') if I write this to file.R:

#' Initiate a pre-commit config file
#'
#' @param verbose way. `r 1+++++`
my_fun <- function(...) NULL

But roxygen2::roxygenize() afterwards catches the problem and a subsequent roxygen2::parse_file('file.R') as well. Not sure how we can catch this in the first place...

- id: parsable-roxygen
name: parsable-roxygen
description: check if roxygen comments in a .R file are parsable
entry: Rscript /inst/hooks/exported/parsable-roxygen.R
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
entry: Rscript /inst/hooks/exported/parsable-roxygen.R
entry: Rscript inst/hooks/exported/parsable-roxygen.R

This must be a relative path, compare to other hooks.

#' some_function(11)
#'
#' @export
some_function <- function(x) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you make the roxygen comment more minimal here since you want to test is parsing R code?

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.

New hook: parsable-roxygen
2 participants