Skip to content

Commit 56c1b8b

Browse files
Change golangci-lint lint mode to project (#3509)
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. Co-authored-by: Nicolas Vuillamy <[email protected]>
1 parent 0e47b9a commit 56c1b8b

File tree

11 files changed

+11
-1
lines changed

11 files changed

+11
-1
lines changed

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

+3
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

+3
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

+3
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

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
2121
- Reporters
2222

2323
- Fixes
24+
- Change `golangci-lint` lint mode to `project`
2425
- Disable sql-lint as it is no longer maintained
2526

2627
- Doc

megalinter/descriptors/go.megalinter-descriptor.yml

+1-1
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)