golangci(lint) : more linters (#2870)

This commit is contained in:
Matthieu MOREL 2021-09-21 09:22:21 +02:00 committed by GitHub
parent 3a6f18f32f
commit 71f7087097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 8 deletions

View File

@ -24,6 +24,7 @@ jobs:
version: v1.42.1 version: v1.42.1
args: --verbose args: --verbose
test: test:
needs: lint
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-latest]

View File

@ -2,9 +2,22 @@ run:
timeout: 5m timeout: 5m
linters: linters:
enable: enable:
- asciicheck
- depguard
- dogsled
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- gofmt - gofmt
- goimports
- misspell - misspell
- nakedret
- nilerr
- nolintlint
- revive - revive
- wastedassign
issues: issues:
exclude-rules: exclude-rules:
- linters: - linters:

View File

@ -5,6 +5,7 @@
package binding package binding
import ( import (
"errors"
"net/http" "net/http"
) )
@ -22,7 +23,7 @@ func (formBinding) Bind(req *http.Request, obj interface{}) error {
if err := req.ParseForm(); err != nil { if err := req.ParseForm(); err != nil {
return err return err
} }
if err := req.ParseMultipartForm(defaultMemory); err != nil && err != http.ErrNotMultipart { if err := req.ParseMultipartForm(defaultMemory); err != nil && !errors.Is(err, http.ErrNotMultipart) {
return err return err
} }
if err := mapForm(obj, req.Form); err != nil { if err := mapForm(obj, req.Form); err != nil {

View File

@ -220,7 +220,8 @@ func (c *Context) Error(err error) *Error {
panic("err is nil") panic("err is nil")
} }
parsedError, ok := err.(*Error) var parsedError *Error
ok := errors.As(err, &parsedError)
if !ok { if !ok {
parsedError = &Error{ parsedError = &Error{
Err: err, Err: err,
@ -515,7 +516,7 @@ func (c *Context) initFormCache() {
c.formCache = make(url.Values) c.formCache = make(url.Values)
req := c.Request req := c.Request
if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil { if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil {
if err != http.ErrNotMultipart { if !errors.Is(err, http.ErrNotMultipart) {
debugPrint("error on parse multipart form array: %v", err) debugPrint("error on parse multipart form array: %v", err)
} }
} }

View File

@ -23,10 +23,9 @@ import (
"github.com/gin-contrib/sse" "github.com/gin-contrib/sse"
"github.com/gin-gonic/gin/binding" "github.com/gin-gonic/gin/binding"
testdata "github.com/gin-gonic/gin/testdata/protoexample"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
testdata "github.com/gin-gonic/gin/testdata/protoexample"
) )
var _ context.Context = &Context{} var _ context.Context = &Context{}

View File

@ -6,6 +6,7 @@ package gin
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -60,7 +61,8 @@ func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc {
// condition that warrants a panic stack trace. // condition that warrants a panic stack trace.
var brokenPipe bool var brokenPipe bool
if ne, ok := err.(*net.OpError); ok { if ne, ok := err.(*net.OpError); ok {
if se, ok := ne.Err.(*os.SyscallError); ok { var se *os.SyscallError
if errors.As(ne, &se) {
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") { if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
brokenPipe = true brokenPipe = true
} }

View File

@ -14,10 +14,9 @@ import (
"strings" "strings"
"testing" "testing"
testdata "github.com/gin-gonic/gin/testdata/protoexample"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
testdata "github.com/gin-gonic/gin/testdata/protoexample"
) )
// TODO unit tests // TODO unit tests