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

Support .config #4554

Open
bersace opened this issue Mar 20, 2024 · 10 comments
Open

Support .config #4554

bersace opened this issue Mar 20, 2024 · 10 comments
Labels
enhancement New feature or improvement no decision No decision to fix or not

Comments

@bersace
Copy link

bersace commented Mar 20, 2024

Your feature request related to a problem? Please describe.

golangci uses .golangci.yml file on top of project. This clutters root directory of projects.

Describe the solution you'd like.

I suggest to search for .config/golangci.yml too as described at https://github.com/pi0/config-dir

Describe alternatives you've considered.

Using environment variable. This work on CI but is not easy for mates.

Additional context.

No response

@bersace bersace added the enhancement New feature or improvement label Mar 20, 2024
Copy link

boring-cyborg bot commented Mar 20, 2024

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

@ldez ldez added no decision No decision to fix or not declined and removed no decision No decision to fix or not labels Mar 20, 2024
@ldez
Copy link
Member

ldez commented Mar 20, 2024

Hello,

the configuration of golangci-lint is not a simple tool configuration: it depends on the project and should be committed inside the project.

If you run golangci-lint with the verbose flag, you will see that golangci-lint tries to find the configuration in several places:

$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/user/a/b/c /home/user/a/b /home/user/a /home/user /home /]

I think that ~/.config is not the right place for tools like golangci-lint.

@ldez ldez closed this as completed Mar 20, 2024
@bersace
Copy link
Author

bersace commented Mar 20, 2024

You confused XDG ~/.config and $PWD/.config as described at https://github.com/pi0/config-dir . Please reopen.

Regards,
Étienne

@ldez
Copy link
Member

ldez commented Mar 20, 2024

$PWD will not work because you can run golangci-lint inside a package.

To have something that works, we will have to look at all the .config inside the directory tree.

  • ./
  • /home/user/a/b/c
  • /home/user/a/b/c/.config
  • /home/user/a/b
  • /home/user/a/b/.config
  • /home/user/a
  • /home/user/a/.config
  • /home/user
  • /home/user/.config
  • /home
  • /home/.config
  • /
  • /.config

@ldez ldez removed the declined label Mar 20, 2024
@ldez ldez reopened this Mar 20, 2024
@ldez
Copy link
Member

ldez commented Mar 20, 2024

🤔 maybe we can do that but the filename will stay .golangci-lint.{yml|yaml|toml|json} (with a dot at the beginning)

🤔 There is a problem with paths, inside the configuration, relative to the configuration position.

@ldez ldez added the no decision No decision to fix or not label Mar 20, 2024
bombsimon added a commit to bombsimon/golangci-lint that referenced this issue Mar 20, 2024
Support for `.config` proposal from https://github.com/pi0/config-dir.
While walking the tree, check if a directory named `.config` exist. If
so, add it to `configSearchPaths` to include when searching for
`.golangci.yaml`.

Fixes golangci#4554
@bombsimon
Copy link
Member

Since it's fairly easy and cheap to check for a .config directory while we create the search paths I created a PR for this. Although I don't know if we want to support so we can continue to discuss it here but the PR is ready if we decide to accept the request.

@ldez
Copy link
Member

ldez commented Mar 20, 2024

My current thought is that we are not ready.

It can feel easy to add the dir to the search (I also did it locally), but we currently have issues with paths inside the configuration as I said here.

Some elements are relative to the configuration path, and some others to the execution path.
Using a path that is not a parent of the project can be a problem.

This is why I put the label no-decision, it needs to evaluate more things.

@bombsimon
Copy link
Member

I'm not sure I see the difference compared to when using --config targeting such locations or a global ~/.golangci.yaml, the config would have to reflect that. But of course it would be better if config was consistent independent on where the file is.

I'm not saying that's a reason to add more problematic code and I understand your reasoning!

@bersace
Copy link
Author

bersace commented Mar 21, 2024

I guess golangci should build the project root from config path by removing both filename and trailing .config.

@silverwind
Copy link
Contributor

silverwind commented Apr 11, 2024

Some elements are relative to the configuration path, and some others to the execution path.

One way of solving this would be to allow the config file to be go code, e.g. golangci.config.go, then the user can take care of path resolution themselves and would ideally only pass absolute paths.

Having the config as code enables many powerful patterns that would otherwise not be possible in static formats like yaml.

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

Successfully merging a pull request may close this issue.

4 participants