Skip to content

trailing_blank_lines_linter for individual Rmd chunks? #741

Open

Description

@MichaelChirico
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?

Activity

  1. added
    feature
    on Feb 8, 2021
  2. IndrajeetPatil commented on Oct 4, 2022

    @IndrajeetPatil
    Contributor

    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

  3. IndrajeetPatil commented on Oct 4, 2022

    @IndrajeetPatil
    Contributor

    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

  4. added a commit that references this issue on Oct 4, 2022
    acc646a
  5. MichaelChirico commented on Oct 4, 2022

    @MichaelChirico
    CollaboratorAuthor

    the issue is referring to when internal chunks have trailing blank lines, say chunk 2 out of 3

  6. IndrajeetPatil commented on Oct 4, 2022

    @IndrajeetPatil
    Contributor

    I am not sure if I still get it. 😢

    In your example code, are you referring to these blank lines?

    Screenshot 2022-10-04 at 17 47 56

  7. MichaelChirico commented on Oct 4, 2022

    @MichaelChirico
    CollaboratorAuthor

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

  8. added a commit that references this issue on Jan 8, 2025
    a6254c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurermd

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions