Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joaopmatias opened this issue Dec 15, 2019 · 5 comments · Fixed by #539
Closed

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

joaopmatias opened this issue Dec 15, 2019 · 5 comments · Fixed by #539
Labels
feature a feature request or enhancement

Comments

@joaopmatias
Copy link

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

@russHyde
Copy link
Collaborator

Could you post an example .lintr file, please

@joaopmatias
Copy link
Author

joaopmatias commented Dec 16, 2019

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")

@russHyde
Copy link
Collaborator

russHyde commented Dec 16, 2019

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()

@russHyde
Copy link
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

@joaopmatias
Copy link
Author

joaopmatias commented Dec 16, 2019

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.

russHyde added a commit to russHyde/lintr that referenced this issue Dec 16, 2019
`read_settings` was modified: when it is passed a directory, any
excluded files that are specified in a user config are now specified
relative to the directory (eg, the package root), rather relative to the
current working directory
@russHyde russHyde added the feature a feature request or enhancement label Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
2 participants