feat: support searching for config in XDG_CONFIG_HOME and $HOME/.config #4974
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This code will, in addition to the current directories being searched, also look for the config file in
XDG_CONFIG_HOME/golangci
and$HOME/.config/golangci
.For desktop applications, I find it not very elegant to leave the
.golangci.yml
in my home directory. I usually prefer to put config files inXDG_CONFIG_HOME
($HOME/.config
) to avoid making a mess in the home directory. I do not want to manually specify a config path with--config
since it will overwrite the repository's config if one exists. I reviewed the code and found thatgolangci-lint
does not seem to support finding the config inXDG_CONFIG_HOME
, so I'm submitting this PR in recommendation of adding this support.Setup
I have a configuration file located at
$HOME/.config/golangci/golangci.yml
. I am usinggolangci-lint
's repository for the demo below. I have removed the repository's built-in.golangci.yml
so it will search for the global config.Previous Behavior
Previously,
golangci-lint
does not search for the said directories above, only$HOME
:New Behavior
Now, if the old recursive search does not yield any results, it will also search the global config directories:
...and if we restore the repo config it still finds that first:
Fixes #4554