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

*: cleanup lint tools #1956

Merged
merged 2 commits into from
Nov 19, 2019
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
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,8 @@ static: export GO111MODULE=on
static:
@ # Not running vet and fmt through metalinter becauase it ends up looking at vendor
gofmt -s -l $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(GOCHECKER)
./scripts/retool do govet --shadow $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(GOCHECKER)

CGO_ENABLED=0 ./scripts/retool do golangci-lint run --disable-all --deadline 120s \
--enable misspell \
--enable staticcheck \
--enable ineffassign \
--enable unconvert \
$$($(PACKAGE_DIRECTORIES))
CGO_ENABLED=0 ./scripts/retool do golangci-lint run --enable misspell --disable errcheck --deadline 120s $$($(PACKAGE_DIRECTORIES))

lint:
@echo "linting"
Expand Down
11 changes: 0 additions & 11 deletions pkg/btree/btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
package btree

import (
"fmt"
"io"
"sort"
"strings"
"sync"
)

Expand Down Expand Up @@ -741,14 +738,6 @@ func (n *node) iterate(dir direction, start, stop Item, includeStart bool, hit b
return hit, true
}

// Used for testing/debugging purposes.
func (n *node) print(w io.Writer, level int) {
fmt.Fprintf(w, "%sNODE:%v, %v\n", strings.Repeat(" ", level), n.items, n.indices)
for _, c := range n.children {
c.print(w, level+1)
}
}

// BTree is an implementation of a B-Tree.
//
// BTree stores Item instances in an ordered structure, allowing easy insertion,
Expand Down
4 changes: 1 addition & 3 deletions pkg/mock/mockhbstream/mockhbstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ func (s HeartbeatStream) Send(m *pdpb.RegionHeartbeatResponse) error {
}

// SendMsg is used to send the message.
func (s HeartbeatStream) SendMsg(region *core.RegionInfo, msg *pdpb.RegionHeartbeatResponse) {
return
}
func (s HeartbeatStream) SendMsg(region *core.RegionInfo, msg *pdpb.RegionHeartbeatResponse) {}

// Recv mocks method.
func (s HeartbeatStream) Recv() *pdpb.RegionHeartbeatResponse {
Expand Down
8 changes: 2 additions & 6 deletions server/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,10 @@ func (r *RegionsInfo) GetRegions() []*RegionInfo {
func (r *RegionsInfo) GetStoreRegions(storeID uint64) []*RegionInfo {
regions := make([]*RegionInfo, 0, r.GetStoreLeaderCount(storeID)+r.GetStoreFollowerCount(storeID))
if leaders, ok := r.leaders[storeID]; ok {
for _, region := range leaders.scanRanges() {
regions = append(regions, region)
}
regions = append(regions, leaders.scanRanges()...)
}
if followers, ok := r.followers[storeID]; ok {
for _, region := range followers.scanRanges() {
regions = append(regions, region)
}
regions = append(regions, followers.scanRanges()...)
}
return regions
}
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func CreateScheduler(typ string, opController *OperatorController, storage *core
func FindSchedulerTypeByName(name string) string {
var typ string
for registerdType := range schedulerMap {
if strings.Index(name, registerdType) != -1 {
if strings.Contains(name, registerdType) {
if len(registerdType) > len(typ) {
typ = registerdType
}
Expand Down
1 change: 0 additions & 1 deletion server/schedulers/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ type testBalanceLeaderRangeSchedulerSuite struct {
ctx context.Context
cancel context.CancelFunc
tc *mockcluster.Cluster
lb schedule.Scheduler
oc *schedule.OperatorController
}

Expand Down
3 changes: 1 addition & 2 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const (
// HotWriteRegionType is hot write region scheduler type.
HotWriteRegionType = "hot-write-region"
minFlowBytes = 128 * 1024
minScoreLimit = 0.35
)

// BalanceType : the perspective of balance
Expand Down Expand Up @@ -533,7 +532,7 @@ func (h *balanceHotRegionsScheduler) GetHotWriteStatus() *statistics.StoreHotPee
func (h *balanceHotRegionsScheduler) GetStoresScore() map[uint64]float64 {
h.RLock()
defer h.RUnlock()
storesScore := make(map[uint64]float64, 0)
storesScore := make(map[uint64]float64)
for _, info := range h.scoreInfos.ToSlice() {
storesScore[info.GetStoreID()] = info.GetScore()
}
Expand Down
6 changes: 2 additions & 4 deletions server/schedulers/scatter_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,8 @@ func (l *scatterRangeScheduler) Schedule(cluster opt.Cluster) []*operator.Operat
}

type scatterRangeHandler struct {
scheduleName string
storage *core.Storage
rd *render.Render
config *scatterRangeSchedulerConfig
rd *render.Render
config *scatterRangeSchedulerConfig
}

func (handler *scatterRangeHandler) UpdateConfig(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions server/schedulers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func NewScoreInfos() *ScoreInfos {
// Add adds a scoreInfo into the slice.
func (s *ScoreInfos) Add(scoreInfo *ScoreInfo) {
infosLen := len(s.scoreInfos)
if s.isSorted == true && infosLen != 0 && s.scoreInfos[infosLen-1].score > scoreInfo.score {
if s.isSorted && infosLen != 0 && s.scoreInfos[infosLen-1].score > scoreInfo.score {
s.isSorted = false
}
s.scoreInfos = append(s.scoreInfos, scoreInfo)
Expand Down Expand Up @@ -297,7 +297,7 @@ func AggregateScores(storesStats []*ScoreInfos, weights []float64) *ScoreInfos {
num = len(weights)
}

scoreMap := make(map[uint64]float64, 0)
scoreMap := make(map[uint64]float64)
for i := 0; i < num; i++ {
scoreInfos := storesStats[i]
for _, info := range scoreInfos.ToSlice() {
Expand Down
2 changes: 2 additions & 0 deletions server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func NewTestServer(c *check.C) (*Server, CleanupFunc, error) {
cfg := NewTestSingleConfig(c)
s, err := CreateServer(cfg)
if err != nil {
cancel()
return nil, nil, err
}
if err = s.Run(ctx); err != nil {
cancel()
return nil, nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions tests/server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (s *serverTestSuite) TestReconnect(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(3, func(conf *config.Config) {
conf.TickInterval = typeutil.Duration{50 * time.Millisecond}
conf.ElectionInterval = typeutil.Duration{250 * time.Millisecond}
conf.TickInterval = typeutil.Duration{Duration: 50 * time.Millisecond}
conf.ElectionInterval = typeutil.Duration{Duration: 250 * time.Millisecond}
})
c.Assert(err, IsNil)
defer cluster.Destroy()
Expand Down
4 changes: 0 additions & 4 deletions tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"Repository": "github.com/mgechev/revive",
"Commit": "7773f47324c2bf1c8f7a5500aff2b6c01d3ed73b"
},
{
"Repository": "github.com/dnephin/govet",
"Commit": "4a96d43e39d340b63daa8bc5576985aa599885f6"
},
{
"Repository": "github.com/pingcap/failpoint/failpoint-ctl",
"Commit": "30cc7431d99c6a7f2836387d4bb255a3bd6a5e0a"
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-analysis/analysis/parse_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Interpreter interface {
}

// CompileRegex is to provide regexp for transfer counter.
func (TransferCounter) CompileRegex(operator string) (*regexp.Regexp, error) {
func (c *TransferCounter) CompileRegex(operator string) (*regexp.Regexp, error) {
var r *regexp.Regexp
var err error

Expand All @@ -56,7 +56,7 @@ func (TransferCounter) CompileRegex(operator string) (*regexp.Regexp, error) {
return r, err
}

func (TransferCounter) parseLine(content string, r *regexp.Regexp) ([]uint64, error) {
func (c *TransferCounter) parseLine(content string, r *regexp.Regexp) ([]uint64, error) {
results := make([]uint64, 0, 4)
subStrings := r.FindStringSubmatch(content)
if len(subStrings) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func newRedundantBalanceRegion() *Case {
})
}

storesLastUpdateTime := make([]int64, storeNum+1, storeNum+1)
storeLastAvailable := make([]uint64, storeNum+1, storeNum+1)
storesLastUpdateTime := make([]int64, storeNum+1)
storeLastAvailable := make([]uint64, storeNum+1)
simCase.Checker = func(regions *core.RegionsInfo, stats []info.StoreStats) bool {
res := true
curTime := time.Now().Unix()
Expand Down