Document formatting ensures trailing empty line#509
Document formatting ensures trailing empty line#509renkun-ken merged 1 commit intoREditorSupport:masterfrom
Conversation
|
I read this as if the last line is not empty, add one (if ensure_last_n_empty <- function(x, n = 1) {
if (all(x == "")) {
return("")
}
x <- c(x, "", "")
x <- x[seq(1, length(x) - which(rev(x) != "")[1] + 1L)]
c(x, rep("", n))
}styler:::ensure_last_n_empty("hi")
#> [1] "hi" ""
styler:::ensure_last_n_empty(c("hi", ""))
#> [1] "hi" ""
styler:::ensure_last_n_empty(c("hi", "", ""))
#> [1] "hi" ""Created on 2021-12-28 by the reprex package (v2.0.1) |
|
Thanks for pointing to The current release does not remove any trailing empty lines, and the latest dev removes all trailing empty lines. I think it might make some sense to leave it to styler to determine whether it is appropriate to remove all trailing empty lines? Looks like it should be subject to user preference and should be customizable via styler some how, if possible. On languageserver side, we only need to ensure there is at least a trailing empty line to make things work (e.g. |
|
Ok, makes sense. {styler} dev does remove these additional lines, so with the next CRAN release, people will have this functionality anyways. Thanks for looking into it @renkun-ken, appreciate it that you help fix a problem that is fundamentally not a {languageserver}, but a {styler} problem. 👍 |
Closes #462
In document formatting, a trailing new line is ensured in the end of the new text.