lintr icon indicating copy to clipboard operation
lintr copied to clipboard

Use XDG config directory

Open klmr opened this issue 5 years ago • 4 comments

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 avatar Feb 22 '20 16:02 klmr

How about the rappdirs package?

gaborcsardi avatar Feb 22 '20 17:02 gaborcsardi

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.

klmr avatar Feb 22 '20 18:02 klmr

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

jimhester avatar Mar 02 '20 16:03 jimhester

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

AshesITR avatar Mar 28 '22 12:03 AshesITR

@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.

AshesITR avatar Nov 03 '22 19:11 AshesITR

@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!

klmr avatar Nov 03 '22 19:11 klmr

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.

AshesITR avatar Nov 03 '22 19:11 AshesITR

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%) :arrow_up:

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

codecov-commenter avatar Nov 03 '22 21:11 codecov-commenter

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 avatar Nov 03 '22 22:11 klmr

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

AshesITR avatar Nov 07 '22 06:11 AshesITR

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

klmr avatar Nov 13 '22 22:11 klmr

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

AshesITR avatar Nov 14 '22 09:11 AshesITR

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

klmr avatar May 23 '23 14:05 klmr

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

AshesITR avatar Jun 01 '23 20:06 AshesITR