Skip to content

Exclusions read from .lintr are depedent of the current working directory #438

Closed

Description

@joaopmatias

Hi, I recently started using lintr and it's pretty great. Thank you to everyone involved!

I bumped into an issue related with the exclusions extracted from .lintr files. It seems that the lint report depends on the current working directory of the R console.

Running the following script while the working directory was in the root of the project (lintr/)

> lint_package(".")

does not show inst/example/bad.R in the report (since it's path is in .lintr). Then, if I run

> setwd("..")
> lint_package("lintr")

the file inst/example/bad.R shows in the report.

There is a similar issue with lint(). I added a file lintr/inst/example/.lintr with the content

exclusions: list("bad.R")

Then, I ran the commands

> setwd("lintr/inst/example")
> lint("bad.R")

and bad.R did not show up in the report (as expected). However, that was not the case when I ran

> setwd("..")
> lint("example/bad.R")

Furthermore, when run directly from the console, it seems that lint_dir() always ignores the exclusions in .lintr.

Can you clarify if any of these contrasting behaviors are expected, or what the expected behaviors should be?

Thank you
João

Activity

  1. russHyde commented on Dec 16, 2019

    @russHyde
    Collaborator

    Could you post an example .lintr file, please

  2. joaopmatias commented on Dec 16, 2019

    @joaopmatias
    Author

    I'm using the code from master in the commands shown above, so the .lintr file is

    linters: with_defaults(line_length_linter(120))
    exclusions: list("inst/doc/creating_linters.R" = 1, "inst/example/bad.R", "tests/testthat/exclusions-test")
  3. russHyde commented on Dec 16, 2019

    @russHyde
    Collaborator

    Just seen this as well.
    Seems to relate to read_settings

    # in /path/to/lintr
    # mimicking the code in `lint_package()`
    path <- lintr:::find_package(".")
    lintr:::read_settings(path)
    lintr:::settings$exclusions
    $`<HOME>/progs/pull_requests/lintr/inst/example/bad.R`
    [1] Inf
    
    $`<HOME>/progs/pull_requests/lintr/tests/testthat/exclusions-test`
    [1] Inf
    
    # In parent of lintr directory (<HOME>/progs/pull_requests/)
    path <- lintr:::find_package("lintr")
    lintr:::read_settings(path)
    lintr:::settings$exclusions
    named list()
    
  4. russHyde commented on Dec 16, 2019

    @russHyde
    Collaborator

    All calls to read_settings come from lint.R or cache.R; when called from lint.R either a single filename (from lint) or a directory path (from lint_dir or lint_package) is passed in. So we should be able to modify read_settings, appending the (assumed relative) filepaths from exclusions onto the dir-path whenever the input to read_settings is a directory

  5. joaopmatias commented on Dec 16, 2019

    @joaopmatias
    Author

    I noticed that in both read_settings and the functions in lint.R, the exclusions always pass by the function normalize_exclusions.
    This function gives the absolute paths for a list of files paths and removes non-existing files. I think that the issue is that it searches for the files paths relative to the working directory and not relatively to the path given in the input of a lint function.

    I think that the issue won't be solved just by changing read_settings but it's a good point to start.

  6. added a commit that references this issue on Dec 16, 2019
    f8157c2
  7. added
    feature
    on Jan 6, 2020
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

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions