feat: 配置 golangci-lint 静态分析并修复存量违规
- 新增 backend/.golangci.yml 配置 12 个 linter(forbidigo、errorlint、errcheck、staticcheck、revive、gocritic、gosec、bodyclose、noctx、nilerr、goimports、gocyclo) - 新增 lefthook.yml 配置 pre-commit hook 自动运行 lint - 修复存量代码违规:errors.Is/As 替换、zap.Error 替换、import 排序、errcheck 修复 - 更新 README 补充编码规范说明 - 归档 backend-code-lint 变更
This commit is contained in:
@@ -7,10 +7,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"nex/backend/internal/domain"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"nex/backend/internal/domain"
|
||||
)
|
||||
|
||||
type mockStatsRepo struct {
|
||||
@@ -58,8 +58,10 @@ func TestStatsBuffer_Increment(t *testing.T) {
|
||||
|
||||
var count int64
|
||||
buffer.counters.Range(func(key, value interface{}) bool {
|
||||
counter := value.(*int64)
|
||||
count += atomic.LoadInt64(counter)
|
||||
counter, ok := value.(*int64)
|
||||
if ok {
|
||||
count += atomic.LoadInt64(counter)
|
||||
}
|
||||
return true
|
||||
})
|
||||
assert.Equal(t, int64(3), count)
|
||||
@@ -82,8 +84,10 @@ func TestStatsBuffer_ConcurrentIncrement(t *testing.T) {
|
||||
|
||||
var count int64
|
||||
buffer.counters.Range(func(key, value interface{}) bool {
|
||||
counter := value.(*int64)
|
||||
count = atomic.LoadInt64(counter)
|
||||
counter, ok := value.(*int64)
|
||||
if ok {
|
||||
count = atomic.LoadInt64(counter)
|
||||
}
|
||||
return true
|
||||
})
|
||||
assert.Equal(t, int64(100), count)
|
||||
@@ -161,8 +165,10 @@ func TestStatsBuffer_SwapInt64(t *testing.T) {
|
||||
|
||||
var beforeCount int64
|
||||
buffer.counters.Range(func(key, value interface{}) bool {
|
||||
counter := value.(*int64)
|
||||
beforeCount = atomic.LoadInt64(counter)
|
||||
counter, ok := value.(*int64)
|
||||
if ok {
|
||||
beforeCount = atomic.LoadInt64(counter)
|
||||
}
|
||||
return true
|
||||
})
|
||||
assert.Equal(t, int64(2), beforeCount)
|
||||
@@ -171,8 +177,10 @@ func TestStatsBuffer_SwapInt64(t *testing.T) {
|
||||
|
||||
var afterCount int64
|
||||
buffer.counters.Range(func(key, value interface{}) bool {
|
||||
counter := value.(*int64)
|
||||
afterCount = atomic.LoadInt64(counter)
|
||||
counter, ok := value.(*int64)
|
||||
if ok {
|
||||
afterCount = atomic.LoadInt64(counter)
|
||||
}
|
||||
return true
|
||||
})
|
||||
assert.Equal(t, int64(0), afterCount)
|
||||
@@ -190,8 +198,10 @@ func TestStatsBuffer_FailRetry(t *testing.T) {
|
||||
|
||||
var count int64
|
||||
buffer.counters.Range(func(key, value interface{}) bool {
|
||||
counter := value.(*int64)
|
||||
count = atomic.LoadInt64(counter)
|
||||
counter, ok := value.(*int64)
|
||||
if ok {
|
||||
count = atomic.LoadInt64(counter)
|
||||
}
|
||||
return true
|
||||
})
|
||||
assert.Equal(t, int64(2), count)
|
||||
|
||||
Reference in New Issue
Block a user