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

Remove empty lines between roxygen docs and code? #936

Open
IndrajeetPatil opened this issue Mar 28, 2022 · 3 comments
Open

Remove empty lines between roxygen docs and code? #936

IndrajeetPatil opened this issue Mar 28, 2022 · 3 comments

Comments

@IndrajeetPatil
Copy link
Collaborator

AFAIK, there are currently no guidelines about this in the tidyverse style guide, but I was wondering if {styler} should adopt a convention to remove empty lines between roxygen documentation and the code.

  • Actual

In the wild, I often come across codebases that have formatting like the following. The count of empty spurious lines may differ across files. Currently, {styler} preserves such empty lines.

styler::style_text(
  "#' @export
  


  foo <- function() NULL"
)
#> #' @export
#> 
#> 
#> 
#> foo <- function() NULL
  • Expected new behavior

I wish {styler} could remove such inconsistencies and adopt a single rule. I'd propose that it removes all empty lines by default, but I am also open to other rules (e.g. always have a single empty line). The point is more about consistency in formatting.

#> #' @export
#> foo <- function() NULL
  • Exception

Just like in formatting R6 lists, I think one exception to this rule could be the presence of a comment block before the function. In such cases, a single empty line can be preserved.

styler::style_text(
  "#' @export
  
  # bla bla bla
  foo <- function() NULL"
)
#> #' @export
#> 
#> # bla bla bla
#> foo <- function() NULL

Curious to hear what you think.

@MichaelChirico
Copy link
Contributor

I see this a lot too and regular favor styler removing it by default . I think of it like trailing_blank_lines_linter for roxygen blocks

@lorenzwalthert
Copy link
Collaborator

I agree we could remove blank lines after #'. This could be a new transformer in R/rules-line-break.R, and it could be off for strict = FALSE. @IndrajeetPatil interested in a PR? I can provide guidance. You can see how rules were added previously, e.g. https://github.com/r-lib/styler/pull/569/files.

@IndrajeetPatil
Copy link
Collaborator Author

@IndrajeetPatil interested in a PR? I can provide guidance.

Let me give this a try! And, yes, I will definitely need your guidance 🙃

You can see how rules were added previously, e.g. https://github.com/r-lib/styler/pull/569/files

That's a good starting point. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants