You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exclusions read from .lintr are depedent of the current working directory #438
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?
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()
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
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.
Activity
russHyde commentedon Dec 16, 2019
Could you post an example
.lintrfile, pleasejoaopmatias commentedon Dec 16, 2019
I'm using the code from
masterin the commands shown above, so the.lintrfile isrussHyde commentedon Dec 16, 2019
Just seen this as well.
Seems to relate to
read_settingsrussHyde commentedon Dec 16, 2019
All calls to read_settings come from
lint.Rorcache.R; when called fromlint.Reither a single filename (fromlint) or a directory path (fromlint_dirorlint_package) is passed in. So we should be able to modify read_settings, appending the (assumed relative) filepaths fromexclusionsonto the dir-path whenever the input to read_settings is a directoryjoaopmatias commentedon Dec 16, 2019
I noticed that in both
read_settingsand the functions inlint.R, the exclusions always pass by the functionnormalize_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
pathgiven in the input of alintfunction.I think that the issue won't be solved just by changing
read_settingsbut it's a good point to start.fix r-lib#438 - pin exclusions relative to dir/pkg in lint_[package|dir]