golangci / golangci-lint

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

Cannot easily disable `typecheck` #2912

Closed Callisto13 closed 2 years ago

Callisto13 commented 2 years ago

Welcome

Description of the problem

While waiting for full 1.18 support, I attempted to disable the typecheck linter which was giving me grief.

I added it to this section of my config:

linters:
  enable-all: true
  disable:
  - typecheck
  - etc...

But it had no effect.

According to the docs this should be possible.

In the end I did the following, which worked:

issues:
  exclude-rules:
  - path: /
    linters:
    - typecheck

Version of golangci-lint

```console $ golangci-lint --version golangci-lint has version 1.46.2 built from a3336890 on 2022-05-17T11:31:29Z ```

Configuration file

```console $ cat .golangci.yml run: go: "1.18" timeout: 10m tests: false allow-parallel-runners: true skip-dirs: - "./*/mock" linters-settings: funlen: lines: 110 statements: 60 staticcheck: go: "1.18" stylecheck: go: "1.18" cyclop: max-complexity: 15 skip-tests: true gosec: exclude-generated: true lll: line-length: 120 misspell: locale: GB goimports: local-prefixes: github.com/weaveworks/flintlock govet: check-shadowing: true nolintlint: allow-leading-space: false allow-unused: false require-explanation: true require-specific: false varnamelen: ignore-names: - err - wg - fs - id - vm - ns - ip issues: max-same-issues: 0 max-issues-per-linter: 0 exclude-rules: - text: "should not use dot imports|don't use an underscore in package name" linters: - golint - text: "local replacement are not allowed: github.com/weaveworks/flintlock/" linters: - gomoddirectives - text: "sig: func github.com/weaveworks/flintlock/" linters: - wrapcheck - source: "https://" linters: - lll - path: pkg/defaults/ linters: - lll - path: _test\.go linters: - goerr113 - gocyclo - errcheck - gosec - dupl - funlen - scopelint - testpackage - path: internal/version/ linters: - gochecknoglobals - path: internal/command/ linters: - exhaustivestruct - lll - wrapcheck - source: "// .* #\\d+" linters: - godox - path: test/e2e/ linters: - goerr113 - gomnd linters: enable-all: true disable: - exhaustivestruct - golint - interfacer - ireturn - maligned - nilnil - scopelint - tagliatelle - gomoddirectives - typecheck ```

Go environment

```console $ go version && go env go version go1.18.3 linux/amd64 GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/claudia/.cache/go-build" GOENV="/home/claudia/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/claudia/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/claudia/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.3" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/claudia/workspace/flintlock/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1873054285=/tmp/go-build -gno-record-gcc-switches" ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v INFO [config_reader] Config search paths: [./ /home/claudia/workspace/flintlock /home/claudia/workspace /home/claudia /home /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 73 linters: [asciicheck bidichk bodyclose contextcheck cyclop deadcode depguard dogsled dupl durationcheck errcheck errname errorlint exhaustive exportloopref forbidigo forcetypeassert funlen gci gochecknoglobals gochecknoinits gocognit goconst gocritic gocyclo godot godox goerr113 gofmt gofumpt goheader goimports gomnd gomodguard goprintffuncname gosec gosimple govet ifshort importas ineffassign lll makezero misspell nakedret nestif nilerr nlreturn noctx nolintlint paralleltest prealloc predeclared promlinter revive rowserrcheck sqlclosecheck staticcheck structcheck stylecheck tenv testpackage thelper tparallel unconvert unparam unused varcheck varnamelen wastedassign whitespace wrapcheck wsl] INFO [loader] Go packages loading at mode 575 (deps|exports_file|imports|compiled_files|files|name|types_sizes) took 271.667642ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 5.868339ms INFO [linters context] importas settings found, but no aliases listed. List aliases under alias: key. INFO [linters context/goanalysis] analyzers took 2.284062685s with top 10 stages: the_only_name: 72.982384ms, gocritic: 34.429007ms, godox: 28.403245ms, ineffassign: 23.718449ms, directives: 20.996316ms, buildtag: 20.314691ms, testpackage: 20.134428ms, errorlint: 20.052842ms, dupl: 19.97993ms, ST1012: 17.987856ms INFO [runner] Issues before processing: 11228, after processing: 51 INFO [runner] Processors filtering stat (out/in): max_per_file_from_linter: 51/51, filename_unadjuster: 11228/11228, path_prettifier: 11228/11228, diff: 51/51, sort_results: 51/51, autogenerated_exclude: 11228/11228, identifier_marker: 11228/11228, max_same_issues: 51/51, max_from_linter: 51/51, source_code: 51/51, path_shortener: 51/51, severity-rules: 51/51, skip_files: 11228/11228, skip_dirs: 11228/11228, nolint: 11220/11220, uniq_by_line: 51/11220, path_prefixer: 51/51, cgo: 11228/11228, exclude: 11228/11228, exclude-rules: 11220/11228 INFO [runner] processing took 420.037627ms with stages: exclude-rules: 286.927974ms, identifier_marker: 120.318589ms, nolint: 4.713532ms, path_prettifier: 3.85884ms, skip_dirs: 1.113003ms, cgo: 811.036µs, uniq_by_line: 762.391µs, autogenerated_exclude: 714.042µs, filename_unadjuster: 660.512µs, source_code: 141.818µs, path_shortener: 9.496µs, max_per_file_from_linter: 3.414µs, max_same_issues: 1.146µs, skip_files: 414ns, diff: 344ns, sort_results: 305ns, severity-rules: 253ns, max_from_linter: 234ns, exclude: 205ns, path_prefixer: 79ns INFO [runner] linters took 4.236279675s with stages: goanalysis_metalinter: 3.816156997s INFO File cache stats: 14 entries of total size 57.8KiB INFO Memory: 47 samples, avg is 336.5MB, max is 409.5MB INFO Execution took 4.518303126s hack/tools/bin/golangci-lint run -v --fast=false core/models/vmid.go:4:2: could not import encoding (-: could not load export data: cannot import "encoding" (unstable iexport format version 2, just rebuild compiler and std library), export data is newer version - update tool) (typecheck) "encoding" ^ internal/command/flags/urfave.go:9:29: undeclared name: `cli` (typecheck) type WithFlagsFunc func() []cli.Flag ^ internal/command/flags/urfave.go:11:43: undeclared name: `cli` (typecheck) func CLIFlags(options ...WithFlagsFunc) []cli.Flag { ^ internal/command/flags/urfave.go:62:37: undeclared name: `cli` (typecheck) func ParseFlags(cfg *config.Config) cli.BeforeFunc { ^ internal/command/flags/urfave.go:12:13: undeclared name: `cli` (typecheck) flags := []cli.Flag{} ^ internal/command/flags/urfave.go:22:18: undeclared name: `cli` (typecheck) return func() []cli.Flag { ^ internal/command/flags/urfave.go:23:12: undeclared name: `cli` (typecheck) return []cli.Flag{ ^ internal/command/flags/urfave.go:24:5: undeclared name: `cli` (typecheck) &cli.StringFlag{ ^ internal/command/flags/urfave.go:29:5: undeclared name: `cli` (typecheck) &cli.StringFlag{ ^ internal/command/flags/urfave.go:39:18: undeclared name: `cli` (typecheck) return func() []cli.Flag { ^ internal/command/flags/urfave.go:40:12: undeclared name: `cli` (typecheck) return []cli.Flag{ ^ internal/command/flags/urfave.go:41:5: undeclared name: `cli` (typecheck) &cli.StringFlag{ ^ internal/command/flags/urfave.go:51:18: undeclared name: `cli` (typecheck) return func() []cli.Flag { ^ internal/command/flags/urfave.go:52:12: undeclared name: `cli` (typecheck) return []cli.Flag{ ^ internal/command/flags/urfave.go:53:5: undeclared name: `cli` (typecheck) &cli.StringFlag{ ^ internal/command/flags/urfave.go:63:19: undeclared name: `cli` (typecheck) return func(ctx *cli.Context) error { ^ internal/command/flags/urfave.go:4:2: "github.com/urfave/cli/v2" imported but not used (typecheck) "github.com/urfave/cli/v2" ^ core/application/commands.go:10:2: could not import github.com/weaveworks-liquidmetal/flintlock/client/cloudinit (-: could not load export data: cannot import "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit" (unstable iexport format version 2, just rebuild compiler and std library), export data is newer version - update tool) (typecheck) "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit" ^ core/application/commands.go:11:2: could not import github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/instance (-: could not load export data: cannot import "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/instance" (unstable iexport format version 2, just rebuild compiler and std library), export data is newer version - update tool) (typecheck) "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/instance" ^ infrastructure/containerd/client_interface.go:57:16: undeclared name: `tasks` (typecheck) TaskService() tasks.TasksClient ^ infrastructure/containerd/repo.go:268:73: undeclared name: `digest` (typecheck) func (r *containerdRepo) getWithDigest(ctx context.Context, metadigest *digest.Digest) (*models.MicroVM, error) { ^ infrastructure/containerd/repo.go:288:5: undeclared name: `digest` (typecheck) ) (*digest.Digest, error) { ^ infrastructure/containerd/repo.go:337:96: undeclared name: `digest` (typecheck) func (r *containerdRepo) findAllDigestForSpec(ctx context.Context, name, namespace string) ([]*digest.Digest, error) { ^ infrastructure/containerd/repo.go:146:25: undeclared name: `digest` (typecheck) digests := map[string]*digest.Digest{} ^ infrastructure/containerd/repo.go:289:14: undeclared name: `digest` (typecheck) var digest *digest.Digest ^ infrastructure/containerd/repo.go:343:16: undeclared name: `digest` (typecheck) digests := []*digest.Digest{} ^ infrastructure/containerd/client_interface.go:7:2: "github.com/containerd/containerd/api/services/tasks/v1" imported but not used (typecheck) "github.com/containerd/containerd/api/services/tasks/v1" ^ infrastructure/containerd/repo.go:15:2: "github.com/opencontainers/go-digest" imported but not used (typecheck) "github.com/opencontainers/go-digest" ^ infrastructure/controllers/microvm_controller.go:11:2: "github.com/weaveworks-liquidmetal/flintlock/api/events" imported but not used (typecheck) "github.com/weaveworks-liquidmetal/flintlock/api/events" ^ infrastructure/firecracker/config.go:8:12: could not import github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/network (-: could not load export data: cannot import "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/network" (unstable iexport format version 2, just rebuild compiler and std library), export data is newer version - update tool) (typecheck) cinetwork "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/network" ^ infrastructure/firecracker/config.go:211:11: undeclared name: `firecracker` (typecheck) DHCP4: firecracker.Bool(true), ^ infrastructure/firecracker/config.go:212:11: undeclared name: `firecracker` (typecheck) DHCP6: firecracker.Bool(true), ^ infrastructure/firecracker/config.go:230:13: undeclared name: `yaml` (typecheck) nd, err := yaml.Marshal(network) ^ infrastructure/firecracker/config.go:270:14: undeclared name: `firecracker` (typecheck) eth.DHCP4 = firecracker.Bool(false) ^ infrastructure/firecracker/config.go:271:14: undeclared name: `firecracker` (typecheck) eth.DHCP6 = firecracker.Bool(false) ^ infrastructure/firecracker/create.go:54:9: undeclared name: `firecracker` (typecheck) cmd := firecracker.VMCommandBuilder{}. ^ infrastructure/firecracker/config.go:7:2: "github.com/firecracker-microvm/firecracker-go-sdk" imported but not used (typecheck) "github.com/firecracker-microvm/firecracker-go-sdk" ^ infrastructure/firecracker/config.go:12:2: "gopkg.in/yaml.v3" imported but not used (typecheck) "gopkg.in/yaml.v3" ^ infrastructure/firecracker/create.go:10:2: "github.com/firecracker-microvm/firecracker-go-sdk" imported but not used (typecheck) "github.com/firecracker-microvm/firecracker-go-sdk" ^ infrastructure/grpc/convert.go:7:2: could not import github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/instance (-: could not load export data: cannot import "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/instance" (unstable iexport format version 2, just rebuild compiler and std library), export data is newer version - update tool) (typecheck) "github.com/weaveworks-liquidmetal/flintlock/client/cloudinit/instance" ^ infrastructure/grpc/server.go:56:16: undeclared name: `validator` (typecheck) var valErrors validator.ValidationErrors ^ infrastructure/grpc/server.go:8:2: "github.com/go-playground/validator/v10" imported but not used (typecheck) "github.com/go-playground/validator/v10" ^ internal/command/metrics/main.go:9:29: undeclared name: `cli` (typecheck) func NewApp(out io.Writer) *cli.App { ^ internal/command/metrics/main.go:23:20: undeclared name: `cli` (typecheck) func commands() []*cli.Command { ^ internal/command/metrics/serve.go:20:22: undeclared name: `cli` (typecheck) func serveCommand() *cli.Command { ^ internal/command/metrics/main.go:10:9: undeclared name: `cli` (typecheck) app := cli.NewApp() ^ internal/command/metrics/main.go:24:12: undeclared name: `cli` (typecheck) return []*cli.Command{ ^ internal/command/metrics/serve.go:23:10: undeclared name: `cli` (typecheck) return &cli.Command{ ^ internal/command/metrics/serve.go:33:19: undeclared name: `cli` (typecheck) Action: func(c *cli.Context) error { ^ internal/command/metrics/main.go:6:2: "github.com/urfave/cli/v2" imported but not used (typecheck) "github.com/urfave/cli/v2" ^ internal/command/metrics/serve.go:10:2: "github.com/urfave/cli/v2" imported but not used (typecheck) "github.com/urfave/cli/v2" ^ ```

Code example or link to a public repository

https://github.com/weaveworks-liquidmetal/flintlock

boring-cyborg[bot] commented 2 years ago

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

ldez commented 2 years ago

Hello,

typecheck is not a real linter it's just a way to parse/display "compilation" and linters errors (linter reports are not errors), typecheck cannot be disabled because of that. All the linters can trigger a typecheck issue, but some linters require that the code compile, those linters will produce more typecheck issues. A linter that reports typecheck issue is not able to report other issues for a package because that kind of issue doesn't allow it to perform its own analysis.

Thynix commented 1 year ago

May I propose that this be considered as an area for documentation improvement?

Given that typecheck is an internal mechanism for reporting build and linter errors, I found it very confusing that in all the documentation I checked, it's presented as though it's a linter. It's listed in linters enabled by default, and in run configuration.

Would y'all accept a PR to remove it from those lists, and possibly add a section about how typecheck is not actually a linter? The output format including (typecheck) could be misleading in suggesting that it is.

prochac commented 1 year ago

@ldez since you closed the issue and marked as duplicate, where I can find the active issue? The problem doesn't seem to be solved to me. And this is the issue I found by googling. Would be nice to know what to follow and what link to add to our tweak in .golangci.yaml

ldez commented 1 year ago

where I can find the active issue?

There is no active issue because it's not a bug: compilation errors are not bugs.

https://github.com/golangci/golangci-lint/issues/2912#issuecomment-1149995159

wafaking commented 1 year ago

follow your method, resolved my question the same to you, good!

seanlangbrown commented 1 year ago

Hi folks, @ldez, where can we request improvements to the documentation like @Thynix suggested above? https://github.com/golangci/golangci-lint/issues/2912#issuecomment-1324182223

bombsimon commented 1 year ago

Hi folks, @ldez, where can we request improvements to the documentation like @Thynix suggested above? #2912 (comment)

I opened #3460

adamwoolhether commented 1 year ago

so, how to disable it? Anyone know?

results in tons of false positive for embedded objects.

ldez commented 1 year ago

It's not possible to disable the type checking. If you are using CGO you have to check your OS dependencies.

https://github.com/golangci/golangci-lint/issues/2912#issuecomment-1149995159