{"record":{"id":"2b52a20e44dc396a","repo":"golangci/golangci-lint","slug":"package-s-w","errorCode":null,"errorMessage":"package %s: %w","messagePattern":"package (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/lint/package.go","lineNumber":123,"sourceCode":"\n\treturn l.filterTestMainPackages(pkgs), nil\n}\n\nfunc (*PackageLoader) parseLoadedPackagesErrors(pkgs []*packages.Package) error {\n\tfor _, pkg := range pkgs {\n\t\tvar errs []packages.Error\n\t\tfor _, err := range pkg.Errors {\n\t\t\t// quick fix: skip error related to `go list` invocation by packages.Load()\n\t\t\t// The behavior has been changed between go1.19 and go1.20, the error is now inside the JSON content.\n\t\t\t// https://github.com/golangci/golangci-lint/pull/3414#issuecomment-1364756303\n\t\t\tif strings.Contains(err.Msg, \"# command-line-arguments\") {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\terrs = append(errs, err)\n\n\t\t\tif strings.Contains(err.Msg, \"no Go files\") {\n\t\t\t\treturn fmt.Errorf(\"package %s: %w\", pkg.PkgPath, exitcodes.ErrNoGoFiles)\n\t\t\t}\n\t\t\tif strings.Contains(err.Msg, \"cannot find package\") {\n\t\t\t\t// when analyzing not existing directory\n\t\t\t\treturn fmt.Errorf(\"%v: %w\", err.Msg, exitcodes.ErrFailure)\n\t\t\t}\n\t\t}\n\n\t\tpkg.Errors = errs\n\t}\n\n\treturn nil\n}\n\nfunc (l *PackageLoader) tryParseTestPackage(pkg *packages.Package) (name string, isTest bool) {\n\tmatches := l.pkgTestIDRe.FindStringSubmatch(pkg.ID)\n\tif matches == nil {\n\t\treturn \"\", false\n\t}","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/lint/package.go#L105-L141","documentation":"parseLoadedPackagesErrors inspects per-package errors reported by go/packages. When a package's error message contains \"no Go files\", loading aborts with exitcodes.ErrNoGoFiles wrapped as \"package <pkgpath>: no Go files\". golangci-lint cannot lint a package that has no Go source files in it.","triggerScenarios":"Targeting a package directory whose build yields \"build constraints exclude all Go files\" or a directory with no .go files for the current platform/tags — e.g. GOOS-specific code excluded by build constraints, or a directory containing only _test.go excluded files, C files, or assets.","commonSituations":"Running `golangci-lint run ./...` in a repo where a directory holds only non-Go files or platform-specific code (e.g. *_windows.go while linting on Linux with constraints); missing CGO enabling for cgo-only packages.","solutions":["Exclude the offending directory from the run (e.g. `golangci-lint run ./...` minus that path, or `linters.exclusions.paths` for the directory)","Add build tags/GOOS matching the excluded files, or enable CGO_ENABLED=1 for cgo-only packages","If the directory legitimately has no Go code, remove it from the package patterns you pass to golangci-lint","Ensure the directory is not an empty package accidentally included by `./...`"],"exampleFix":"// before (.golangci.yml) — fails on platform-specific dirs\n// (no exclusions)\n// after\nlinters:\n  exclusions:\n    paths:\n      - internal/windowsonly","handlingStrategy":"validation","validationCode":"// Check each target dir has Go files visible under current tags/GOOS before linting:\n// for d in $(go list -f '{{.Dir}}' ./... 2>/dev/null); do\n//   ls \"$d\"/*.go > /dev/null 2>&1 || echo \"no Go files: $d\"\n// done","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add `linters.exclusions.paths` entries for asset-only or platform-specific directories","Match GOOS/build tags between your build and lint steps (CGO_ENABLED, GOOS)","Avoid running `./...` in repos containing non-Go directories; use explicit package lists","Run `go vet ./...` first — it surfaces the same no-Go-files condition early"],"tags":["golangci-lint","go-packages","build-constraints"],"backgroundTag":"no-go-files","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}