openpharma / roxylint

Lint 'roxygen2'-generated documentation
https://openpharma.github.io/roxylint
Other
17 stars 0 forks source link

Discussion: Syntax for controlling mixing of linter sources #1

Open dgkf opened 1 year ago

dgkf commented 1 year ago

This is one of the more complex behaviors of the package. I'll start with background. There are a number of ways that linters can be added:

  1. roxylint provides its own default linters (that follow the tidyverse style guide for documentation).
  2. Other packages (eg roxytypes) can register linters as well. They'll be registered when they load or when roxytypes loads (if it wasn't already loaded)
  3. Users may define their own linters.

So, given a tag (let's say @param), there might be some default value, some additional linters provided by other packages, and some user-defined linters.

With this, a user should be able to specify whether they want to add to or overwrite existing linters, and assert that new linters should or shouldn't be allowed on top of the ones they've defined.

For now, providing a linter always overwrites existing linters and NULL is used as a sentinel value that says "do not allow more linters for this tag".

However, this isn't very pretty, is a bit unintuitive, and does not provide the ability to add to existing linters. Instead, we might imagine a special constructor:

list(
  linters = list(
    param = roxytypes::linters(mask = FALSE, lock = FALSE,
      function(x, name, description, ...) {
        n_caps <- nchar(gsub("[^[:upper:]]", "", description))
        if (n_caps < nchar(description) / 2)
          warning("descriptions should be at least 50% CaPiTALiZeD")
      }
    )
  )
)
danielinteractive commented 1 year ago

Yeah special constructor also works well I guess. Maybe in general, I wonder how much you could lean on the lintr package for semantics and syntax to simplify learning curve for users.

dgkf commented 1 year ago

A couple thoughts inspired by the lintr comparison

danielinteractive commented 1 year ago

Thanks @dgkf yeah that looks nice! Yes .R is better.