Skip to content

Commit 6d2e3ef

Browse files
Change golangci-lint lint mode to project
It seems `list_of_files` is not the right choice as default lint mode for the `golangci-lint` linter, for several reasons. In such mode, the changed `.go` files are sent in a single call to the linter. The first issue with that is that, as the linter [Quick Start](https://golangci-lint.run/welcome/quick-start/) guide explicitly states, files must come from the same package. The second issue is that the linter tries to compile each file via `types.Checker` and, unless the source file is self-contained and has no references to things declared in other source files of the codebase, the compilation will fail, even if the references are towards the same package. Such compilation errors are reported by `golangci-lint` and labeled as `typecheck` (which is not a linter) (see [why do you have `typecheck` errors?](https://golangci-lint.run/welcome/faq/#why-do-you-have-typecheck-errors) section of the documentation). The same problem has also been reported in [`golangci-lint #1574`](golangci/golangci-lint#1574) by an user who configured his editor to run the linter on single files. As commented by a core maintainer [here](golangci/golangci-lint#1574 (comment)) `typecheck` is not included in the "fast" linters list and, therefore, cannot be run on single files.
1 parent ced5636 commit 6d2e3ef

File tree

11 files changed

+11
-1
lines changed

11 files changed

+11
-1
lines changed

.automation/test/golang/bad/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module megalinter.io/test-bad
2+
3+
go 1.21

.automation/test/golang/fix/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module megalinter.io/test-fix
2+
3+
go 1.21

.automation/test/golang/good/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module megalinter.io/test-good
2+
3+
go 1.21

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
1818
- Reporters
1919

2020
- Fixes
21+
- Change `golangci-lint` lint mode to `project`
2122

2223
- Doc
2324

megalinter/descriptors/go.megalinter-descriptor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ linters:
1616
linter_rules_configuration_url: https://golangci-lint.run/usage/configuration/#config-file
1717
linter_rules_inline_disable_url: https://golangci-lint.run/usage/false-positives/#nolint
1818
config_file_name: .golangci.yml
19-
cli_lint_mode: list_of_files
19+
cli_lint_mode: project
2020
cli_lint_extra_args:
2121
- "run"
2222
cli_lint_fix_arg_name: --fix

0 commit comments

Comments
 (0)