Skip to content

Support excluding entire directories #539

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

Merged
merged 23 commits into from
Nov 26, 2020
Merged

Support excluding entire directories #539

merged 23 commits into from
Nov 26, 2020

Conversation

AshesITR
Copy link
Collaborator

@AshesITR AshesITR commented Oct 21, 2020

fixes #518
fixes #438

  • implement
  • test
  • document

The current solution is a bit inefficient since you could technically avoid listing the ignored directory.
Instead, we add full file exclusions for all files in the directories.

@AshesITR AshesITR requested a review from jimhester as a code owner October 21, 2020 19:18
@AshesITR
Copy link
Collaborator Author

also needed to fix #438 for the .lintr config file based test case to succeed.

@AshesITR
Copy link
Collaborator Author

cc @russHyde @jimhester My hacky fix to #438 isn't quite as nice as #439 (currently not merged)
Do you have a preference regarding the approach to relative exclusions?

The approach in this PR is to temporarily setwd() in the only place where a directory prefix is necessary and set it back on.exit, namely when reading settings. #439 instead introduces a new argument to normalize_exclusions() to carry the path information.

We could also merge #439 first but its diff is kind of large at a quick glance.

@russHyde
Copy link
Collaborator

Hi @AshesITR , I've been quiet on the lintr front for 6 months (job & family reasons). I never actually finished #439 ; my changeset was pretty large to begin with, and a collaborator pushed some additional changes onto my fork of lintr; so the changeset got really large. I'd like to split it into smaller chunks so that it's more easy to review, but I'm not sure where to start.

I'll try to look over your changes in the coming week (haven't looked at them yet), but would urge against using setwd in lintr (& any CRAN-targetted code). Thanks for looking into directory exclusions, to be able to drop directories from the config would be really valuable.

@AshesITR
Copy link
Collaborator Author

AshesITR commented Oct 26, 2020

A rebase to master caused some unexpected diffs...

Thanks @russHyde for the feedback so far - I've removed the call to setwd() instead conditionally adding root to the file path if it's not already an absolute path.


Edit: I've created a squashed rebase commit f29437a.
That contains all the changes specific to this PR

fixes #438 as well as a few unrelated test failures on non-english locales (temporary calls to Sys.setenv(LANGUAGE = "en") for all tests related to vanilla (translated) R error messages)

always normalize exclusions in lint_dir
normalize exclusions in read_settings wrt .lintr file location
fix tests with language-dependent error messages
adapt tests to new settings behaviour
fix cache operations forcing read_settings
 - this caused test failures for exclusions.
   Previously, the incorrect normalization of exclusions let the tests
   pass because the files weren't matched to their exclusion entries
   in .lintr but now they do and care needs to be taken not to call
   read_settings() which would load the exclusions from lintr/.lintr
…rate error

make sure entire file exclusions properly apply to Windows as well
(otherwise .lintr wouldn't be respected for the offending file on Windows)
@AshesITR AshesITR changed the title [WIP] support excluding entire directories Support excluding entire directories Nov 1, 2020
@AshesITR AshesITR requested a review from russHyde November 3, 2020 21:08
Copy link
Collaborator

@russHyde russHyde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, and for requesting my review. I like how you approached excluding directories. I've requested a couple of changes.

I started a PR that aimed to address the relative-path exclusions issue in #438. I'd like to check whether the tests that were written for that PR are all adressed in this PR before continuing.

@AshesITR
Copy link
Collaborator Author

AshesITR commented Nov 6, 2020

Thank you @russHyde for taking the time to do a review.
I stole some files from your PR - I hope you don't mind.

# These packages should not have a .lintr file: Hardcoding a .lintr in a
# dummy package throws problems during `R CMD check` (they are flagged as
# hidden files, but can't be added to RBuildIgnore since they should be
# available during `R CMD check` tests)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a side note: Couldn't we override the options(lintr.linter_file = "test_dot_lintr") to overcome R CMD check warnings about hidden files?

@AshesITR AshesITR requested a review from russHyde November 6, 2020 19:10
@AshesITR AshesITR dismissed russHyde’s stale review November 6, 2020 22:10

Incorporated all suggestions

@AshesITR
Copy link
Collaborator Author

@russHyde do you have the time for another round of review?

@russHyde
Copy link
Collaborator

Okay. I'll look at it today

@russHyde
Copy link
Collaborator

russHyde commented Nov 23, 2020

In it's current form, with a dummy package in "tests/testthat/package", if you run the following from the lintr root, the vignettes subdirectory is not excluded from linting:

lint_package("tests/testthat/package", exclusions = "tests/testthat/package/vignettes")

And, on setwding to the package root, and running:

lint_package(exclusions = "vignettes") // or lint_package(".", exclusions = "vignettes")

an error comes up: "Error in normalize_exclusions(c(exclusions, settings$exclusions), root = path, : object 'pattern' not found"

But, when a ".lintr" file is added into the "package" root with exclusions: "vignettes", the vignettes are excluded from linting.

Although the current PR does a good job of ensuring that directories are excluded when specified in the .lintr config, it doesn't appear to handle directory-exclusions that are passed via the exclusions = "..." arguments. This was an issue that meant my original PR for handling relative filepaths got really large.

I am happy for this PR to be merged, provided that you explicitly say that it handles directory exclusions that are specified in the .lintr config. If you do this, can you open a new issue about supporting directory exclusions via the "exclusions" argument to the lint_*() functions. (Maybe have a look at how @joaopmatias handled it in the unmerged russHyde#2 )

add parse_settings to lint_package() mainly for tests (suppressing global .lintr config exclusions)
@AshesITR
Copy link
Collaborator Author

Thanks @russHyde
I've moved the package.

The current behaviour in this PR would be that exclusions is always relative to the project root (so your example should do exclusions = "vignettes" from outside as well).

It's not hard to change this. What do you prefer?

@russHyde
Copy link
Collaborator

I'd really rather that that was done in a separate PR. We'd have to discuss whether files in ..., exclusions=..., are specified relative to the (possibly unspecified) project root, the (possibly absent) .lintr, the current directory, the targetted directory.

When exclusions are specified within the .lintr it seems a lot simpler: files should be specified relative to the directory containing the .lintr file or as full-paths.

@AshesITR
Copy link
Collaborator Author

Sounds good. Then this PR is done as far as I can tell.

@AshesITR
Copy link
Collaborator Author

ping @russHyde travis build is finally complete

Copy link
Collaborator

@russHyde russHyde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor changes. Happy to merge this without CI if these are addressed.

@AshesITR
Copy link
Collaborator Author

@russHyde thanks for taking all the time to review this thoroughly.
I think we can merge now.

@AshesITR AshesITR mentioned this pull request Nov 25, 2020
Copy link
Collaborator

@russHyde russHyde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@russHyde
Copy link
Collaborator

Feel free to merge whenever. Many thanks for your hard work on this issue.

@AshesITR AshesITR merged commit f955476 into r-lib:master Nov 26, 2020
@AshesITR AshesITR deleted the feature/ignore-dirs branch November 26, 2020 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow exclusion of directories Exclusions read from .lintr are depedent of the current working directory
2 participants