Skip to content

Commit 240a2dd

Browse files
only add line break at EOF if there is not one already. Closes #311.
1 parent e43ec5b commit 240a2dd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

R/addins.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ style_active_file <- function() {
3333
}
3434
rstudioapi::modifyRange(
3535
c(1, 1, length(context$contents) + 1, 1),
36-
paste0(append(out, ""), collapse = "\n"),
36+
paste0(ensure_last_is_empty(out), collapse = "\n"),
3737
id = context$id
3838
)
3939
if (Sys.getenv("save_after_styling") == TRUE && context$path != "") {

R/utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ line_col_names <- function() {
44
c("line1", "line2", "col1", "col2")
55
}
66

7+
ensure_last_is_empty <- function(x) {
8+
has_line_break_at_eof <- x[length(x)] == ""
9+
if (has_line_break_at_eof) {
10+
return(x)
11+
} else {
12+
append(x, "")
13+
}
14+
}
15+
716
#' Check whether two columns match
817
#'
918
#' @param col1,col2 Column names as string.

0 commit comments

Comments
 (0)