Skip to content

Commit 7a9aae9

Browse files
author
chendelin1982
committed
fix golangci-lint config
1 parent e765250 commit 7a9aae9

File tree

25 files changed

+213
-151
lines changed

25 files changed

+213
-151
lines changed

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,34 @@ lint:
134134
echo "💡 Then add $$(go env GOPATH)/bin to your PATH"; \
135135
exit 1; \
136136
}
137+
@echo "🔧 Verifying golangci-lint configuration..."
138+
@cd core && ( \
139+
for i in 1 2 3; do \
140+
output=$$(golangci-lint config verify --config=.golangci.yml 2>&1); \
141+
exit_code=$$?; \
142+
if [ $$exit_code -eq 0 ]; then \
143+
echo "✅ Configuration verified"; \
144+
break; \
145+
else \
146+
if echo "$$output" | grep -q -i "timeout\|deadline\|network"; then \
147+
if [ $$i -lt 3 ]; then \
148+
echo "⚠️ Network timeout on attempt $$i/3, retrying in 2 seconds..."; \
149+
sleep 2; \
150+
else \
151+
echo "❌ Config verification failed after 3 attempts due to network timeout"; \
152+
echo "💡 Please check your internet connection or try again later"; \
153+
exit 1; \
154+
fi \
155+
else \
156+
echo "❌ Config verification failed:"; \
157+
echo "$$output"; \
158+
exit 1; \
159+
fi \
160+
fi \
161+
done \
162+
)
163+
@echo ""
164+
@echo "🔍 Running lint checks..."
137165
@cd core && golangci-lint run --timeout=5m --config=.golangci.yml
138166
@echo "✅ Linting completed"
139167
@echo ""

core/.golangci.yml

Lines changed: 101 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# golangci-lint configuration for apprun project
2-
# Compatible with golangci-lint v2.7.2
3-
# Documentation: https://golangci-lint.run/product/config
2+
# Schema Version: v2.7.2
3+
# Documentation: Based on https://golangci-lint.run/jsonschema/golangci.v2.7.jsonschema.json
44

55
version: "2"
66

@@ -11,101 +11,113 @@ run:
1111
- integration
1212

1313
linters:
14+
default: "none"
1415
enable:
16+
- bodyclose
17+
- dupl
1518
- errcheck
19+
- errorlint
20+
- gocritic
21+
- gocyclo
22+
- gosec
1623
- govet
1724
- ineffassign
18-
- staticcheck
19-
- unused
2025
- misspell
21-
- dupl
22-
- gosec
23-
- unconvert
2426
- prealloc
25-
- gocyclo
26-
- gocritic
27-
- errorlint
28-
- bodyclose
29-
30-
settings:
31-
errcheck:
32-
check-type-assertions: true
33-
check-blank: true
34-
35-
govet:
36-
enable:
37-
- all
38-
disable:
39-
- shadow
40-
- fieldalignment
41-
42-
misspell:
43-
locale: US
44-
45-
dupl:
46-
threshold: 150
47-
48-
gosec:
49-
config:
50-
global:
51-
nosec: false
52-
audit: true
53-
54-
staticcheck:
55-
checks:
56-
- all
57-
58-
gocyclo:
59-
min-complexity: 20
60-
61-
gocritic:
62-
enabled-tags:
63-
- diagnostic
64-
- style
65-
- performance
66-
disabled-checks:
67-
- unnamedResult
68-
- commentFormatting
69-
- httpNoBody
70-
- octalLiteral
71-
- paramTypeCombine
72-
- equalFold
73-
- exitAfterDefer
27+
- staticcheck
28+
- unconvert
29+
- unused
7430

75-
issues:
76-
exclude-dirs:
77-
- ent
78-
- docs
79-
80-
exclude-generated-strict: true
81-
82-
exclude-rules:
83-
- path: cmd/
84-
linters:
85-
- errcheck
86-
87-
- linters:
88-
- errcheck
89-
text: "Error return value of.*WithContext"
90-
91-
- linters:
92-
- errcheck
93-
text: "Error return value of.*logger\\.Sync"
94-
95-
- linters:
96-
- gosec
97-
text: "G302"
31+
settings:
32+
govet:
33+
enable:
34+
- nilness
35+
- shadow
36+
disable:
37+
- fieldalignment
9838

99-
- linters:
100-
- gocritic
101-
text: "exitAfterDefer"
39+
gosec:
40+
excludes:
41+
- G104
42+
- G304
43+
44+
gocyclo:
45+
min-complexity: 20
46+
47+
dupl:
48+
threshold: 150
49+
50+
misspell:
51+
locale: US
52+
53+
errcheck:
54+
check-type-assertions: true
55+
check-blank: true
56+
57+
staticcheck:
58+
checks: ["all"]
59+
60+
gocritic:
61+
enabled-tags:
62+
- diagnostic
63+
- style
64+
- performance
65+
disabled-checks:
66+
- unnamedResult
67+
- commentFormatting
68+
- httpNoBody
69+
- octalLiteral
70+
- paramTypeCombine
71+
- equalFold
72+
- exitAfterDefer
73+
74+
exclusions:
75+
generated: strict
10276

103-
- path: _test\.go
104-
linters:
105-
- dupl
106-
- gosec
107-
- errcheck
108-
- gocyclo
109-
77+
paths:
78+
- "^ent/"
79+
- "^docs/"
80+
81+
rules:
82+
# Exclude cmd/ from errcheck
83+
- path: "cmd/"
84+
linters:
85+
- errcheck
86+
87+
# Specific error suppressions
88+
- linters:
89+
- errcheck
90+
text: "Error return value of.*WithContext"
91+
92+
- linters:
93+
- errcheck
94+
text: "Error return value of.*logger\\.Sync"
95+
96+
- linters:
97+
- errcheck
98+
text: "Error return value of.*DeleteConfig"
99+
100+
- linters:
101+
- errcheck
102+
text: "Error return value of.*Setenv"
103+
104+
- linters:
105+
- gosec
106+
text: "G302"
107+
108+
- linters:
109+
- gocritic
110+
text: "exitAfterDefer"
111+
112+
# Test file exclusions
113+
- path: "_test\\.go"
114+
linters:
115+
- dupl
116+
- gosec
117+
- errcheck
118+
- gocyclo
119+
120+
issues:
110121
max-issues-per-linter: 50
111122
max-same-issues: 3
123+
uniq-by-line: true

core/cmd/server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func run() error {
9898
return err
9999
}
100100
defer func() {
101-
if err := dbClient.Close(); err != nil {
102-
log.Printf("⚠️ Warning: Failed to close database connection: %v", err)
101+
if closeErr := dbClient.Close(); closeErr != nil {
102+
log.Printf("⚠️ Warning: Failed to close database connection: %v", closeErr)
103103
}
104104
}()
105105
log.Println("✅ Database connected")

core/handlers/demo_handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package handlers provides HTTP request handlers for the application.
2+
// It includes demo handlers for testing and reference implementations.
13
package handlers
24

35
import (

core/handlers/handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package handlers provides HTTP request handlers for the application.
12
package handlers
23

34
// TODO: Implement handlers using net/http

core/internal/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package config defines the configuration types and structures for the application.
12
package config
23

34
// Config is the root define source of all configuration items

core/internal/middleware/language.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package middleware provides HTTP middleware components for request processing,
2+
// including language detection and internationalization support.
13
package middleware
24

35
import (

core/modules/config/bootstrap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package config provides the configuration management module,
2+
// including service initialization, dynamic configuration loading,
3+
// and integration with the configuration center database.
14
package config
25

36
import (

core/modules/config/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package config provides HTTP handlers for configuration management endpoints.
12
package config
23

34
import (

core/modules/config/handler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ poc:
462462
// 删除后仍可能从配置文件或默认值返回,所以不检查 404
463463
// 只验证不再是我们设置的值
464464
if w.Code == http.StatusOK {
465-
var response GetConfigResponse
466-
err := json.NewDecoder(w.Body).Decode(&response)
465+
var resp GetConfigResponse
466+
err := json.NewDecoder(w.Body).Decode(&resp)
467467
require.NoError(t, err)
468468
// 验证返回的是默认值,而不是我们设置的值
469-
assert.NotEqual(t, testValue, response.Value)
469+
assert.NotEqual(t, testValue, resp.Value)
470470
}
471471
})
472472
}

0 commit comments

Comments
 (0)