contextcheck icon indicating copy to clipboard operation
contextcheck copied to clipboard

Flagging non-buggy and legal code

Open bentcoder opened this issue 2 years ago • 3 comments

Hi,

I don't understand why this code should be flagged. Any explanation or realistic reason would be appreciated for going deep to raise the flag.

Thanks

// github.com/go-chi/chi/v5
// parameter is set as normal using `"/{id}"`

func find(w http.ResponseWriter, r *http.Request) {
   id := chi.URLParam(r, "id")
}
Function `URLParam->URLParam` should pass the context parameter (contextcheck)
	id := chi.URLParam(r, "id")

Using:

  • golangci-lint has version 1.49.0

bentcoder avatar Jan 28 '23 14:01 bentcoder

I don't get similar output.

source:

package chitst

import (
  "net/http"
  "github.com/go-chi/chi/v5"
)

func find(w http.ResponseWriter, r *http.Request) {
   id := chi.URLParam(r, "id")
   _ = id
}

can you share the complete code?

kkHAIKE avatar Feb 04 '23 13:02 kkHAIKE

I've got a similar issue: the linter tells me to pass context to the function without any parameters.

Function `Close[staff-transactions/internal/queries/pg.ReviseReportPaymentsRow]->Close->close[T]->close` should pass the context parameter (contextcheck) 
for rows.Next() {
	select {
	case <-ctx.Done():
		err = rows.Close() //nolint:contextcheck
		if err != nil {
			// ...
		}
		return
	default:
		// ...
	}
}

golangci-lint version v1.55.1

wawan93 avatar Mar 06 '24 10:03 wawan93

I've got a similar issue: the linter tells me to pass context to the function without any parameters.

Function `Close[staff-transactions/internal/queries/pg.ReviseReportPaymentsRow]->Close->close[T]->close` should pass the context parameter (contextcheck) 
for rows.Next() {
	select {
	case <-ctx.Done():
		err = rows.Close() //nolint:contextcheck
		if err != nil {
			// ...
		}
		return
	default:
		// ...
	}
}

golangci-lint version v1.55.1

You can add //nolint:contextcheck in the comment of the Close method you specified for this case, please refer to README.md.

kkHAIKE avatar Mar 10 '24 02:03 kkHAIKE