Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add fmt lint setting for interface{} #50825

Merged
merged 8 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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