Skip to content

Check for .lintr file in extra subdirectory - #1757

Merged
MichaelChirico merged 25 commits into
r-lib:mainfrom
tonyk7440:update_file_algo
May 22, 2023
Merged

MichaelChirico merged 25 commits into
r-lib:mainfrom
tonyk7440:update_file_algo

Conversation

@tonyk7440

Copy link
Copy Markdown
Contributor

Fixes #1746

Added another condition to check for the .lintr file in the .github/linters subdirectory to improve compatibility with Super-Linter.

Let me know if there's anything I missed, happy to update

@AshesITR

Copy link
Copy Markdown
Collaborator

If we consider this, we might also want #460

@AshesITR AshesITR added breaking change ☠️ API change likely to affect existing code and removed breaking change ☠️ API change likely to affect existing code labels Oct 28, 2022
@tonyk7440
tonyk7440 marked this pull request as ready for review October 28, 2022 16:45
@tonyk7440

tonyk7440 commented Oct 28, 2022 •

Copy link
Copy Markdown
Contributor Author

I can see there is a lint error raised for the cyclomatic complexity linter. I'm not sure what would be the best way to resolve. I don't see an obvious way to make the code simpler. I could increase the threshold to be 16 but not sure if that is an advised route.

Hence marking as ready for review

@AshesITR

Copy link
Copy Markdown
Collaborator

While the current search order is non-breaking, it seems very counter-intuitive to give a "global" config at ~/.lintr priority over a local config at .github/linters.

@AshesITR

Copy link
Copy Markdown
Collaborator

Regarding the cyclomatic complexity: You could refactor the existence check into a for loop that returns as soon as one of the candidate files exists.

@codecov-commenter

codecov-commenter commented Oct 31, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #1757 (581e51d) into main (c6099d5) will decrease coverage by 0.46%.
The diff coverage is 100.00%.

❗ Current head 581e51d differs from pull request most recent head e0ccfbb. Consider uploading reports for the commit e0ccfbb to get more accurate results

@@            Coverage Diff             @@
##             main    #1757      +/-   ##
==========================================
- Coverage   98.95%   98.49%   -0.46%     
==========================================
  Files         113      113              
  Lines        4953     4990      +37     
==========================================
+ Hits         4901     4915      +14     
- Misses         52       75      +23     
Impacted Files Coverage Δ
R/extract.R 98.68% <100.00%> (+0.15%) ⬆️
R/function_left_parentheses_linter.R 100.00% <100.00%> (ø)
R/indentation_linter.R 100.00% <100.00%> (ø)
R/lint.R 96.75% <100.00%> (ø)
R/linter_tags.R 97.50% <100.00%> (+0.06%) ⬆️
R/lintr-deprecated.R 100.00% <100.00%> (ø)
R/object_usage_linter.R 99.40% <100.00%> (+<0.01%) ⬆️
R/settings_utils.R 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@tonyk7440

Copy link
Copy Markdown
Contributor Author

@AshesITR Thanks for the pointers, I have updated the code, it looks to be passing that and other tests now. Let me know if you suggest other changes

@AshesITR AshesITR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@tonyk7440 thanks for your work so far!

@jimhester, @MichaelChirico, @IndrajeetPatil: WDYT about expanding the config search paths?

Comment thread R/settings_utils.R Resolved
Comment thread R/settings_utils.R Resolved
@jimhester

Copy link
Copy Markdown
Member

Sounds good to me

@tonyk7440
tonyk7440 requested a review from AshesITR November 3, 2022 18:25

@AshesITR AshesITR left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice work so far, thanks!
Now that we are sure we'll accept this change, please add a test package where the .github/linters/.lintr config takes effect.
Let me know if you need hints on how to do that.

Comment thread NEWS.md Resolved
Comment thread vignettes/lintr.Rmd Resolved
@AshesITR AshesITR mentioned this pull request Nov 3, 2022
@AshesITR

AshesITR commented Nov 4, 2022 •

Copy link
Copy Markdown
Collaborator

Thanks for trying to cook up a test.
Due to the R CMD check notes, you'll likely have to programmatically dir.create() the .github path.
Also note we usually use a different lintr.linter_file option to circumvent said R CMD check note regarding the .lintr filename.
withr::local_options(lintr.linter_file = "lintr_test_config")

Finally, to test that the config is pulled from .github/linters, you should make sure the test package does not contain a linter config at its root.
That way, if the config is not found, no exclusions would take effect and the test would fail when comparing to the lints generated with the linter config file present at the package root.

Right now, IINM, the lint_package() calls in your test always find .lintr at the package root.

@tonyk7440

Copy link
Copy Markdown
Contributor Author

Thanks @AshesITR!

I've updated the code, seems like the tests are passing now, let me know if I should make further changes.

@tonyk7440
tonyk7440 requested a review from AshesITR November 4, 2022 19:53

@AshesITR AshesITR left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Excellent work so far, thank you!
Just a few more adjustments.

Regarding the NEWS wording, I'd like to have input from @MichaelChirico.

