Skip to content

Commit

Permalink
ci: add fmt lint setting for interface{} (#50825)
Browse files Browse the repository at this point in the history
ref #50765
  • Loading branch information
CabinfeverB authored Jan 31, 2024
1 parent 2c25e89 commit 333fc9a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ linters:
- predeclared
- revive
- lll
- gofmt

linters-settings:
staticcheck:
Expand Down Expand Up @@ -389,6 +390,13 @@ linters-settings:
- name: waitgroup-by-value
severity: warning
disabled: false
gofmt:
# https://golangci-lint.run/usage/linters/#gofmt
# disable for faster check
simplify: false
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
issues:
exclude-rules:
- path: _test\.go
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ check: check-bazel-prepare parser_yacc check-parallel lint tidy testSuite errdoc

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

check-static: tools/bin/golangci-lint
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(PACKAGE_DIRECTORIES)) --config .golangci.yml
Expand Down
1 change: 0 additions & 1 deletion br/cmd/br/fips.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

//go:build boringcrypto
// +build boringcrypto

package main

Expand Down
1 change: 0 additions & 1 deletion br/cmd/tidb-lightning-ctl/fips.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

//go:build boringcrypto
// +build boringcrypto

package main

Expand Down
1 change: 0 additions & 1 deletion br/cmd/tidb-lightning/fips.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

//go:build boringcrypto
// +build boringcrypto

package main

Expand Down
7 changes: 5 additions & 2 deletions build/linter/gofmt/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ func run(pass *analysis.Pass) (any, error) {
fileNames = append(fileNames, pos.Filename)
}
}

rules := []gofmt.RewriteRule{{
Pattern: "interface{}",
Replacement: "any",
}}
for _, f := range fileNames {
diff, err := gofmt.Run(f, needSimplify)
diff, err := gofmt.RunRewrite(f, needSimplify, rules)
if err != nil {
return nil, fmt.Errorf("could not run gofmt: %w (%s)", err, f)
}
Expand Down
2 changes: 1 addition & 1 deletion build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
},
"gofmt": {
"exclude_files": {
"pkg/parser/parser.go": "parser/parser.go code",
"pkg/parser/": "parser/*.go code",
"external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
".*mock.go$": "ignore generated code",
Expand Down
1 change: 0 additions & 1 deletion cmd/tidb-server/fips.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

//go:build boringcrypto
// +build boringcrypto

package main

Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type BuildContext interface {
// GetSessionVars gets the session variables.
GetSessionVars() *variable.SessionVars
// SetValue saves a value associated with this context for key.
SetValue(key fmt.Stringer, value interface{})
SetValue(key fmt.Stringer, value any)
// BuiltinFunctionUsageInc increase the counting of each builtin function usage
// Notice that this is a thread safe function
BuiltinFunctionUsageInc(scalarFuncSigName string)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func calcStrsMemUsage(strs map[string]strHandleVal) int64 {
return res
}

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

Expand Down

0 comments on commit 333fc9a

Please sign in to comment.