lintr
lintr copied to clipboard
trailing_blank_lines_linter for individual Rmd chunks?
writeLines("
```{r code}
some_code
```
```{r code_2}
more_code
```
", tmp <- tempfile(fileext = ".Rmd"))
lintr::lint(tmp, lintr::trailing_blank_lines_linter())
Shouldn't we be linting all of those blank lines at the end of the first chunk as well?
Definitely, these should be linted.
Thankfully, simply running {styler}
should help clean up these lints.
tmp <- tempfile(fileext = ".Rmd")
cat(file = tmp, "
```{r chunk}
x <- 1
```
")
writeLines(readLines(tmp))
#> ```{r chunk}
#> x <- 1
#>
#>
#>
#> ```
styler::style_file(tmp)
#> Styling 1 files:
#> /var/folders/xr/v_vddzvs33q5wg7jv9mr__4h0000gn/T//RtmpKRn4HF/file7f5c2cf055dd.Rmd ℹ
#> ────────────────────────────────────────────────────────────────────────────────
#> Status Count Legend
#> ✔ 0 File unchanged.
#> ℹ 1 File changed.
#> ✖ 0 Styling threw an error.
#> ────────────────────────────────────────────────────────────────────────────────
#> Please review the changes carefully!
writeLines(readLines(tmp))
#>
#> ```{r chunk}
#> x <- 1
#> ```
Created on 2022-10-04 with reprex v2.0.2
Actually, this already works! I guess it's just a matter of adding tests?
library(lintr)
tmp <- tempfile(fileext = ".Rmd")
cat(
file = tmp,
"```{r chunk}
x <- 1
```"
)
lint(tmp, linters = trailing_blank_lines_linter())
#> /private/var/folders/xr/v_vddzvs33q5wg7jv9mr__4h0000gn/T/Rtmp6B4mcl/file88023cfc3d1d.Rmd:3:1: style: [trailing_blank_lines_linter] Trailing blank lines are superfluous.
#>
#> ^
#> /private/var/folders/xr/v_vddzvs33q5wg7jv9mr__4h0000gn/T/Rtmp6B4mcl/file88023cfc3d1d.Rmd:4:1: style: [trailing_blank_lines_linter] Trailing blank lines are superfluous.
#>
#> ^
#> /private/var/folders/xr/v_vddzvs33q5wg7jv9mr__4h0000gn/T/Rtmp6B4mcl/file88023cfc3d1d.Rmd:5:1: style: [trailing_blank_lines_linter] Trailing blank lines are superfluous.
#>
#> ^
#> /private/var/folders/xr/v_vddzvs33q5wg7jv9mr__4h0000gn/T/Rtmp6B4mcl/file88023cfc3d1d.Rmd:6:1: style: [trailing_blank_lines_linter] Missing terminal newline.
#> NA
#> ^
Created on 2022-10-04 with reprex v2.0.2
the issue is referring to when internal chunks have trailing blank lines, say chunk 2 out of 3
I am not sure if I still get it. 😢
In your example code, are you referring to these blank lines?

no, but your example works. chunk 1 has trailing blank lines after some code
, chunk 2 does not