-
Notifications
You must be signed in to change notification settings - Fork 71
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
preserve initial newlines when styling file? #1224
Comments
I guess a similar question might apply to newlines before and after braces; it looks like |
I am curious as to why you would like to preserve these empty lines? Also, just at the start or also at the end? Note that (latest-main-)styler will remove blank lines both at the start and end of a scope: "f <- function() {
x <- 1L
}" -> code
styler::style_text(code)
#> f <- function() {
#> x <- 1L
#> } Created on 2024-07-25 with reprex v2.1.1 The reason it doesn't get rid of blank lines inside the scope is because it is difficult to know if they are intentional or unintentional. E.g. Intentional: Users wish to visually distinguish lines of code achieving different subgoals by separating blocks of code with empty lines. clean_data <- function() {
# subgoal-1: check for missing data
...
# deliberate empty lines
# subgoal-2: remove duplicates
...
# deliberate empty lines
# etc.
} The situation is less uncertain for the blank lines at the start and the end, since they are often leftovers either from removal of code, accidental enters, etc., and less likely to be deliberate. But their unchecked presence can visually distort the structure of a program, and, therefore, we believe, it's better to get rid of them. If you really wish to preserve these lines, you could remove corresponding rules when you use |
For example:
This gives:
What do you think about preserving the leading newlines in the file? (I don't think the tidyverse style guide has any recommendations here, but I could be wrong.)
The text was updated successfully, but these errors were encountered: