Questions tagged [golangci-lint]

32 questions
13
votes
1 answer

Is it really bad to use init() functions in Go?

I started a new go projects a few days ago, and I use golangci-lint to make my code in good style. I found gochecknoinits is one of linters of golangci-lint, and it tells me not to use init. In my opinion, I can put simple initial code in init for…
Neo Li
  • 213
  • 1
  • 2
  • 9
6
votes
1 answer

golangci-lint gives unseen errors after reinstalling

I upgraded the version of go to go1.18.3, following the instruction on https://go.dev/doc/install: rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin Then I tried to run a Makefile for my…
instant501
  • 195
  • 1
  • 10
5
votes
0 answers

golangci-lint undeclared name: `getProxyURL` (typecheck)

Im new on golang and Im trying to _test my proxy func, the test passes correctly but when running golangci it gives me the error: undeclared name: getProxyURL (typecheck) if got := getProxyURL(tt.args.campaignCode, urls); got != tt.want { ^ func…
Ryke
  • 51
  • 3
4
votes
2 answers

How to check if a public go function/struct is not used outside of the package?

Is there a way to check if a public function/struct is used outside of the package in which it's declared? I'm not writing a public go module that's consumed anywhere else, and simply want to scan whether func Foo() it's used anywhere in my codebase…
asaf92
  • 1,557
  • 1
  • 19
  • 30
3
votes
2 answers

How do you remove unused imports using GolangCI

I enabled goimports in my GolangCI tool using my makefile and it's able to spot unused imports but is not automatically remove them. How do I enable my golangCI tool to remove the unused imports automatically? Below is my makefile command for the…
Mabel Oza
  • 557
  • 8
  • 22
3
votes
2 answers

Can't install golangci-lint locally

I'm using RHEL 8.6 and my Go version is the following: $ go version go version go1.18.3 linux/amd64 I'm trying to install locally golangci-lint and none of the described ways in the documentation are working. What I tried: First: $ curl -sSfL…
Andressa Cabistani
  • 463
  • 1
  • 5
  • 14
3
votes
1 answer

How to run file watcher in virtual environment in GoLand?

I have enabled golangci-lint file watcher in GoLand but when I save file I got error like below one: msg="Running error: context loading failed: no go files to analyze" After some debugging I found that this error comes when I run golangci-lint…
3
votes
3 answers

golang linter always complains

Q: How do I resolve this madness between the ireturn and nolintlint linters? Details: I have a Golang function with this signature func NewClientCredentialsTokenSource( issuer string, clientId string, clientSecret string, scope…
HairOfTheDog
  • 2,489
  • 2
  • 29
  • 35
2
votes
1 answer

missing cases in switch of type parsing.tokenType on golinter

So I have this code token := NextToken() switch token.Typ { case tokenEOF: return nil case tokenMentionTargetedControl: # do stuff default: return nil } my tokentype is a enum my golinter is throwing this error: missing cases in switch…
Raul Quinzani
  • 493
  • 1
  • 4
  • 16
2
votes
1 answer

Go line-length-linter: How to ignore one line?

I get this warning: main.go:72: line is 191 characters (lll) klog.Fatalf("no ...") //nolint:lll I added nolint:lll, but this does not silence this warning. We use https://golangci-lint.run/ I want to ignore this line only (no global…
guettli
  • 25,042
  • 81
  • 346
  • 663
2
votes
1 answer

golangci-lint not showing errors on vscode

I'm trying to integrate golangci-lint with vscode. This is my settings file in vscode "go.lintTool": "golangci-lint", "go.lintFlags": ["--fast"], "go.liveErrors": { "enabled": true, "delay": 500 }, "go.lintOnSave": "workspace", …
tmp dev
  • 8,043
  • 16
  • 53
  • 108
2
votes
0 answers

err: exit status 1: stderr: go: updates to go.mod needed, disabled by -mod=readonly; to update it:

I have added multiple root packages in Visual Studio Code and defined the dependencies and packages properly. When I build my code I am not getting any compiler errors and I am able to run the application. There is no issue in compiling and running…
Madhusudhan
  • 103
  • 1
  • 1
  • 9
1
vote
0 answers

Golang lint rule to require launching a goroutine with a recover

I want to create a go lint rule that requires all goroutines to be launched with a wrapper function that can recover from a crash on the goroutine (this will also take an onRecover callback that will cancel context of request). The pain point I am…
D. Maul
  • 341
  • 2
  • 11
1
vote
0 answers

Lint check for assignments to a range element field

A common Go programming error we've seen is: for _, item := range items { item.SomeField = value // oops } As range copies the value, assigning to the struct field effectively does nothing. The correct way is to use the index:…
TrueWill
  • 25,132
  • 10
  • 101
  • 150
1
vote
1 answer

could not load export data: cannot import error in golanglint

I see new error in prow job could not load export data: cannot import "github.com/IBM/ibmcloud-volume-interface/lib/utils/reasoncode" (unknown bexport format version -1…
ambikanair
  • 4,004
  • 11
  • 43
  • 83
1
2 3