Skip to content

VS Code extension doesn't work on monorepos #6110

@mauriciabad

Description

@mauriciabad

Description of the problem

Given a monorepo inside the user's home:

  • ~: User's home folder
    • project: Monorepo root
      • api: go code
        • subdir: example subdirectory
          • myfile.go: example file
      • frontend: website that uses api

Opening project folder in VS Code with the go extension installed crashes and doesn't mark any lint errors.

[error] level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"

In contrast, if I open the api folder, the linter works.

Basically, these commands should work:

cd ~/project && golangci-lint run
cd ~/project && golangci-lint run ./api/...

And from a UX perspective, in my opinion, this should also work: (Because it's unexpected that the run command must run from the go module directory)

cd ~/project/api/subdir && golangci-lint run ./myfile.go

Related to: #828 (comment) #6057

Possible fix suggestion

When running golangci-lint run, don't error if the folder isn't a go module. Instead, keep going and ignore all the files/directories that are not a go module. When it finds a module, then run the lint with that configuration. And if it doesn't find any go module, then error.

This solution is nice because you can run different configurations using the same run command.

Consider also checking the parent directories recursively, to find a go module.

How did you install golangci-lint?

Via editor/IDE

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 2.5.0 built with go1.25.1 from ff63786 on 2025-09-21T18:53:13Z

Configuration

Configuration not relevant

Go environment

Go environment not relevant

Verbose output of running

$ golangci-lint cache clean
$ cd ~/project
$ golangci-lint run ./api/... -v

INFO golangci-lint has version 2.5.0 built with go1.25.1 from ff63786 on 2025-09-21T18:53:13Z 
INFO [config_reader] Config search paths: [./ /Users/me/project/api /Users/me/project /Users/me/Projects /Users/me /Users /] 
INFO maxprocs: Leaving GOMAXPROCS=10: CPU quota undefined 
INFO [goenv] Read go env for 7.046ms: map[string]string{"GOCACHE":"/Users/me/Library/Caches/go-build", "GOROOT":"/opt/homebrew/Cellar/go/1.25.1/libexec"} 
INFO [lintersdb] Active 5 linters: [errcheck govet ineffassign staticcheck unused] 
INFO [loader] Go packages loading at mode 8767 (exports_file|imports|types_sizes|compiled_files|deps|files|name) took 28.981292ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 141.584µs 
ERRO [linters_context] typechecking error: pattern ./api/...: directory prefix api does not contain main module or its selected dependencies 
INFO [linters_context/goanalysis] analyzers took 850.542µs with top 10 stages: fact_deprecated: 709.5µs, cgocall: 113.125µs, config: 27.917µs 
INFO [runner] processing took 1.374µs with stages: max_same_issues: 250ns, path_absoluter: 208ns, exclusion_rules: 167ns, fixer: 125ns, exclusion_paths: 84ns, sort_results: 84ns, nolint_filter: 83ns, path_prettifier: 42ns, path_shortener: 42ns, severity-rules: 42ns, filename_unadjuster: 42ns, generated_file_filter: 41ns, uniq_by_line: 41ns, max_per_file_from_linter: 41ns, max_from_linter: 41ns, source_code: 41ns, invalid_issue: 0s, cgo: 0s, path_relativity: 0s, diff: 0s 
INFO [runner] linters took 1.650875ms with stages: goanalysis_metalinter: 1.60025ms 
0 issues.
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 2 samples, avg is 35.4MB, max is 35.4MB 
INFO Execution took 38.923209ms                 

A minimal reproducible example or link to a public repository

Already described before.

Just use any working go codebase using golangci-lint, wrap it in a folder (example), and wrap that into another folder (monorepo):

  • monorepo: root of the monorepo
    • example: Any codebase using golangci-lint

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions