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