Skip to content

Support multiple .lintr files in nested directories? #1976

Open

Description

@MichaelChirico

I would like to apply different linter configs to different directories.

In particular, I would turn off quotes_linter() in my tests/ directory, but use quotes_linter("'") in the rest of the package. " can be particularly good for tests where we might compare to dput() output, and dput uses ".

./             # package TLD
./.lintr       # has linters: linters_with_defaults(quotes_linter('"'))
./tests/.lintr # has linters: linters_with_defaults(quotes_linter('"'))

AFAICT this doesn't work, and only the top-level config applies.

Activity

  1. added
    feature
    on Jun 25, 2023
  2. AshesITR commented on Jul 1, 2023

    @AshesITR
    Collaborator

    This is due to the parse_settigs = FALSE argument passed from lint_package() and lint_dir() respectively.
    If we want to be smart about the config detection, we probably need to instead track the absolute path of the currently active settings and check during each call to lint() if we need to reload the settings.

    If we do that, we should

    1. upgrade our error messages related to settings so that the path to the config file is also provided
    2. think about what to do with the argument parse_settings if a user provides it.
  3. MichaelChirico commented on Oct 23, 2023

    @MichaelChirico
    CollaboratorAuthor

    Another use case:

    I'd like to run undesirable_function_linter(c(sapply = NA)) in package code (R directory), but think it's fine to use sapply() in vignettes. Currently the way to do this is:

    linters: list(undesirable_function_linter(c(sapply = NA)))
    exclusions: list(vignettes = list(undesirable_function_linter = Inf))
    

    But that's not flexible enough -- if we want to mark any other functions as undesirable, the exclusions entry will also be disabled in the vignettes directory.

    The two improvements that come to mind here are:

    1. Support some way in .lintr to mess with the parameterization of the linter that's run
    2. Allow keeping a .lintr config in the vignettes directory

    Of those the latter seems much more promising.

  4. AshesITR commented on Oct 23, 2023

    @AshesITR
    Collaborator

    Regarding your use case: You can define two undesirable_function_linter()s with separate names and exclude only one of them in vignettes.

    linters: list(
      fun_linter = undesirable_function_linter(c(sapply = "Use vapply")),
      global_fun_linter = undesirable_function_linter(Sys.setenv = NA)
     )
    exclusions: list(
      vignettes = list(fun_linter = Inf)
     )
  5. MichaelChirico commented on Oct 23, 2023

    @MichaelChirico
    CollaboratorAuthor

    Nice idea! The only downside there is mental overload of having to remember the renamed linter. Easy for two new linters but trickier if we have dozens of undesirable functions.

  6. AshesITR commented on Oct 23, 2023

    @AshesITR
    Collaborator

    At least the linter name appears in the lint message so ex post you don't have to know the linter name, but I see what you mean.
    Another issue with this is if you wanted to only lint some things in a specific directory, the exclusions would get quite big.

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

    configfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions