Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
MistaTwista opened this issue Apr 18, 2024 · 5 comments
Labels
question Further information is requested

Comments

@MistaTwista
Copy link

MistaTwista commented Apr 18, 2024

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

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

Configuration

issues:
  exclude-dirs:
    - internal/snippet

Go environment

$ 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

$ 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

[email protected]: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

  • Yes, I've included all information above (version, config, etc.).
@MistaTwista MistaTwista added the bug Something isn't working label Apr 18, 2024
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Apr 18, 2024
@ldez
Copy link
Member

ldez commented Apr 18, 2024

Hello,

can you provide a minimal reproducible example?

@ldez ldez added the feedback required Requires additional feedback label Apr 18, 2024
@MistaTwista
Copy link
Author

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

@MistaTwista
Copy link
Author

MistaTwista commented Apr 19, 2024

looks similar at some things #1832

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

@ldez
Copy link
Member

ldez commented Apr 19, 2024

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 ldez removed the feedback required Requires additional feedback label Apr 19, 2024
@ldez
Copy link
Member

ldez commented Apr 19, 2024

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

@ldez ldez closed this as completed Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants