50 questions
0
votes
0
answers
76
views
golangci-lint forbidgo for `Times(1)` is does not correctly match the function call
forbidigo:
forbid:
- pattern: Times\(1\)
msg: "No need to specify Times(1) for a single call."
The above forbidgo rule, still lets the code below pass! What is going ...
0
votes
1
answer
882
views
can't run linter goanalysis_metalinter: failed to load package environment
If golangci-lint gives you an error like this, what can I do to fix it?
ERRO Running error: can't run linter goanalysis_metalinter
buildir: failed to load package environment: could not load export ...
-2
votes
1
answer
146
views
Correct re-use of context.WithTimeout in golang?
First the code I have:
for last < end {
// HERE the linter is complaining with:
// nested context in loop (fatcontext)
ctx, cancel = context.WithTimeout(...
1
vote
2
answers
579
views
golangci-lint results differ for the exact same file
I have a fork of the Polygon Edge software, developed in Go v1.20. The project uses golangci-lint in its GitHub Actions workflows. I enabled golangci-lint but first ran it manually on both the ...
2
votes
0
answers
358
views
VSCode doesn't show golangci-linter errors
I can't see the linter errors as problems in VS Code.
Here is my setup:
I am using VS Code without a .golangci.yml config file. Golangci-linter is installed and works. I can run golangci-lint run --...
1
vote
1
answer
320
views
Specify path to golangci-lint executable in vsCode Go extension
I'm working on a shared Go repo. The repo includes a committed executable for golangci-lint, so that we can all run the same exact version of the linter on local machines and on CI.
I'm also using the ...
1
vote
1
answer
475
views
VSCode does not do auto formatting on save - Go
I am working on a Go project and using VSCode as an IDE. I have installed the official Go extensions and configured my settings in such a way as to have a formatting onSave while coding.
My settings....
2
votes
1
answer
367
views
What is the idiomatic method and style of combining two slices in go?
When combining two slices, e.g. fruit and vegetables, to create a third, e.g. food. it would seem to make sense to append fruit and vegetable and assign the result directly to food.
golangci-lint's ...
0
votes
1
answer
772
views
Different result in linting errors in GitHub Actions and locally
I am working on a project. Here are my config files.
.github/workflows/linting.yaml
name: Go Lint CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
...
1
vote
0
answers
473
views
Golangci unparam linter not working in VS code
I have enabled unparam linter in my config but its not detecting any warnings for my code
This shows for unparam when I run golangci-lint linters:
Enabled by your configuration linters: unparam: ...
2
votes
0
answers
94
views
Finding scope level using Golang Analysis package
I am having trouble finding scope level using the Go Analyze package.
Given an example.go
package main
import "log"
var myglobalvar = "hello from global"
func myLog(format ...
2
votes
0
answers
262
views
Is there a golangci-lint rule that checks for local variables only on specific functions?
I am aware of shadowing checks from govet but I am looking for something more specific.
I am looking for a golangci-lint plugin that allows us to force local variables on specific functions.
Ideally, ...
2
votes
0
answers
2k
views
Is there a way for golangci-lint to only analyze changes
I have a big code repository on self-hosted gitlab, which always costs about 15 minutes to run golangci-lint.
Is there a way for golangci-lint to only analyze code changes in merge request?
I know --...
1
vote
0
answers
53
views
Get correct token position in golangci-lint private plugin
Created a custom plugin for golangci-lint linter which just verifies imports in the go.mod file against the whitelisted ones. Now, if linter finds a disallowed dependency it reports:
goModPath := ...
0
votes
1
answer
83
views
Go vet Sprinf checking number of arguments
I’ve found an interesting behavior of go vet with Sprintf which I would not expect (it’s
inside the lint check).
Could you explain me why go vet is not throwing a violation in the second numbered case ...
0
votes
0
answers
355
views
punctuation mark in Golang
I'm working on a Golang text editor but i have an issue when solving for punctuation the requirement is as follow.
The punctuation mark ' will always be found with another instance of it and they ...
0
votes
1
answer
167
views
GolangCI Not Removing Unused Imports
For some reason my GolangCI is able to identify unused imports but not able to remove them. This is my GolangCI file used to remove unused import statements, I did specify remove-unused as true:
run:
...
0
votes
1
answer
109
views
I can't import local packages in my go project
folder structure:
- myproject
- resolver
- resolver.go
- main.go
go mod init github.com/kaleabbyh/foodrecipie
resolver.go:
package resolvers
import "fmt"
func resolverfunc(){
...
1
vote
0
answers
664
views
Getting the error "can't load fmt" - golangci-lint
I installed golangci-lint using the link
# binary will be $(go env GOPATH)/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go ...
3
votes
0
answers
661
views
VS Code doesn't detect unhandled errors written in GO
VSCode doesn't show a warning on unhandled error.
I've got this line of code:
defer resp.Body.Close()
which is market as unhandled error in GOLAND IDE but in VSCode I don't get similar nice
warning as ...
2
votes
2
answers
3k
views
Where can I find the documentation for SyscallN, since syscall.Syscall6 has been deprecated as of Go 1.18?
When I run golangci-lint on my Go code after changing the go value in my go.mod from go 1.16 to go 1.20, I now get this linter warning:
windows.go:210:16: SA1019: syscall.Syscall6 has been deprecated ...
1
vote
0
answers
251
views
Dynamic vscode settings for linting config?
At work, we have a shared golangci configuration that lives in a github repo, github.com/github/go-linter.
I'm trying to figure out how best to share that configuration across many go repos. I've ...
2
votes
0
answers
482
views
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 ...
0
votes
2
answers
201
views
How to detect error values that are never used [closed]
I'm looking for a way to to find occurrences of this error "handling" that doesn't do anything with the first error:
example:
func handler() {
var myErr error
myErr = doSomething() //...
3
votes
1
answer
2k
views
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 ...
1
vote
0
answers
372
views
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 ...
1
vote
1
answer
891
views
Golang list indirect dependencies for a dependency in go.mod file
Is there a way we can list down the indirect dependencies of a dependency in go lang go.mod file.
For example in go.mod:
require (
github.com/blang/semver/v4 v4.0.0
github.com/fatih/structtag ...
5
votes
2
answers
3k
views
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 ...
2
votes
1
answer
6k
views
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 ("u\x01\x00\x00\...
2
votes
1
answer
1k
views
golangci-lint complains on SQL rows not closed, despite it is closed from a goroutine
I am using golangci-lint as part of my CI/CD. It is complaining on SQL rows not being closed, despite it is being closed from a goroutine:
....
rows, err := ...
...
go ...
0
votes
1
answer
153
views
Is there a script to fix opentelemetry lint errors?
When running the make golint target in opentelemetry-collector-contrib, sometimes a lint error will appear. It seems like the kind of lint-check which could be easily fixed as well, but make gofmt ...
9
votes
1
answer
25k
views
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/...
4
votes
3
answers
1k
views
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 ...
1
vote
1
answer
167
views
Deletion of metrics not working kubernetes operator controller
I have been working on my operator where I have some of the custom metric setting the values and that works fine (registration and displaying the metric value). The problem is that metric deletion isn'...
-1
votes
1
answer
2k
views
A persistent warning when using //nolint:godox in Golang
WARN [runner/nolint] Found unknown linters in //nolint directives: godox todo: fix once roles are in place
This warning keeps coming up when I am building my Golang project. What does this mean?
...
-1
votes
1
answer
636
views
Why 'go vet' failing with go build.... signal: killed error?
We are using The Kubernetes executor for GitLab Runner, as part of GitLab CI
Go vet is failing with error--go build github.com/hashicorp/cdktf-provider-aws-go/aws/v9/wafv2: /usr/local/go/pkg/tool/...
2
votes
1
answer
4k
views
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"],
"...
5
votes
0
answers
1k
views
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....
4
votes
0
answers
4k
views
golangci-lint error go imports error computing diff
I´m trying to use golangci-lint with vscode, however when i run it, the following error occurs
level=warning msg="[runner] Can't run linter goanalysis_metalinter: goimports: error computing diff:...
1
vote
0
answers
2k
views
golangci-lint: exec: "git": executable file not found in $PATH
I'm trying to integrate golangci-lint on my project. I use golangci-lint v1.49.0 that I install from snap. I've added ci config on my project but when I try to run it, it throws a very bizarre error.
$...
1
vote
1
answer
2k
views
/../usr/local/go/src/runtime/cgo/cgo.go:34:8: could not import C (cgo preprocessing failed) (typecheck)
Note:
current version of Go - 1.17.13
current version of golangci-lint - 1.45.2
I am getting the same error `could not import C (cgo preprocessing failed) (typecheck) no matter which version of ...
0
votes
1
answer
247
views
GoLang Level3 embedded struct initialisation
I am new to Golang development. I was trying to initialize a struct which has a level 3 embedded struct. I can create till 2 levels, but when I try with level 3, it gives me this compile time error.
...
4
votes
0
answers
6k
views
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 ...
5
votes
4
answers
23k
views
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 ...
6
votes
1
answer
5k
views
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:/...
3
votes
1
answer
487
views
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 ...
0
votes
1
answer
1k
views
Variable is being used but Golang lint complaining that the variable is not being used
Below is the code snippet where i have declared a for loop and getting index and box from the array of boxes. I am using the same index below in the if else block, but the golangci-lint is complaining ...
9
votes
3
answers
7k
views
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 ...
74
votes
2
answers
46k
views
Implicit memory aliasing in for loop
I'm using golangci-lint and I'm getting an error on the following code:
versions []ObjectDescription
... (populate versions) ...
for i, v := range versions {
res := createWorkerFor(&v)
.....
21
votes
1
answer
20k
views
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 ...