Skip to content

Commit 333fc9a

Browse files
authored
ci: add fmt lint setting for interface{} (pingcap#50825)
ref pingcap#50765
1 parent 2c25e89 commit 333fc9a

File tree

10 files changed

+17
-10
lines changed

10 files changed

+17
-10
lines changed

.golangci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ linters:
2525
- predeclared
2626
- revive
2727
- lll
28+
- gofmt
2829

2930
linters-settings:
3031
staticcheck:
@@ -389,6 +390,13 @@ linters-settings:
389390
- name: waitgroup-by-value
390391
severity: warning
391392
disabled: false
393+
gofmt:
394+
# https://golangci-lint.run/usage/linters/#gofmt
395+
# disable for faster check
396+
simplify: false
397+
rewrite-rules:
398+
- pattern: 'interface{}'
399+
replacement: 'any'
392400
issues:
393401
exclude-rules:
394402
- path: _test\.go

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ check: check-bazel-prepare parser_yacc check-parallel lint tidy testSuite errdoc
4444

4545
fmt:
4646
@echo "gofmt (simplify)"
47-
@gofmt -s -l -w $(FILES) 2>&1 | $(FAIL_ON_STDOUT)
47+
@gofmt -s -l -w -r 'interface{} -> any' $(FILES) 2>&1 | $(FAIL_ON_STDOUT)
4848

4949
check-static: tools/bin/golangci-lint
5050
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(PACKAGE_DIRECTORIES)) --config .golangci.yml

br/cmd/br/fips.go

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
//go:build boringcrypto
16-
// +build boringcrypto
1716

1817
package main
1918

br/cmd/tidb-lightning-ctl/fips.go

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
//go:build boringcrypto
16-
// +build boringcrypto
1716

1817
package main
1918

br/cmd/tidb-lightning/fips.go

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
//go:build boringcrypto
16-
// +build boringcrypto
1716

1817
package main
1918

build/linter/gofmt/analyzer.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ func run(pass *analysis.Pass) (any, error) {
4545
fileNames = append(fileNames, pos.Filename)
4646
}
4747
}
48-
48+
rules := []gofmt.RewriteRule{{
49+
Pattern: "interface{}",
50+
Replacement: "any",
51+
}}
4952
for _, f := range fileNames {
50-
diff, err := gofmt.Run(f, needSimplify)
53+
diff, err := gofmt.RunRewrite(f, needSimplify, rules)
5154
if err != nil {
5255
return nil, fmt.Errorf("could not run gofmt: %w (%s)", err, f)
5356
}

build/nogo_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
},
259259
"gofmt": {
260260
"exclude_files": {
261-
"pkg/parser/parser.go": "parser/parser.go code",
261+
"pkg/parser/": "parser/*.go code",
262262
"external/": "no need to vet third party code",
263263
".*_generated\\.go$": "ignore generated code",
264264
".*mock.go$": "ignore generated code",

cmd/tidb-server/fips.go

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
//go:build boringcrypto
16-
// +build boringcrypto
1716

1817
package main
1918

pkg/expression/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type BuildContext interface {
8282
// GetSessionVars gets the session variables.
8383
GetSessionVars() *variable.SessionVars
8484
// SetValue saves a value associated with this context for key.
85-
SetValue(key fmt.Stringer, value interface{})
85+
SetValue(key fmt.Stringer, value any)
8686
// BuiltinFunctionUsageInc increase the counting of each builtin function usage
8787
// Notice that this is a thread safe function
8888
BuiltinFunctionUsageInc(scalarFuncSigName string)

pkg/kv/key.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func calcStrsMemUsage(strs map[string]strHandleVal) int64 {
464464
return res
465465
}
466466

467-
func calcIntsMemUsage(ints map[int64]interface{}) int64 {
467+
func calcIntsMemUsage(ints map[int64]any) int64 {
468468
return int64(len(ints)) * (size.SizeOfInt64 + size.SizeOfInterface)
469469
}
470470

0 commit comments

Comments
 (0)