Skip to content

Using a nolint= chunk option for Rmd #773

@MichaelChirico

Description

@MichaelChirico

Currently, if we want to skip linting certain lines in an Rmd file, we have two options (IIUC):

  1. Include # nolint or # nolint start / # nolint end in the code just like for .R scripts. This is somewhat awkward for .Rmd because .Rmd are especially made for reading, and readers are likely to be confused by these tags that have nothing to do with the tutorial (e.g.) per se.

  2. Include invisible chunks starting/stopping nolint ranges "behind the scenes", e.g.

    ```{r nolint_start, echo = FALSE}
    # nolint start: assignment_linter.
    ```
    
    ```{r regular_chunk, ...}
    x = 4
    ```
    
    ```{r nolint_stop, echo = FALSE}
    # nolint end: assignment_linter.
    ```
    

This is also far from ideal and pretty limiting. It's OK for hiding whole files, but impractical for excluding small portions of code, as well as hugely increasing the amount of clutter in the source.

A good workaround IMO would be for lintr to understand an Rmd chunk option, e.g. nolint = :

```{r regular_chunk, ..., nolint = TRUE}
x = 4
```

I propose the following API for this option:

  • nolint = TRUE: exclude the chunk from linting
  • nolint = integer(n): exclude the lines listed in nolint, given relative to the chunk (similar to eval, but we use lines instead of expressions)
  • nolint = list(linter1 = TRUE || integer(n1), ..., linterk = TRUE || integer(nk)): linter-specific exclusions are given via named elements of a list, with the list elements' values being used just like one of the first two options

This should be a no-op from knitr's perspective and still analyzed statically, so e.g. knitr::opts_chunk is not a valid way to set this "pseudo-chunk option".

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementrmd

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions