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

Add analyze_types config option for forbidigo #3802

Closed
4 tasks done
sbrownjc opened this issue Apr 25, 2023 · 2 comments
Closed
4 tasks done

Add analyze_types config option for forbidigo #3802

sbrownjc opened this issue Apr 25, 2023 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@sbrownjc
Copy link

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc.).
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

In v1.4.0 forbidigo added the ability to analyze import types and match regardless of the aliased import name, however this requires a new config flag to be set to true: analyze_types.

forbidigo was updated to 1.4.0 in golangci-lint v1.51.2, but the required flag does not appear to be supported.

Can we add that flag?

Expected output:

main.go:8:2: use of `log.Warn` forbidden because "do not use logrus, instead use slog" (forbidigo)
        log.Warn("Hello")
main.go:8:11: use of `log.Entry.Info` forbidden because "do not use logrus, instead use slog" (forbidigo)
	}).Info("A walrus appears")

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.52.2 built with go1.19.8 from (unknown, mod sum: "h1:FrPElUUI5rrHXg1mQ7KxI1MXPAw5lBVskiz7U7a8a1A=") on (unknown)

Configuration file

$ cat .golangci.yml
---
linters:
  disable-all: true
  enable:
    - forbidigo

linters-settings:
  forbidigo:
    analyze-types: true
    forbid:
      - '{p: "^logrus\\.(Debug|Error|Fatal|Info|Panic|Print|Println|Trace|Warn|Warning)f?$", msg: "do not use logrus, instead use slog"}'
      - '{p: "^\\*?logrus.Entry\\.(Debug|Error|Fatal|Info|Panic|Print|Println|Trace|Warn|Warning)f?$", msg: "do not use logrus, instead use slog"}'

Go environment

$ go version && go env
go version go1.19.8 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/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.19.8"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/src/github.com/<Company>/<repo>/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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1372520807=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /go/src/github.com/<Company>/<repo> /go/src/github.com/<Company> /go/src/github.com /go/src /go / /root] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 1 linters: [forbidigo]    
INFO [loader] Go packages loading at mode 575 (compiled_files|name|types_sizes|deps|exports_file|files|imports) took 20.89445497s 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 20.132798ms 
INFO [linters_context/goanalysis] analyzers took 18.042039ms with top 10 stages: forbidigo: 18.042039ms 
WARN [runner] Can't run linter forbidigo: forbidigo: failed to create linter "forbidigo": parsing as JSON or YAML failed: yaml: unmarshal errors:
  line 1: field pkg not found in type forbidigo.pattern 
INFO [runner] processing took 2.031µs with stages: max_same_issues: 400ns, skip_dirs: 268ns, nolint: 203ns, filename_unadjuster: 124ns, cgo: 118ns, autogenerated_exclude: 93ns, exclude-rules: 92ns, fixer: 92ns, skip_files: 91ns, identifier_marker: 90ns, path_prettifier: 89ns, path_prefixer: 84ns, max_from_linter: 58ns, sort_results: 31ns, diff: 31ns, path_shortener: 31ns, source_code: 30ns, exclude: 27ns, max_per_file_from_linter: 27ns, severity-rules: 26ns, uniq_by_line: 26ns 
INFO [runner] linters took 175.963204ms with stages: forbidigo: 175.941496ms 
ERRO Running error: 1 error occurred:
        * can't run linter forbidigo: forbidigo: failed to create linter "forbidigo": parsing as JSON or YAML failed: yaml: unmarshal errors:
  line 1: field pkg not found in type forbidigo.pattern
 
INFO Memory: 212 samples, avg is 33.8MB, max is 168.6MB 
INFO Execution took 21.096143903s

Code example or link to a public repository

package main

import (
	log "github.com/sirupsen/logrus"
)

func main() {
	log.Warn("Hello")
	log.WithFields(log.Fields{
		"animal": "walrus",
	}).Info("A walrus appears")
}
@sbrownjc sbrownjc added the bug Something isn't working label Apr 25, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 25, 2023

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

@sbrownjc
Copy link
Author

My apologies. I had searched for existing issues, but then found this PR which will address this one.

@ldez ldez added duplicate This issue or pull request already exists and removed bug Something isn't working labels Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants