Skip to content

Issues in gqlgen resolvers are ignored #4506

Closed
@bnavetta

Description

@bnavetta

Welcome

Description of the problem

I'm using gqlgen to implement a GraphQL server. It autogenerates stubs for GraphQL endpoints, in *.resolver.go files. Even though the stubs are autogenerated, the files have non-autogenerated code.

golangci-lint run ignores issues in these files. Based on the verbose output, I think they're getting filtered out by the autogenerated_exclude processor.

Each resolver file has a comment like this:

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.27

I think that's triggering the rule here, even though the rest of the file isn't autogenerated.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.56.2 built with go1.22.0 from 58a724a on 2024-02-15T12:52:06Z

Configuration

run:
linters:
  enable:
    - gocritic
    - exhaustruct
linters-settings:
  exhaustruct:
    exclude:
      - '.+/graph\.Config$'
      - '.+/graphql\.FieldContext$'
      - '.+/graphql\.Response$'

Go environment

$ go version && go env
go version go1.22.1 darwin/arm64
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/ben/Library/Caches/go-build'
GOENV='/Users/ben/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/ben/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/ben/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/ben/src/gqlgen-linting/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/vx/hb7qrv412lnbfgmqn9rpwc200000gn/T/go-build1658647304=/tmp/go-build -gno-record-gcc-switches -fno-common'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/ben/src/gqlgen-linting /Users/ben/src /Users/ben /Users /]
INFO [config_reader] Used config file .golangci.yaml
INFO [lintersdb] Active 8 linters: [errcheck exhaustruct gocritic gosimple govet ineffassign staticcheck unused]
INFO [loader] Go packages loading at mode 575 (compiled_files|exports_file|name|deps|files|imports|types_sizes) took 144.178708ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 2.938416ms
INFO [linters_context/goanalysis] analyzers took 3.379248363s with top 10 stages: buildir: 2.373889789s, inspect: 125.784248ms, fact_deprecated: 103.66313ms, fact_purity: 100.208455ms, ctrlflow: 96.994997ms, printf: 92.911998ms, nilness: 77.548118ms, SA5012: 77.15329ms, typedness: 68.571036ms, gocritic: 24.120708ms
INFO [runner] Issues before processing: 1, after processing: 0
INFO [runner] Processors filtering stat (out/in): cgo: 1/1, skip_files: 1/1, path_prettifier: 1/1, skip_dirs: 1/1, filename_unadjuster: 1/1, autogenerated_exclude: 0/1
INFO [runner] processing took 61.588µs with stages: autogenerated_exclude: 27.625µs, path_prettifier: 24.625µs, skip_dirs: 4.501µs, cgo: 625ns, nolint: 625ns, max_same_issues: 416ns, max_from_linter: 376ns, fixer: 375ns, severity-rules: 334ns, filename_unadjuster: 333ns, exclude-rules: 292ns, uniq_by_line: 292ns, skip_files: 209ns, exclude: 209ns, identifier_marker: 167ns, source_code: 167ns, path_shortener: 126ns, diff: 125ns, sort_results: 83ns, max_per_file_from_linter: 42ns, path_prefixer: 41ns
INFO [runner] linters took 1.274062792s with stages: goanalysis_metalinter: 1.273950375s
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 16 samples, avg is 212.5MB, max is 366.9MB
INFO Execution took 1.427133584s
Running `exhaustruct` directly:
$ exhaustruct -e '.+/graph\.Config$' -e '.+/graphql\.FieldContext$' -e '.+/graphql\.Response$' ./...
/Users/ben/src/gqlgen-linting/graph/schema.resolvers.go:21:11: model.Todo is missing fields ID, Done, User

A minimal reproducible example or link to a public repository

See https://github.com/bnavetta/gqlgen-linting

The code that should be reported is here: https://github.com/bnavetta/gqlgen-linting/blob/2f18e1ecca7cffa1030a12aa10d5af4e1ce49de4/graph/schema.resolvers.go#L21-L24

Validation

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions