-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Ability to run golangci_lint in a specific directory / change project directory for linter #4370
Comments
@angelahnicole it seems that golangci_lint allows to specify folders to analyze (sources: ChatGPT & golangci doc) Please can you try these solutions and confirm if it works ? Using command lineAdd in .mega-linter.yml
Using ENV variable
Using configuration file
|
Hey @nvuillam! We did try that, but it doesn't work :/ error when we added �[31m❌ Linted [GO] files with [golangci-lint]: Found 1 error(s) - (0.42s)�[0m
- Using [golangci-lint v1.62.0] https://megalinter.io/8.3.0/descriptors/go_golangci_lint
- MegaLinter key: [GO_GOLANGCI_LINT]
- Rules config: [/.golangci.yml]
- Command: [golangci-lint run --fix src/ -c /tmp/lint/.golangci.yml]
--Error detail:
level=error msg="Running error: context loading failed: no go files to analyze: running `go mod tidy` may solve the problem" error when we added �[31m❌ Linted [GO] files with [golangci-lint]: Found 1 error(s) - (0.89s)�[0m
- Using [golangci-lint v1.62.0] https://megalinter.io/8.3.0/descriptors/go_golangci_lint
- MegaLinter key: [GO_GOLANGCI_LINT]
- Rules config: [/.golangci.yml]
- Command: [golangci-lint run --fix src/... -c /tmp/lint/.golangci.yml]
--Error detail:
level=error msg="[linters_context] typechecking error: pattern ./src/...: directory prefix src does not contain main module or its selected dependencies" We're assuming it's because the
EDIT: FWIW, we also tried the env variable ( |
Oops... you can ask on golangci-lint repo what is the good call to perform for your use case ? ( I'm not a go expert :/ ) Then once we'll have the good call i'll be able to help |
Is your feature request related to a problem? Please describe.
It'd be nice to be able to run
golangci_lint
in a sub-directory of a golang repository so megalinter works for projects that are structured like this:. ├── .mega-linter.yml ├── README.md ├── src │ ├── cmd │ │ └── myservice │ │ └── main.go │ ├── .golangci.yml │ ├── go.mod │ └── go.sum └── terraform
Currently this does not work because
golangci_lint
is ran in the top-level directory where there isn't ago.mod
orgo.sum
file, and so you get this error:❌ Linted [GO] files with [golangci-lint]: Found 1 error(s) - (0.74s) - Using [golangci-lint v1.59.1] https://megalinter.io/7.13.0/descriptors/go_golangci_lint - MegaLinter key: [GO_GOLANGCI_LINT] - Rules config: [.golangci.yml] --Error detail: level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"
Describe the solution you'd like
It'd be nice to specify something like this in `.mega-linter.yml:
And have megalinter basically do a
cd ./src
before runninggolangci_lint
.Describe alternatives you've considered
I've tried passing in a different lint mode and regex like so:
But it doesn't work since only
project
is supported forGO_GOLANGCI_LINT_CLI_LINT_MODE
.I also looked into updating
GO_GOLANGCI_LINT_ARGUMENTS
somehow, butgolangci_lint
seems to need thego.mod
andgo.sum
files in the directory that it's ran from and there is no way to specify them.Additional context
N/A
The text was updated successfully, but these errors were encountered: