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 gci #35823

Merged
merged 2 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ def go_deps():
sum = "h1:0rkFMAbn5KBKNpJyHQ6Prb95vIKanmAe62KxsrN+sqA=",
version = "v0.0.0-20171016134553-529a34b1c186",
)
go_repository(
name = "com_github_daixiang0_gci",
build_file_proto_mode = "disable",
importpath = "github.com/daixiang0/gci",
sum = "h1:+EZ83znNs73C9ZBTM7xhNagMP6gJs5wlptiFiuce5BM=",
version = "v0.3.4",
)

go_repository(
name = "com_github_danjacques_gofslock",
build_file_proto_mode = "disable_global",
Expand Down Expand Up @@ -1250,6 +1258,14 @@ def go_deps():
sum = "h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM=",
version = "v1.1.2",
)
go_repository(
name = "com_github_hexops_gotextdiff",
build_file_proto_mode = "disable",
importpath = "github.com/hexops/gotextdiff",
sum = "h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=",
version = "v1.0.3",
)

go_repository(
name = "com_github_hpcloud_tail",
build_file_proto_mode = "disable_global",
Expand Down
7 changes: 3 additions & 4 deletions br/pkg/lightning/backend/kv/sql2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import (
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/mysql" //nolint: goimports
// Import tidb/planner/core to initialize expression.RewriteAstExpr
_ "github.com/pingcap/tidb/planner/core"
Copy link
Contributor

Choose a reason for hiding this comment

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

What if separate init only import-s?

Copy link
Member Author

Choose a reason for hiding this comment

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

if remove //nolint:goimports

[2022-07-03T15:57:37.755Z] br/pkg/lightning/backend/kv/sql2kv.go:36: File is not `goimports`-ed (goimports)

[2022-07-03T15:57:37.755Z] 	"github.com/pingcap/tidb/parser/mysql"

I don't know what is it.

"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
Expand All @@ -42,9 +44,6 @@ import (
"github.com/pingcap/tidb/util/chunk"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

// Import tidb/planner/core to initialize expression.RewriteAstExpr
_ "github.com/pingcap/tidb/planner/core"
)

var ExtraHandleColumnInfo = model.NewExtraHandleColInfo()
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/lightning/backend/local/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import (
"github.com/cockroachdb/pebble"
"github.com/cockroachdb/pebble/sstable"
"github.com/google/uuid"
"github.com/pingcap/tidb/br/pkg/lightning/backend"
"github.com/pingcap/tidb/br/pkg/lightning/log"
"github.com/stretchr/testify/require"

"github.com/pingcap/tidb/br/pkg/lightning/backend"
)

func TestIngestSSTWithClosedEngine(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions br/pkg/lightning/errormanager/errormanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ import (
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/pingcap/errors"
"go.uber.org/multierr"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"

"github.com/pingcap/tidb/br/pkg/lightning/common"
"github.com/pingcap/tidb/br/pkg/lightning/config"
"github.com/pingcap/tidb/br/pkg/lightning/log"
"github.com/pingcap/tidb/br/pkg/redact"
"github.com/pingcap/tidb/br/pkg/utils"
"go.uber.org/multierr"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)

const (
Expand Down
5 changes: 2 additions & 3 deletions br/pkg/lightning/errormanager/errormanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ import (
"testing"

"github.com/DATA-DOG/go-sqlmock"
"github.com/pingcap/tidb/br/pkg/lightning/config"
"github.com/pingcap/tidb/br/pkg/lightning/log"
"github.com/pingcap/tidb/br/pkg/utils"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"

"github.com/pingcap/tidb/br/pkg/lightning/config"
"github.com/pingcap/tidb/br/pkg/utils"
)

func TestInit(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/lightning/mydump/charset_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
"unicode/utf8"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/br/pkg/lightning/config"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/simplifiedchinese"

"github.com/pingcap/tidb/br/pkg/lightning/config"
)

// CharsetConvertor is used to convert a character set to utf8mb4 encoding.
Expand Down
5 changes: 2 additions & 3 deletions br/pkg/lightning/mydump/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/br/pkg/lightning/config"
"github.com/pingcap/tidb/br/pkg/lightning/log"
"github.com/pingcap/tidb/util/filter"
"github.com/pingcap/tidb/util/slice"
"go.uber.org/zap"

"github.com/pingcap/tidb/br/pkg/lightning/config"
"github.com/pingcap/tidb/br/pkg/lightning/log"
)

type SourceType int
Expand Down
7 changes: 3 additions & 4 deletions br/pkg/lightning/restore/restore_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/golang/mock/gomock"
"github.com/pingcap/errors"
filter "github.com/pingcap/tidb/util/table-filter"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/pingcap/tidb/br/pkg/lightning/backend"
"github.com/pingcap/tidb/br/pkg/lightning/checkpoints"
"github.com/pingcap/tidb/br/pkg/lightning/config"
Expand All @@ -39,6 +35,9 @@ import (
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
tmock "github.com/pingcap/tidb/util/mock"
filter "github.com/pingcap/tidb/util/table-filter"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

type restoreSchemaSuite struct {
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/restore/rawkv_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import (
berrors "github.com/pingcap/tidb/br/pkg/errors"
"github.com/pingcap/tidb/br/pkg/restore"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/util/codec"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/rawkv"

"github.com/pingcap/tidb/util/codec"
)

// fakeRawkvClient is a mock for rawkv.client
Expand Down
5 changes: 2 additions & 3 deletions br/pkg/storage/azblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (
"path"
"strings"

"github.com/google/uuid"
"github.com/spf13/pflag"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/google/uuid"
"github.com/pingcap/errors"
backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/pingcap/log"
berrors "github.com/pingcap/tidb/br/pkg/errors"
"github.com/spf13/pflag"
"go.uber.org/zap"
)

Expand Down
1 change: 0 additions & 1 deletion br/pkg/storage/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"

"github.com/pingcap/errors"

berrors "github.com/pingcap/tidb/br/pkg/errors"
)

Expand Down
5 changes: 2 additions & 3 deletions br/pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import (
"github.com/pingcap/errors"
backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/pingcap/log"
"github.com/spf13/pflag"
"go.uber.org/zap"

berrors "github.com/pingcap/tidb/br/pkg/errors"
"github.com/pingcap/tidb/br/pkg/logutil"
"github.com/spf13/pflag"
"go.uber.org/zap"
)

const (
Expand Down
5 changes: 2 additions & 3 deletions br/pkg/stream/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (

"github.com/gogo/protobuf/proto"
"github.com/pingcap/errors"
"github.com/pingcap/log"
"go.uber.org/zap"

backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/pingcap/log"
berrors "github.com/pingcap/tidb/br/pkg/errors"
"github.com/pingcap/tidb/br/pkg/redact"
"github.com/pingcap/tidb/kv"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
)

// MetaDataClient is the client for operations over metadata.
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/stream/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"net/url"
"testing"

berrors "github.com/pingcap/tidb/br/pkg/errors"

"github.com/pingcap/errors"
"github.com/pingcap/log"
berrors "github.com/pingcap/tidb/br/pkg/errors"
"github.com/pingcap/tidb/br/pkg/logutil"
"github.com/pingcap/tidb/br/pkg/storage"
"github.com/pingcap/tidb/br/pkg/stream"
Expand Down
1 change: 0 additions & 1 deletion br/pkg/task/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/pingcap/errors"
backuppb "github.com/pingcap/kvproto/pkg/brpb"

"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/tidb/br/pkg/conn"
"github.com/pingcap/tidb/br/pkg/pdutil"
Expand Down
1 change: 1 addition & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ nogo(
"//build/linter/durationcheck:durationcheck",
"//build/linter/exportloopref:exportloopref",
"//build/linter/gofmt:gofmt",
"//build/linter/gci:gci",
"//build/linter/ineffassign:ineffassign",
"//build/linter/misspell:misspell",
"//build/linter/prealloc:prealloc",
Expand Down
13 changes: 13 additions & 0 deletions build/linter/gci/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "gci",
srcs = ["analysis.go"],
importpath = "github.com/pingcap/tidb/build/linter/gci",
visibility = ["//visibility:public"],
deps = [
"@com_github_daixiang0_gci//pkg/configuration",
"@com_github_daixiang0_gci//pkg/gci",
"@org_golang_x_tools//go/analysis",
],
)
65 changes: 65 additions & 0 deletions build/linter/gci/analysis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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 gci

import (
"fmt"
"sync"

"github.com/daixiang0/gci/pkg/configuration"
"github.com/daixiang0/gci/pkg/gci"
"golang.org/x/tools/go/analysis"
)

// Analyzer is the analyzer struct of gci.
var Analyzer = &analysis.Analyzer{
Name: "gci",
Doc: "Gci controls golang package import order and makes it always deterministic.",
Run: run,
}

func run(pass *analysis.Pass) (any, error) {
fileNames := make([]string, 0, len(pass.Files))
for _, f := range pass.Files {
pos := pass.Fset.PositionFor(f.Pos(), false)
fileNames = append(fileNames, pos.Filename)
}
var rawCfg gci.GciStringConfiguration
rawCfg.Cfg = configuration.FormatterConfiguration{
NoInlineComments: false,
NoPrefixComments: false,
Debug: false,
}
cfg, _ := rawCfg.Parse()
var diffs []string
var lock sync.Mutex
err := gci.DiffFormattedFilesToArray(fileNames, *cfg, &diffs, &lock)
if err != nil {
return nil, err
}

for _, diff := range diffs {
if diff == "" {
continue
}

pass.Report(analysis.Diagnostic{
Pos: 1,
Message: fmt.Sprintf("\n%s", diff),
})
}

return nil, nil
}
12 changes: 12 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@
".*failpoint_binding__.go$": "ignore generated code"
}
},
"gci": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
"/cgo/": "ignore cgo code",
".*\\.pb\\.go$": "generated code",
"/rules_go_work-*": "ignore generated code",
".*test_/testmain\\.go$": "ignore generated code",
".*failpoint_binding__.go$": "ignore generated code",
"util/printer/printer.go": "ignore util/printer code"
}
},
"httpresponse": {
"exclude_files": {
"/external/": "no need to vet third party code",
Expand Down
1 change: 0 additions & 1 deletion cmd/benchraw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/tidb/parser/terror"
"github.com/tikv/client-go/v2/config"
"github.com/tikv/client-go/v2/rawkv"

"go.uber.org/zap"
)

Expand Down
5 changes: 2 additions & 3 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/util"
ddlutil "github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/infoschema"
Expand Down Expand Up @@ -726,7 +725,7 @@ func TestCancelJobByErrorCountLimit(t *testing.T) {

limit := variable.GetDDLErrorCountLimit()
tk.MustExec("set @@global.tidb_ddl_error_count_limit = 16")
err := ddlutil.LoadDDLVars(tk.Session())
err := util.LoadDDLVars(tk.Session())
require.NoError(t, err)
defer tk.MustExec(fmt.Sprintf("set @@global.tidb_ddl_error_count_limit = %d", limit))

Expand All @@ -744,7 +743,7 @@ func TestTruncateTableUpdateSchemaVersionErr(t *testing.T) {

limit := variable.GetDDLErrorCountLimit()
tk.MustExec("set @@global.tidb_ddl_error_count_limit = 5")
err := ddlutil.LoadDDLVars(tk.Session())
err := util.LoadDDLVars(tk.Session())
require.NoError(t, err)
defer tk.MustExec(fmt.Sprintf("set @@global.tidb_ddl_error_count_limit = %d", limit))

Expand Down
4 changes: 1 addition & 3 deletions ddl/table_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/testkit"

"github.com/tikv/client-go/v2/tikv"

"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/tikv"
)

func TestTableSplit(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion distsql/select_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tipb/go-tipb"

"github.com/stretchr/testify/require"
)

Expand Down
Loading