Skip to content

Commit

Permalink
golangci(lint) : more linters (gin-gonic#2870)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorel-35 authored Sep 21, 2021
1 parent 3a6f18f commit 71f7087
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
version: v1.42.1
args: --verbose
test:
needs: lint
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand Down
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ run:
timeout: 5m
linters:
enable:
- asciicheck
- depguard
- dogsled
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- gofmt
- goimports
- misspell
- nakedret
- nilerr
- nolintlint
- revive
- wastedassign
issues:
exclude-rules:
- linters:
Expand Down
3 changes: 2 additions & 1 deletion binding/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package binding

import (
"errors"
"net/http"
)

Expand All @@ -22,7 +23,7 @@ func (formBinding) Bind(req *http.Request, obj interface{}) error {
if err := req.ParseForm(); err != nil {
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
}
if err := mapForm(obj, req.Form); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func (c *Context) Error(err error) *Error {
panic("err is nil")
}

parsedError, ok := err.(*Error)
var parsedError *Error
ok := errors.As(err, &parsedError)
if !ok {
parsedError = &Error{
Err: err,
Expand Down Expand Up @@ -515,7 +516,7 @@ func (c *Context) initFormCache() {
c.formCache = make(url.Values)
req := c.Request
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)
}
}
Expand Down
3 changes: 1 addition & 2 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import (

"github.com/gin-contrib/sse"
"github.com/gin-gonic/gin/binding"
testdata "github.com/gin-gonic/gin/testdata/protoexample"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"

testdata "github.com/gin-gonic/gin/testdata/protoexample"
)

var _ context.Context = &Context{}
Expand Down
4 changes: 3 additions & 1 deletion recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gin

import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -60,7 +61,8 @@ func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc {
// condition that warrants a panic stack trace.
var brokenPipe bool
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") {
brokenPipe = true
}
Expand Down
3 changes: 1 addition & 2 deletions render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import (
"strings"
"testing"

testdata "github.com/gin-gonic/gin/testdata/protoexample"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"

testdata "github.com/gin-gonic/gin/testdata/protoexample"
)

// TODO unit tests
Expand Down

0 comments on commit 71f7087

Please sign in to comment.