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

Use XDG config directory #460

Merged
merged 5 commits into from
Jun 4, 2023
Merged

Use XDG config directory #460

merged 5 commits into from
Jun 4, 2023

Conversation

klmr
Copy link
Contributor

@klmr klmr commented Feb 22, 2020

It would be great if the default lintr config would be preferentially looked up in the appropriate XDG base configuration directory instead of the user home directory. That is, if lintr defaulted to loading ${XDG_CONFIG_HOME-$HOME/.config}/lintr (note lack of leading dot in the filename!) and only if that doesn’t exist, checked for $HOME/.lintr. This avoids cluttering the home directory with config files.

Of course this can already be achieved by appropriately setting the lintr.linter_file option. But defaults matter.

This PR implements the necessary change, and stays 100% backwards compatible. Note that this causes the cyclomatic complexity of the find_config function to exceed the linting threshold. I’m open for suggestions of how to change this — but I’m tempted to call it a false positive (and to add an appropriate nolint comment).

@klmr klmr requested a review from jimhester as a code owner February 22, 2020 16:17
@gaborcsardi
Copy link
Member

How about the rappdirs package?

@klmr
Copy link
Contributor Author

klmr commented Feb 22, 2020

Good idea! However, if I understand correctly rappdirs is particularly geared towards GUI applications, rather than cross-platform tools and/or code library packages. In particular, on macOS, rappdirs::user_config_dir('lintr') returns /Users/‹user›/Library/Application Support/lintr, which is generally not where a command line tool/library configuration would be expected to reside. Apple would probably disagree, but the overwhelming convention for such tools on macOS is to either follow XDG or to dump everything in the home dir.

@jimhester
Copy link
Member

I think using rappdirs is the best solution if we want to go down this route.

@AshesITR
Copy link
Collaborator

Meanwhile, base R provides tools::R_user_dir("lintr", "config"), with backports providing this function to older R versions.

@klmr klmr changed the title USE XDG config directory Use XDG config directory Aug 8, 2022
@klmr klmr marked this pull request as draft August 8, 2022 12:22
@AshesITR
Copy link
Collaborator

AshesITR commented Nov 3, 2022

@krlmlr Are you still interested in this? #1757 is about to change the config search behavior so now would be a good time to also include XDG_CONFIG_HOME if it still seems useful.

@klmr
Copy link
Contributor Author

klmr commented Nov 3, 2022

@AshesITR (Wrong user tagged) Absolutely, and I had thought I had already submitted an updated PR. My bad! I’ll check the other PR and submit my changes ASAP!

@AshesITR
Copy link
Collaborator

AshesITR commented Nov 3, 2022

Thanks a ton and sorry for the wrong tag.
Maybe best to base against the new PR because it simplifies the code complexity by creating a candidate list.
This PR would then be as small as +1 line of code and some documentation around it.

@klmr klmr force-pushed the feature_xdg_config branch from 971fa47 to eddfb04 Compare November 3, 2022 21:53
@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2022

Codecov Report

Merging #460 (3b3f44e) into main (04eecd4) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #460   +/-   ##
=======================================
  Coverage   98.87%   98.87%           
=======================================
  Files         109      109           
  Lines        4621     4622    +1     
=======================================
+ Hits         4569     4570    +1     
  Misses         52       52           
Impacted Files Coverage Δ
R/settings.R 97.82% <ø> (ø)
R/settings_utils.R 100.00% <100.00%> (ø)
R/lint.R 96.78% <0.00%> (+<0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@klmr klmr marked this pull request as ready for review November 3, 2022 22:03
@klmr
Copy link
Contributor Author

klmr commented Nov 3, 2022

OK, I’ve added the necessary changes. This includes adding an environment variable to override the lintr config file location; I added this change because I think it belongs here: it is a widespread convention that the location of a configuration file can be overridden by an environment variable.

In the case of ‘lintr’ it made sense (I think) to make this environment variable act as the default value for getOption('lintr.linter_file'), rather than being yet another way of specifying the file location.

@AshesITR At your suggestion I rebased this PR onto #1757; however, this means that the outstanding changes to that PR will probably block this one.

@klmr klmr force-pushed the feature_xdg_config branch from 9e8fb79 to 219dacf Compare November 3, 2022 22:23
@AshesITR
Copy link
Collaborator

AshesITR commented Nov 7, 2022

Could you write some tests to see if the XDG config is pulled as expected?

@klmr
Copy link
Contributor Author

klmr commented Nov 13, 2022

@AshesITR Apologies, I had completely missed that. Test added.

@AshesITR
Copy link
Collaborator

LGTM, thanks! Waiting for #1757 to hit the finish line and then rebasing #460 again.

@AshesITR AshesITR added this to the 3.0.3 milestone Dec 5, 2022
@MichaelChirico MichaelChirico modified the milestones: 3.0.3, 3.1.0, 3.2.0, 3.1.1 Mar 20, 2023
@klmr klmr force-pushed the feature_xdg_config branch from 3b3f44e to 3e86b45 Compare May 23, 2023 14:50
@klmr
Copy link
Contributor Author

klmr commented May 23, 2023

@AshesITR I’ve rebased the PR against the merged main branch now that #1757 has been merged. Please have a look.

@AshesITR
Copy link
Collaborator

AshesITR commented Jun 1, 2023

Sorry for taking so long to review, I'll try to get to this soon.

@AshesITR AshesITR merged commit b4fd5db into r-lib:main Jun 4, 2023
@klmr klmr deleted the feature_xdg_config branch June 5, 2023 19:34
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.

6 participants