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

Global configuration #1324

Closed
System-Glitch opened this issue Aug 21, 2020 · 5 comments
Closed

Global configuration #1324

System-Glitch opened this issue Aug 21, 2020 · 5 comments
Labels
enhancement New feature or improvement

Comments

@System-Glitch
Copy link
Member

System-Glitch commented Aug 21, 2020

Is your feature request related to a problem? Please describe.
Default settings don't suit my needs. When I clone projects that are not using golangci-lint, I would like to keep the configuration I am using everywhere else.

Describe the solution you'd like
If ~/.golangci.yml exists, use it as global configuration, but only if there is no .golangci.yml file in the working directory or in parent directories. For example, if your projects are not located inside your home directory (maybe on another drive), the ~/.golangci.yml file won't be found and it won't work.

Describe alternatives you've considered
Copying my default config to every new project, but it's not very practical. If you agree with the feature, but you don't have time to implement it, I can try and open a pull request.

@System-Glitch System-Glitch added the enhancement New feature or improvement label Aug 21, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 21, 2020

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@bombsimon
Copy link
Member

Sorry if I'm missing something but this is exactly how it works to me. golangci-lint will look in your project root for a golangci.yaml file and if it doesn't exist fall back to ~/.golangci.yaml. If that doesn't exist default settings will be used.

I have a personal configuration file in my home directory and it's being used in every project that doesn't bundle it's own configuration file.

@System-Glitch
Copy link
Member Author

System-Glitch commented Aug 21, 2020

Oh that's right. It works for me too. However, this only works if your projects are located inside your home directory. Try with a project that is located on another drive, and it won't work.

Docs:

GolangCI-Lint also searches for config files in all directories from the directory of the first analyzed path up to the root.

It is correct, but it doesn't search specifically in the home directory.

@SVilgelm
Copy link
Member

SVilgelm commented Aug 21, 2020

Confirmed.
it's actually looks for the configuration file starts from the current folder and goes up to the root: https://github.com/golangci/golangci-lint/blob/master/pkg/config/reader.go#L155
It's does not use $HOME
So it works if the project is placed on same drive, but it does not work from another drive.
The fix should be trivial, I would suggest to use the https://github.com/mitchellh/go-homedir package and add homedir.Dir() to the configSearchPaths variable: https://github.com/golangci/golangci-lint/blob/master/pkg/config/reader.go#L172

@System-Glitch
Copy link
Member Author

@SVilgelm Thank you for the guidance. I will open a PR later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

3 participants