r-lib / styler

Non-invasive pretty printing of R code
https://styler.r-lib.org
Other
725 stars 72 forks source link

`@examplesIf` sometimes removing `# nolint end` #828

Closed jonkeane closed 3 years ago

jonkeane commented 3 years ago

In some circumstances, styler will delete the line # nolint end after examplesIf. The two critical bits I needed to trigger it are: a %>% in the example and a function definition below. Without either of those I get behavior where the line is either kept as is or transformed into #' # nolint end.


author: jkeane date: 2021-08-03 output: "reprex::reprex\_document" title: drear-kitty_reprex.R

styler::style_text("
# nolint start
#' @examplesIf TRUE
# nolint end
#' df %>% func()
func <- function() NULL
")
#> 
#> # nolint start
#> #' @examplesIf TRUE
#> #' df %>% func()
#> func <- function() NULL

Created on 2021-08-03 by the reprex package (v2.0.0)

lorenzwalthert commented 3 years ago

@jonkeane can you try #830 and tell me if it works for you?

jonkeane commented 3 years ago

Yup, that works! Thanks for the quick turn around on this

lorenzwalthert commented 3 years ago

@jonkeane I am glad {styler} can help you guys out in {arrow}. Let me know if you have further questions or find more bugs 😊. You can also see the third-party integrations that {styler} has, e.g. with pre-commit that your repo is already using. These can also be enforced with https://pre-commit.ci, but R {precommit} is not there yet, so a manual GitHub actions workflow would be needed (like 10 lines of config, can assist here also) . There are also hooks for lintr etc.

jonkeane commented 3 years ago

Thanks for those pointers. The Arrow project has a comment-based system for auto-formatting like this, which we setup styler to be a part of to match that style/workflow that Arrow developers are used to.

I will definitely look in to pre-commits for other projects though!