chore: fix lint
parent
27f3083195
commit
a4188fd5c6
|
@ -1,10 +1,12 @@
|
|||
run:
|
||||
timeout: 2m
|
||||
tests: false
|
||||
skip-dirs:
|
||||
- ".*test.*"
|
||||
- ".*mock.*"
|
||||
- ".*generated.*"
|
||||
- ".*example.*"
|
||||
- ".*utils.*"
|
||||
skip-files:
|
||||
- ".*Mock.*"
|
||||
- ".*_mock.*"
|
||||
|
@ -16,6 +18,7 @@ output:
|
|||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
# Default
|
||||
- errcheck
|
||||
- gosimple
|
||||
- govet
|
||||
|
@ -23,31 +26,30 @@ linters:
|
|||
- staticcheck
|
||||
- typecheck
|
||||
- unused
|
||||
# Custom
|
||||
- errchkjson
|
||||
- errname
|
||||
- errorlint
|
||||
- execinquery
|
||||
- forcetypeassert
|
||||
- gocritic
|
||||
- goerr113
|
||||
- gofumpt
|
||||
- gomodguard
|
||||
- gosec
|
||||
- importas
|
||||
- makezero
|
||||
- nilnil
|
||||
- prealloc
|
||||
- reassign
|
||||
# - rowserrcheck
|
||||
- sqlclosecheck
|
||||
- unconvert
|
||||
# - wastedassign
|
||||
fast: true
|
||||
|
||||
linters-settings:
|
||||
gosec:
|
||||
excludes:
|
||||
- G101
|
||||
- G112
|
||||
- G402
|
||||
- G404
|
||||
- G501
|
||||
- G505
|
||||
exclude-generated: true
|
||||
# Default
|
||||
govet:
|
||||
check-shadowing: false
|
||||
disable-all: true
|
||||
|
@ -67,9 +69,17 @@ linters-settings:
|
|||
- unmarshal
|
||||
- unreachable
|
||||
- unusedresult
|
||||
staticcheck:
|
||||
checks: ["all", "-SA1019"]
|
||||
# Custom
|
||||
gocritic:
|
||||
disabled-checks:
|
||||
- ifElseChain
|
||||
- singleCaseSwitch
|
||||
enabled-tags:
|
||||
- diagnostic
|
||||
- style
|
||||
- performance
|
||||
gosec:
|
||||
exclude-generated: true
|
||||
reassign:
|
||||
patterns:
|
||||
- ".*"
|
||||
|
|
|
@ -36,6 +36,8 @@ var (
|
|||
ErrEmptyImport = errors.New("empty import")
|
||||
ErrGoModNotExist = errors.New("go mod not exist")
|
||||
ErrGoModEmptyModule = errors.New("go mod empty module")
|
||||
ErrNotBytesBuffer = errors.New("not bytes.Buffer")
|
||||
ErrNotDSTGenDecl = errors.New("not dst.GenDecl")
|
||||
)
|
||||
|
||||
// https://pkg.go.dev/sync#Pool
|
||||
|
@ -78,7 +80,6 @@ func NewFormmater(opts ...FormatterOptionFn) (*Formatter, error) {
|
|||
for _, stdPackage := range stdPackages {
|
||||
ft.stdPackages[stdPackage.PkgPath] = struct{}{}
|
||||
}
|
||||
// ft.log("NewFormmater: stdPackages: %+v\n", ft.stdPackages)
|
||||
|
||||
ft.moduleNames = make(map[string]string)
|
||||
ft.formattedPaths = make(map[string]struct{})
|
||||
|
@ -280,8 +281,12 @@ func (ft *Formatter) formatImports(
|
|||
// First update
|
||||
dstFile.Imports = formattedDSTImportSpecs
|
||||
|
||||
genSpecs := dstFile.Decls[0].(*dst.GenDecl).Specs
|
||||
formattedGenSpecs := make([]dst.Spec, 0, len(genSpecs))
|
||||
genDecl, ok := dstFile.Decls[0].(*dst.GenDecl)
|
||||
if !ok {
|
||||
return nil, ErrNotDSTGenDecl
|
||||
}
|
||||
|
||||
formattedGenSpecs := make([]dst.Spec, 0, len(genDecl.Specs))
|
||||
|
||||
// Append all imports first
|
||||
for _, importSpec := range formattedDSTImportSpecs {
|
||||
|
@ -289,7 +294,7 @@ func (ft *Formatter) formatImports(
|
|||
}
|
||||
|
||||
// Append all non imports later
|
||||
for _, genSpec := range genSpecs {
|
||||
for _, genSpec := range genDecl.Specs {
|
||||
if _, ok := genSpec.(*dst.ImportSpec); !ok {
|
||||
formattedGenSpecs = append(formattedGenSpecs, genSpec)
|
||||
continue
|
||||
|
@ -297,9 +302,12 @@ func (ft *Formatter) formatImports(
|
|||
}
|
||||
|
||||
// Second update
|
||||
dstFile.Decls[0].(*dst.GenDecl).Specs = formattedGenSpecs
|
||||
genDecl.Specs = formattedGenSpecs
|
||||
|
||||
b := bufPool.Get().(*bytes.Buffer)
|
||||
b, ok := bufPool.Get().(*bytes.Buffer)
|
||||
if !ok {
|
||||
return nil, ErrNotBytesBuffer
|
||||
}
|
||||
b.Reset()
|
||||
defer bufPool.Put(b)
|
||||
|
||||
|
|
Loading…
Reference in New Issue