Comment thread R/settings_utils.R Resolved
Comment thread tests/testthat/test-lint_package.R Resolved
@tonyk7440

Copy link
Copy Markdown
Contributor Author

Hi @AshesITR , sorry for the delay, currently very busy with work, will try to get some time this coming weekend

@AshesITR

Copy link
Copy Markdown
Collaborator

No worries, thanks for your feedback and good work so far.

@AshesITR AshesITR added this to the 3.0.3 milestone Dec 5, 2022
@IndrajeetPatil IndrajeetPatil modified the milestones: 3.0.3, 3.1.0 Dec 5, 2022
@klmr

klmr commented Mar 16, 2023

Copy link
Copy Markdown
Contributor

@tonyk7440 Hi, just wondering: are there any updates on this PR?

@MichaelChirico

Copy link
Copy Markdown
Collaborator

Gentle ping @tonyk7440 as we're moving towards release and it would be ideal to include this breaking change alongside a few others at the bump to 3.1.0.

If you're currently short on time, please ping & we can try and crowdsource getting this across the finish line.

Thanks again!

@MichaelChirico MichaelChirico modified the milestones: 3.1.0, 3.1.1 Apr 7, 2023
@tonyk7440

Copy link
Copy Markdown
Contributor Author

Hi @AshesITR @MichaelChirico @klmr , sorry for the delay in responding.
I've resolved most of the comments above. There is one outstanding ask from @AshesITR, due to my track record above I'll ask to crowdsource this change. Or else the above changes could be merged for the upcoming release and postpone that change to a later release?
Thanks!

Comment thread R/settings_utils.R Outdated

# Search through locations, return first valid result
for (loc in file_locations) {
if (isTRUE(file.exists(loc))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the isTRUE() call? As far as I can tell file.exists() should always return exactly one logical value here so this code doesn’t need to guard against non-logical values or vectors of length > 1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ugh, this comment (along with others that seem to be gone?!) was written months ago but was somehow part of a pending review without my noticing.

klmr added 4 commits April 21, 2023 18:50
Previously the test case never failed, even without the relevant patch.
This test will currently fail, and should no longer fail once
`.github/linters` is searched in parent directories as well as in the
current directory.
@klmr

klmr commented Apr 27, 2023

Copy link
Copy Markdown
Contributor

Alright, I’ve pushed my suggested changes. Happy for a review.

Comment thread vignettes/lintr.Rmd Outdated
3. A linter file in a parent directory of the currently-searched directory, starting from the deepest path, moving upwards one level at a time.
4. A linter file in the user's `HOME` directory.
3. A linter file in the `.github/linters` child directory of the currently-searched directory.
4. A linter file in a parent directory of the currently-searched directory, starting from the deepest path, moving upwards one level at a time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This could be made more clear, stating that 2. and 3. are searched from the parent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Aren't we checking 2. and 3. for the current directory and only if none match, the parent is searched recursively?

This description suggests we first search for .lintr in any parent and only look for .github/linters/.lintr if there is no .lintr anywhere in the path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@klmr this is the only blocker I see. Good to merge once the docs match the behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I completely missed these comments. I agree, my description is incorrect. Will change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Updated. Please take a look. I think we won’t get around making nested bullet points, since that reflects how the algorithm works. Is this clear enough?

Comment thread NEWS.md Outdated

## Deprecations & Breaking Changes

* .lintr configs can now be kept in the directory .github/linters for better compatibility with Super-Linter. Note that this may be a breaking change if you already have a config in both such a directory and in your R project's root since the former will now be discovered first where it was ignored before. Please see vignette("lintr") for details on how configs are discovered. (#1746, @tonyk7440)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IINM, the only breaking constellation is if .github/linter/.lintr is in a subdirectory, right?

i.e.

.lintr
tests/.github/linters/.lintr

will find a different config when run from tests/. Is that correct?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, you should add your name, @klmr.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You’re absolutely right! Will amend.

klmr added 2 commits April 28, 2023 18:33
Fixed the description based on review, performed very minor copy
editing, and adapted formatting to be consistent.

@AshesITR AshesITR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Just a minor nitpick left.

Comment thread vignettes/lintr.Rmd Outdated
2. A project-local linter file; that is, either
1. a linter file (that is, a file named like `lintr.linter_file`) in the currently-searched directory, i.e. the directory of the file passed to `lint()`; or
2. a linter file in the `.github/linters` child directory of the currently-searched directory.
3. A project-local linter file in the closest parent directory of the currently-searched directory, starting from the deepest path, moving upwards one level at a time. When run from `lint_package()`, this directory can differ for each linted file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Whitespace is inconsistent across top-level bullets.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oops. Fixed.

@AshesITR AshesITR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot, you two!

@MichaelChirico
MichaelChirico merged commit 4ef15f9 into r-lib:main May 22, 2023
@MichaelChirico

Copy link
Copy Markdown
Collaborator

@AshesITR it looked like this is ready to merge, LMK if that was in error.

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.

Modify .lintr file search algorithm

7 participants