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

*: enable mirror linter #43644

Merged
merged 8 commits into from
May 9, 2023
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 DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ def go_deps():
sum = "h1:QvrO2QF2+/Cx1WA/vETCIYBKtRjc30vesdoPUNo1EbY=",
version = "v0.1.1",
)
go_repository(
name = "com_github_butuzov_mirror",
build_file_proto_mode = "disable",
importpath = "github.com/butuzov/mirror",
sum = "h1:AOFqNeGL+3znnsBptNI4PNKT1IpzTD+95vY7bsMM1pg=",
version = "v0.1.2",
)

go_repository(
name = "com_github_cakturk_go_netstat",
build_file_proto_mode = "disable",
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/utils/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ParseKey(format, key string) ([]byte, error) {
// Ref PD: https://github.com/pingcap/pd/blob/master/tools/pd-ctl/pdctl/command/region_command.go#L334
func unescapedKey(text string) ([]byte, error) {
var buf []byte
r := bytes.NewBuffer([]byte(text))
r := bytes.NewBufferString(text)
for {
c, err := r.ReadByte()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ nogo(
"//build/linter/gosec",
"//build/linter/ineffassign",
"//build/linter/makezero",
"//build/linter/mirror",
"//build/linter/misspell",
"//build/linter/noloopclosure",
"//build/linter/prealloc",
Expand Down
12 changes: 12 additions & 0 deletions build/linter/mirror/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "mirror",
srcs = ["analyzer.go"],
importpath = "github.com/pingcap/tidb/build/linter/mirror",
visibility = ["//visibility:public"],
deps = [
"//build/linter/util",
"@com_github_butuzov_mirror//:mirror",
],
)
27 changes: 27 additions & 0 deletions build/linter/mirror/analyzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mirror

import (
"github.com/butuzov/mirror"
"github.com/pingcap/tidb/build/linter/util"
)

// Analyzer is the analyzer struct of mirror.
var Analyzer = mirror.NewAnalyzer()

func init() {
util.SkipAnalyzer(Analyzer)
}
9 changes: 9 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,15 @@
".*_generated\\.go$": "ignore generated code"
}
},
"mirror": {
"exclude_files": {
"parser/parser.go": "parser/parser.go code",
"/cgo/": "ignore cgo code",
"external/": "no need to vet third party code",
"tools/": "ignore tools code",
".*_generated\\.go$": "ignore generated code"
}
},
"misspell": {
"exclude_files": {
"parser/parser.go": "parser/parser.go code",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/aws/aws-sdk-go v1.44.48
github.com/bazelbuild/buildtools v0.0.0-20230317132445-9c3c1fc0106e
github.com/blacktear23/go-proxyprotocol v1.0.6
github.com/butuzov/mirror v0.1.2
github.com/carlmjohnson/flagext v0.21.0
github.com/charithe/durationcheck v0.0.10
github.com/cheggaaa/pb/v3 v3.0.8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ github.com/blacktear23/go-proxyprotocol v1.0.6 h1:eTt6UMpEnq59NjON49b3Cay8Dm0sCs
github.com/blacktear23/go-proxyprotocol v1.0.6/go.mod h1:FSCbgnRZrQXazBLL5snfBbrcFSMtcmUDhSRb9OfFA1o=
github.com/bmatcuk/doublestar/v2 v2.0.4 h1:6I6oUiT/sU27eE2OFcWqBhL1SwjyvQuOssxT4a1yidI=
github.com/bmatcuk/doublestar/v2 v2.0.4/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQmTZRptLie8RgRw=
github.com/butuzov/mirror v0.1.2 h1:AOFqNeGL+3znnsBptNI4PNKT1IpzTD+95vY7bsMM1pg=
github.com/butuzov/mirror v0.1.2/go.mod h1:8wpO6gP+57XaZ4BF6pFeZ8UwaXFxdjoaEObe710+8hM=
github.com/carlmjohnson/flagext v0.21.0 h1:/c4uK3ie786Z7caXLcIMvePNSSiH3bQVGDvmGLMme60=
github.com/carlmjohnson/flagext v0.21.0/go.mod h1:Eenv0epIUAr4NuedNmkzI8WmBmjIxZC239XcKxYS2ac=
github.com/cenk/backoff v2.0.0+incompatible/go.mod h1:7FtoeaSnHoZnmZzz47cM35Y9nSW7tNyaidugnHTaFDE=
Expand Down
12 changes: 6 additions & 6 deletions parser/auth/caching_sha2.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func hashCrypt(plaintext string, salt []byte, iterations int, hash func([]byte)

// 1, 2, 3
bufA := bytes.NewBuffer(make([]byte, 0, 4096))
bufA.Write([]byte(plaintext))
bufA.WriteString(plaintext)
bufA.Write(salt)

// 4, 5, 6, 7, 8
bufB := bytes.NewBuffer(make([]byte, 0, 4096))
bufB.Write([]byte(plaintext))
bufB.WriteString(plaintext)
bufB.Write(salt)
bufB.Write([]byte(plaintext))
bufB.WriteString(plaintext)
sumB := hash(bufB.Bytes())
bufB.Reset()

Expand All @@ -95,7 +95,7 @@ func hashCrypt(plaintext string, salt []byte, iterations int, hash func([]byte)
// 11
for i = len(plaintext); i > 0; i >>= 1 {
if i%2 == 0 {
bufA.Write([]byte(plaintext))
bufA.WriteString(plaintext)
} else {
bufA.Write(sumB[:])
}
Expand All @@ -108,7 +108,7 @@ func hashCrypt(plaintext string, salt []byte, iterations int, hash func([]byte)
// 13, 14, 15
bufDP := bufA
for range []byte(plaintext) {
bufDP.Write([]byte(plaintext))
bufDP.WriteString(plaintext)
}
sumDP := hash(bufDP.Bytes())
bufDP.Reset()
Expand Down Expand Up @@ -170,7 +170,7 @@ func hashCrypt(plaintext string, salt []byte, iterations int, hash func([]byte)
buf := bytes.NewBuffer(make([]byte, 0, 100))
buf.Write([]byte{'$', 'A', '$'})
rounds := fmt.Sprintf("%03d", iterations/ITERATION_MULTIPLIER)
buf.Write([]byte(rounds))
buf.WriteString(rounds)
buf.Write([]byte{'$'})
buf.Write(salt)

Expand Down
2 changes: 1 addition & 1 deletion session/txninfo/txn_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ var columnValueGetterMap = map[string]func(*TxnInfo) types.Datum{
first := true
for tblID := range relatedTableIDs {
if !first {
str.Write([]byte(","))
str.WriteString(",")
} else {
first = false
}
Expand Down
2 changes: 1 addition & 1 deletion types/json_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func appendBinaryNumber(buf []byte, x json.Number) (JSONTypeCode, []byte, error)
// - Then uint64 (valid in MySQL JSON, not in JSON decode library)
// - Then float64
// - Return an error
if strings.ContainsAny(string(x), "Ee.") {
if strings.Contains(x.String(), "Ee.") {
f64, err := x.Float64()
if err != nil {
return JSONTypeCodeFloat64, nil, errors.Trace(err)
Expand Down
2 changes: 1 addition & 1 deletion types/json_binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func quoteJSONString(s string) string {
i++
}
} else {
c, size := utf8.DecodeRune([]byte(s[i:]))
c, size := utf8.DecodeRuneInString(s[i:])
if c == utf8.RuneError && size == 1 { // refer to codes of `binary.jsonMarshalStringTo`
if start < i {
ret.WriteString(s[start:i])
Expand Down