-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Upgraded to 1.57.0, all my "nolint" comments are not working (contextcheck) #4550
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
Comments
I can give more examples of the |
Hello, I don't reproduce your problem: package main
import (
"bytes"
"os"
)
type ServerConn struct{}
func (c ServerConn) Stor(path string, buffer *bytes.Buffer) error {
return nil
}
// UploadFileToFTP uploads a file to an FTP server
func UploadFileToFTP(client *ServerConn, filePath, targetPath string) error {
contents, err := os.ReadFile(filePath) //nolint:gosec // This is a local file
if err != nil {
return err
}
return client.Stor(targetPath, bytes.NewBuffer(contents))
} $ golangci-lint run
WARN [config_reader] The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.
WARN [config_reader] The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`.
WARN [config_reader] The configuration option `output.format` is deprecated, please use `output.formats`
WARN [config_reader] The configuration option `govet.check-shadowing` is deprecated. Please enable `shadow` instead, if you are not using `enable-all`.
main.go:8:6: exported: exported type ServerConn should have comment or be unexported (revive)
type ServerConn struct{}
^
main.go:10:1: exported: exported method ServerConn.Stor should have comment or be unexported (revive)
func (c ServerConn) Stor(path string, buffer *bytes.Buffer) error {
^
main.go:1:1: package-comments: should have a package comment (revive)
package main
^ |
I found some strange issues with If I leave
Also my code base is private, and lots of code, so i'm sorry about the example but it's probably somewhere else that is affecting it |
I disabled |
Can you provide a reproducible example? (a link to a public repo can be useful) |
Can you provide an extract of the code related to |
This is the function that it is referencing, but I cannot spot the issue. package config
import (
"context"
"fmt"
"github.com/mrz1836/go-cachestore"
)
// NewWriteLock will take care of creating a lock and defer
func NewWriteLock(ctx context.Context, lockKey string, cacheStore cachestore.LockService, ttl int64) (func(), error) {
if ttl <= 0 {
ttl = DefaultCacheLockTTL
}
secret, err := cacheStore.WriteLock(ctx, lockKey, ttl)
return func() {
// context is not set, since the req could be canceled, but unlocking should never be stopped
_, _ = cacheStore.ReleaseLock(context.Background(), lockKey, secret)
}, err
} |
Do you have a caller example of |
I'm able to reproduce the problem: it's a bug inside package config
import (
"context"
"github.com/mrz1836/go-cachestore"
)
const DefaultCacheLockTTL = 0
// NewWriteLock will take care of creating a lock and defer
func NewWriteLock(ctx context.Context, lockKey string, cacheStore cachestore.LockService, ttl int64) (func(), error) {
if ttl <= 0 {
ttl = DefaultCacheLockTTL
}
secret, err := cacheStore.WriteLock(ctx, lockKey, ttl)
return func() {
// context is not set, since the req could be canceled, but unlocking should never be stopped
_, _ = cacheStore.ReleaseLock(context.Background(), lockKey, secret)
}, err
}
func Foo() {
lock, err := NewWriteLock(context.Background(), "", nil, 12)
if err != nil {
return
}
lock()
} $ golangci-lint run
WARN [config_reader] The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.
WARN [config_reader] The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`.
WARN [config_reader] The configuration option `output.format` is deprecated, please use `output.formats`
WARN [config_reader] The configuration option `govet.check-shadowing` is deprecated. Please enable `shadow` instead, if you are not using `enable-all`.
WARN [runner] Can't process result by autogenerated_exclude processor: can't filter issue result.Issue{FromLinter:"contextcheck", Text:"Function `NewWriteLock$1` should pass the context parameter", Severity:"", SourceLines:[]string(nil), Replacement:(*result.Replacement)(nil), Pkg:(*packages.Package)(0xc0012e6f00), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"", Offset:0, Line:0, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}: no file path for issue
WARN [runner] Can't process result by nolint processor: can't filter issue result.Issue{FromLinter:"contextcheck", Text:"Function `NewWriteLock$1` should pass the context parameter", Severity:"", SourceLines:[]string(nil), Replacement:(*result.Replacement)(nil), Pkg:(*packages.Package)(0xc0012e6f00), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"", Offset:0, Line:0, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}: no file path for issue
WARN [runner/source_code] Failed to get line 0 for file : failed to get file lines cache: can't get file bytes from cache: can't read file : open : no such file or directory
main.go:1:1: package-comments: should have a package comment (revive)
package config
^
main.go:9:7: exported: exported const DefaultCacheLockTTL should have comment or be unexported (revive)
const DefaultCacheLockTTL = 0
^
main.go:23:1: exported: exported function Foo should have comment or be unexported (revive)
func Foo() {
^
:0: Function `NewWriteLock$1` should pass the context parameter (contextcheck) |
I changed this line and the warning issue went away: From: To: So I got the warning to go away, but it looks like the |
Can you open an issue on https://github.com/kkHAIKE/contextcheck/issues? I will create a fix inside golangci-lint about reports without filepath. |
I have same issue after upgrade to version 1.57.0. No one Information about my environment
Error:
FullLogger implementation package middleware
import (...)
type dbWriter func(context.Context, *model.Log) error
func FullLogger(l logrus.FieldLogger, db dbWriter) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
...
go func(writer dbWriter, log *model.Log, reqID string) {...}(db, &model.Log{...}, requestID)
...
next.ServeHTTP(w, r)
})
}
} Call FullLogger: package main
import (
localMiddleware ".../middleware"
"github.com/go-chi/chi/v5"
)
func main() {
r := chi.NewRouter()
r.Use(localMiddleware.FullLogger(logger, srv.Log.Create))
} Implementation of func (srv *Service) Create(ctx context.Context, log *model.Log) error {
...
return srv.db.Create(ctx, log)
} With version 1.56.2 all works fine. |
I will provide a fix in a few minutes. |
The fix: #4552 |
I also created a fix for |
I created a new bugfix release: https://github.com/golangci/golangci-lint/releases/tag/v1.57.1 Sponsoring is a good way to sustain open source maintainers: sponsor me |
Welcome
Description of the problem
Upgraded my golangci-lint via brew to the latest version. I use this in 20+ projects and have used it for a long time. After upgrading and running, several nolint directives are not working.
Version of golangci-lint
Configuration
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
Validation
The text was updated successfully, but these errors were encountered: