-
Notifications
You must be signed in to change notification settings - Fork 73
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
Work around empty example lines #1085
Conversation
Output has changed for two existing tests, but I believe the new behavior is correct. Empty lines and comments inside examples are a hassle, would it be a big stretch if we ignored such examples entirely (except when last lines are empty)? |
Codecov Report
@@ Coverage Diff @@
## main #1085 +/- ##
=======================================
Coverage 91.10% 91.10%
=======================================
Files 46 46
Lines 2698 2699 +1
=======================================
+ Hits 2458 2459 +1
Misses 240 240
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 93914e4 is merged into main:
Further explanation regarding interpretation and methodology can be found in the documentation. |
I think I don't think styler should remove blank lines here. #' @export
#' @examples
#' a + b
#'
#' # here I put a comment
#' 2 + 1
#'
NULL
Why should the styling of previousl lines depend on the last lines being empty? And are you referring to a line in the examples (like |
I'm referring to the following case: #' @export
#' @examples
#' a + b
#'
# here I put a comment
#' 2 + 1
#'
NULL What should we do with that comment? Perhaps a warning 😱 that we can't process this, with accurate file+line information? |
Yeah, this is definitely a tricky case. The clearest usage of regular comments I can see with the Roxygen blocks is to add annotations to ignore some code from being styled. For example, if I have a few examples in the docs, maybe I want some to be styled, while others not because I have custom formatting (example in the wild). For example: "#' @export
#' @examples
#'
#' # example code I want styled
#' x = 1
#' y = 2
#'
#example code I want styler to skip to preserve alignment
# styler: off
#' a = 1
#' ab = 2
#' abc = 3
#styler: on
NULL" -> code
styler::style_text(code)
#> #' @export
#> #' @examples
#> #'
#> #' # example code I want styled
#> #' x <- 1
#> #' y <- 2
#> #'
#> # example code I want styler to skip to preserve alignment
#> # styler: off
#> #' a = 1
#> #' ab = 2
#> #' abc = 3
#> # styler: on
#> NULL Created on 2022-12-27 with reprex v2.0.2 As can be seen, currently, IINM, if we stop processing the embedded comments, we will stop supporting this use case, right? |
Closes #1084.