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

Enable several gocritic checks; resolve identified issues #1728

Merged

Conversation

alexandear
Copy link
Contributor

The PR enables temporarily disabled httpNoBody, initClause, paramTypeCombine, typeUnparen checks from gocritic linter and fixes up lint issues.

❯ golangci-lint run
fs.go:1353:1: paramTypeCombine: func(filePath string, fileEncoding string) (*fsFile, error) could be replaced with func(filePath, fileEncoding string) (*fsFile, error) (gocritic)
func (h *fsHandler) compressAndOpenFSFile(filePath string, fileEncoding string) (*fsFile, error) {
^
fs.go:1535:1: paramTypeCombine: func(filePath string, fileEncoding string) (*fsFile, error) could be replaced with func(filePath, fileEncoding string) (*fsFile, error) (gocritic)
func (h *fsHandler) newCompressedFSFile(filePath string, fileEncoding string) (*fsFile, error) {
^
header.go:1433:1: paramTypeCombine: func(key []byte, value []byte) could be replaced with func(key, value []byte) (gocritic)
func (h *ResponseHeader) setNonSpecial(key []byte, value []byte) {
^
header.go:1492:1: paramTypeCombine: func(key []byte, value []byte) could be replaced with func(key, value []byte) (gocritic)
func (h *RequestHeader) setNonSpecial(key []byte, value []byte) {
^
http.go:1204:1: paramTypeCombine: func(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error could be replaced with func(r *bufio.Reader, maxBodySize int, getOnly, preParseMultipartForm bool) error (gocritic)
func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error {
^
http.go:1222:1: paramTypeCombine: func(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error could be replaced with func(r *bufio.Reader, maxBodySize int, getOnly, preParseMultipartForm bool) error (gocritic)
func (req *Request) readBodyStream(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error {
^
http.go:1313:1: paramTypeCombine: func(r *bufio.Reader, contentLength int, maxBodySize int) (err error) could be replaced with func(r *bufio.Reader, contentLength, maxBodySize int) (err error) (gocritic)
func (req *Request) ReadBody(r *bufio.Reader, contentLength int, maxBodySize int) (err error) {
^
http.go:2245:1: paramTypeCombine: func(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ([]byte, error) could be replaced with func(r *bufio.Reader, contentLength, maxBodySize int, dst []byte) ([]byte, error) (gocritic)
func readBody(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ([]byte, error) {
^
http.go:2254:1: paramTypeCombine: func(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) (b []byte, err error) could be replaced with func(r *bufio.Reader, contentLength, maxBodySize int, dst []byte) (b []byte, err error) (gocritic)
func readBodyWithStreaming(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) (b []byte, err error) {
^
server.go:685:1: paramTypeCombine: func(key any, value any) could be replaced with func(key, value any) (gocritic)
func (ctx *RequestCtx) SetUserValue(key any, value any) {
^
status.go:166:1: paramTypeCombine: func(dst []byte, protocol []byte, statusCode int, statusText []byte) []byte could be replaced with func(dst, protocol []byte, statusCode int, statusText []byte) []byte (gocritic)
func formatStatusLine(dst []byte, protocol []byte, statusCode int, statusText []byte) []byte {
^
userdata.go:14:1: paramTypeCombine: func(key any, value any) could be replaced with func(key, value any) (gocritic)
func (d *userData) Set(key any, value any) {
^
client_timing_test.go:168:15: httpNoBody: http.NoBody should be preferred to the nil request body (gocritic)
                req, err := http.NewRequest(MethodGet, fmt.Sprintf("http://foobar%d.com/aaa/bbb", atomic.AddUint32(&nn, 1)), nil)
                            ^
client_timing_test.go:553:15: httpNoBody: http.NoBody should be preferred to the nil request body (gocritic)
                req, err := http.NewRequest(MethodGet, url, nil)
                            ^
http_test.go:2661:10: typeUnparen: could simplify chan (int) to chan int (gocritic)
        read    chan (int)
                ^
http_test.go:2662:10: typeUnparen: could simplify chan (struct{}) to chan struct{} (gocritic)
        cb      chan (struct{})
                ^
prefork/prefork.go:213:3: initClause: consider to move `exitedProcs++` before if (gocritic)
                if exitedProcs++; exitedProcs > p.RecoverThreshold {
                ^

@alexandear alexandear changed the title Enable few gocritic checks; fix up issues Enable several gocritic checks; resolve identified issues Mar 1, 2024
@erikdubbelboer erikdubbelboer merged commit 3166afd into valyala:master Mar 2, 2024
15 checks passed
@erikdubbelboer
Copy link
Collaborator

Great, thanks!

@alexandear alexandear deleted the gocritic-enable-few-checks branch March 2, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants