golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.27k stars 1.36k forks source link

linters_context generating typechecking error about malformed import path for files and folders in issues.exclude-dirs #4659

Closed MistaTwista closed 4 months ago

MistaTwista commented 4 months ago

Welcome

Description of the problem

I have a project where go files generating from paths that looks like internal/snippet/some{{ .Metadata.Name }}/packageName/something.go. I process them with golang template engine, so in a final project it's ok)

I've set option to exclude-dirs in config. The problem here is that folders actually are not skipped.

I see error like: typechecking error: malformed import path "...some{{.Metadata.Name}}": invalid char '{'

The question is is this a bug or if I need to template something I should use .tmpl files instead of .go? But what about to skip directories completely?

Version of golangci-lint

```console $ golangci-lint --version golangci-lint has version 1.57.2 built with go1.22.1 from 77a8601 on 2024-03-28T18:39:06Z ```

Configuration

```yaml issues: exclude-dirs: - internal/snippet ```

Go environment

```console $ go version && go env go version go1.21.6 darwin/amd64 GO111MODULE='auto' GOARCH='amd64' GOBIN='' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='darwin' GOINSECURE='' GOOS='darwin' GOPROXY='direct' GOSUMDB='off' GOTMPDIR='' GOTOOLCHAIN='auto' GOVCS='' GOVERSION='go1.21.6' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='clang' CXX='clang++' CGO_ENABLED='1' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v INFO [config_reader] Config search paths: [/Users/mistatwista/go/src /Users/mistatwista/go /Users/mistatwista /Users /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 74 linters: [asasalint asciicheck bidichk bodyclose contextcheck cyclop decorder dogsled dupl errcheck errchkjson errname errorlint execinquery exhaustive exportloopref forbidigo forcetypeassert funlen gci gochecknoglobals gochecknoinits gocognit goconst gocritic godot godox goerr113 gofmt gofumpt goheader goimports gomnd gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper importas ineffassign ireturn lll maintidx makezero misspell nakedret nestif nilerr nilnil nlreturn noctx nolintlint nosprintfhostport paralleltest prealloc predeclared promlinter revive rowserrcheck sqlclosecheck staticcheck tagliatelle tenv thelper tparallel unconvert unparam unused usestdlibvars wastedassign whitespace wsl] INFO [loader] Go packages loading at mode 575 (exports_file|imports|files|name|types_sizes|compiled_files|deps) took 1.137843266s INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 6.726087ms INFO [linters_context] importas settings found, but no aliases listed. List aliases under alias: key. ERRO [linters_context] typechecking error: malformed import path "... internal/snippet/some{{.Metadata.Name}}": invalid char '{' INFO [linters_context/goanalysis] analyzers took 14.285252ms with top 10 stages: fact_deprecated: 1.315369ms, buildir: 1.138168ms, S1021: 679.879µs, SA4021: 666.613µs, nilerr: 630.405µs, SA9006: 609.793µs, commentmap: 605.164µs, S1039: 604.204µs, tagliatelle: 604.203µs, gosec: 593.179µs INFO [runner] Issues before processing: 383, after processing: 0 INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 383/383, invalid_issue: 383/383, autogenerated_exclude: 383/383, exclude-rules: 202/383, cgo: 383/383, skip_files: 383/383, skip_dirs: 383/383, identifier_marker: 383/383, nolint: 0/202, path_prettifier: 383/383, exclude: 383/383 INFO [runner] processing took 40.010755ms with stages: exclude-rules: 15.646809ms, nolint: 12.484288ms, identifier_marker: 9.554098ms, path_prettifier: 1.182333ms, autogenerated_exclude: 878.819µs, skip_dirs: 208.593µs, cgo: 20.813µs, invalid_issue: 16.718µs, filename_unadjuster: 13.237µs, max_same_issues: 976ns, path_shortener: 632ns, exclude: 481ns, fixer: 481ns, uniq_by_line: 420ns, skip_files: 345ns, diff: 305ns, max_from_linter: 289ns, path_prefixer: 241ns, sort_results: 239ns, source_code: 237ns, severity-rules: 220ns, max_per_file_from_linter: 181ns INFO [runner] linters took 879.282409ms with stages: goanalysis_metalinter: 839.105891ms INFO File cache stats: 0 entries of total size 0B INFO Memory: 22 samples, avg is 42.6MB, max is 84.1MB INFO Execution took 2.04524279s ```

A minimal reproducible example or link to a public repository

```bash git@github.com:MistaTwista/templado.git cd templado golangci-lint run ERRO [linters_context] typechecking error: malformed import path "github.com/MistaTwista/templado/internal/snippets/es-{{ .Metadata.Name }}": invalid char '{' echo $? 7 ```

Validation

ldez commented 4 months ago

Hello,

can you provide a minimal reproducible example?

MistaTwista commented 4 months ago

yes, sure, sorry https://github.com/MistaTwista/templado

MistaTwista commented 4 months ago

looks similar at some things https://github.com/golangci/golangci-lint/issues/1832

btw, i can look for fix if you don't mind

ldez commented 4 months ago

There is no possible fix because it's related to the Go tooling. The loading of packages (by the official Go tooling) doesn't behave exactly like go build: file paths don't follow the same validations.

I recommend using the .tmpl extension.

FYI exclude-dirs is a post-process filter on reports, currently the Go tooling doesn't offer the possibility to ignore a package or a file during the analysis. We renamed and moved run.skip-dirs to issues.exclude-dirs to avoid confusion about this option.

ldez commented 4 months ago

Closes in favor of #4360 - Feel free to subscribe there for updates.