Skip to content

Commit

Permalink
Format the code (milvus-io#27275)
Browse files Browse the repository at this point in the history
Signed-off-by: SimFG <[email protected]>
  • Loading branch information
SimFG authored Sep 21, 2023
1 parent fe01d54 commit 26f06dd
Show file tree
Hide file tree
Showing 652 changed files with 3,342 additions and 2,992 deletions.
34 changes: 24 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,43 @@ run:
- docs
- scripts
- internal/core
- cmake_build

linters:
disable-all: true
enable:
- staticcheck
- typecheck
- goimports
- misspell
- gosimple
- govet
- ineffassign
- gosimple
- staticcheck
- decorder
- depguard
- gofmt
- goimports
- gosec
- revive
- durationcheck
- unconvert
- misspell
- typecheck
- durationcheck
- forbidigo
- depguard
- gci
- whitespace
- gofumpt
# - gocritic

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/milvus-io)
custom-order: true
gofumpt:
lang-version: "1.18"
module-path: github.com/milvus-io
goimports:
local-prefixes: github.com/milvus-io
revive:
rules:
- name: unused-parameter
Expand Down Expand Up @@ -92,6 +109,3 @@ issues:
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

service:
golangci-lint-version: 1.27.0 # use the fixed version to not introduce new linters unexpectedly
38 changes: 30 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ INSTALL_GOLANGCI_LINT := $(findstring $(GOLANGCI_LINT_VERSION), $(GOLANGCI_LINT_
MOCKERY_VERSION := 2.32.4
MOCKERY_OUTPUT := $(shell $(INSTALL_PATH)/mockery --version 2>/dev/null)
INSTALL_MOCKERY := $(findstring $(MOCKERY_VERSION),$(MOCKERY_OUTPUT))
# gci
GCI_VERSION := 0.11.2
GCI_OUTPUT := $(shell $(INSTALL_PATH)/gci --version 2>/dev/null)
INSTALL_GCI := $(findstring $(GCI_VERSION),$(GCI_OUTPUT))
# gofumpt
GOFUMPT_VERSION := 0.5.0
GOFUMPT_OUTPUT := $(shell $(INSTALL_PATH)/gofumpt --version 2>/dev/null)
INSTALL_GOFUMPT := $(findstring $(GOFUMPT_VERSION),$(GOFUMPT_OUTPUT))

export GIT_BRANCH=master

Expand Down Expand Up @@ -97,18 +105,32 @@ else
@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh pkg/
endif

lint: tools/bin/revive
@echo "Running $@ check"
@tools/bin/revive -formatter friendly -config tools/check/revive.toml ./...
lint-fix: getdeps
@mkdir -p $(INSTALL_PATH)
@if [ -z "$(INSTALL_GCI)" ]; then \
echo "Installing gci v$(GCI_VERSION) to ./bin/" && GOBIN=$(INSTALL_PATH) go install github.com/daixiang0/gci@v$(GCI_VERSION); \
else \
echo "gci v$(GCI_VERSION) already installed"; \
fi
@if [ -z "$(INSTALL_GOFUMPT)" ]; then \
echo "Installing gofumpt v$(GOFUMPT_VERSION) to ./bin/" && GOBIN=$(INSTALL_PATH) go install mvdan.cc/gofumpt@v$(GOFUMPT_VERSION); \
else \
echo "gofumpt v$(GOFUMPT_VERSION) already installed"; \
fi
@echo "Running gofumpt fix"
@$(INSTALL_PATH)/gofumpt -l -w .
@echo "Running gci fix"
@$(INSTALL_PATH)/gci write cmd/ --skip-generated -s standard -s default -s "prefix(github.com/milvus-io)" --custom-order
@$(INSTALL_PATH)/gci write internal/ --skip-generated -s standard -s default -s "prefix(github.com/milvus-io)" --custom-order
@$(INSTALL_PATH)/gci write pkg/ --skip-generated -s standard -s default -s "prefix(github.com/milvus-io)" --custom-order
@$(INSTALL_PATH)/gci write tests/ --skip-generated -s standard -s default -s "prefix(github.com/milvus-io)" --custom-order
@echo "Running golangci-lint auto-fix"
@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --fix --timeout=30m --config $(PWD)/.golangci.yml; cd pkg && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --fix --timeout=30m --config $(PWD)/.golangci.yml

#TODO: Check code specifications by golangci-lint
static-check: getdeps
@echo "Running $@ check"
@GO111MODULE=on $(INSTALL_PATH)/golangci-lint cache clean
@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config ./.golangci.yml ./internal/...
@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config ./.golangci.yml ./cmd/...
@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config ./.golangci.yml ./tests/integration/...
@source $(PWD)/scripts/setenv.sh && cd pkg && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config ../.golangci.yml ./...
@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config $(PWD)/.golangci.yml; cd pkg && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config $(PWD)/.golangci.yml

verifiers: build-cpp getdeps cppcheck fmt static-check

Expand Down
3 changes: 2 additions & 1 deletion cmd/components/data_coord.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package components
import (
"context"

"go.uber.org/zap"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
grpcdatacoordclient "github.com/milvus-io/milvus/internal/distributed/datacoord"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/typeutil"
"go.uber.org/zap"
)

// DataCoord implements grpc server of DataCoord server
Expand Down
3 changes: 2 additions & 1 deletion cmd/components/data_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package components
import (
"context"

"go.uber.org/zap"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
grpcdatanode "github.com/milvus-io/milvus/internal/distributed/datanode"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/typeutil"
"go.uber.org/zap"
)

// DataNode implements DataNode grpc server
Expand Down
3 changes: 1 addition & 2 deletions cmd/components/index_coord.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
)

// IndexCoord implements IndexCoord grpc server
type IndexCoord struct {
}
type IndexCoord struct{}

// NewIndexCoord creates a new IndexCoord
func NewIndexCoord(ctx context.Context, factory dependency.Factory) (*IndexCoord, error) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/components/index_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package components
import (
"context"

"go.uber.org/zap"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
grpcindexnode "github.com/milvus-io/milvus/internal/distributed/indexnode"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/typeutil"
"go.uber.org/zap"
)

// IndexNode implements IndexNode grpc server
Expand All @@ -43,7 +44,6 @@ func NewIndexNode(ctx context.Context, factory dependency.Factory) (*IndexNode,
}
n.svr = svr
return n, nil

}

// Run starts service
Expand Down
3 changes: 2 additions & 1 deletion cmd/components/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package components
import (
"context"

"go.uber.org/zap"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
grpcproxy "github.com/milvus-io/milvus/internal/distributed/proxy"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/typeutil"
"go.uber.org/zap"
)

// Proxy implements Proxy grpc server
Expand Down
1 change: 0 additions & 1 deletion cmd/components/query_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewQueryNode(ctx context.Context, factory dependency.Factory) (*QueryNode,
ctx: ctx,
svr: svr,
}, nil

}

// Run starts service
Expand Down
3 changes: 2 additions & 1 deletion cmd/components/root_coord.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package components
import (
"context"

"go.uber.org/zap"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
rc "github.com/milvus-io/milvus/internal/distributed/rootcoord"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/typeutil"
"go.uber.org/zap"
)

// RootCoord implements RoodCoord grpc server
Expand Down
3 changes: 2 additions & 1 deletion cmd/embedded/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package main

import "C"

import (
"C"
"os"

"github.com/milvus-io/milvus/cmd/milvus"
Expand Down
2 changes: 0 additions & 2 deletions cmd/milvus/mck.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ func getTrashKey(taskType, key string) string {
}

func (c *mck) extractTask(prefix string, keys []string, values []string) {

for i := range keys {
taskID, err := strconv.ParseInt(filepath.Base(keys[i]), 10, 64)
if err != nil {
Expand Down Expand Up @@ -520,7 +519,6 @@ func (c *mck) extractVecFieldIndexInfo(taskID int64, infos []*querypb.FieldIndex
func (c *mck) unmarshalTask(taskID int64, t string) (string, []int64, []int64, error) {
header := commonpb.MsgHeader{}
err := proto.Unmarshal([]byte(t), &header)

if err != nil {
return errReturn(taskID, "MsgHeader", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/milvus/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *stop) formatFlags(args []string, flags *flag.FlagSet) {
func (c *stop) stopPid(filename string, runtimeDir string) error {
var pid int

fd, err := os.OpenFile(path.Join(runtimeDir, filename), os.O_RDONLY, 0664)
fd, err := os.OpenFile(path.Join(runtimeDir, filename), os.O_RDONLY, 0o664)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/milvus/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func makeRuntimeDir(dir string) error {
perm := os.FileMode(0755)
perm := os.FileMode(0o755)
// os.MkdirAll equal to `mkdir -p`
err := os.MkdirAll(dir, perm)
if err != nil {
Expand Down Expand Up @@ -63,7 +63,7 @@ func createRuntimeDir(sType string) string {
func createPidFile(w io.Writer, filename string, runtimeDir string) (*flock.Flock, error) {
fileFullName := path.Join(runtimeDir, filename)

fd, err := os.OpenFile(fileFullName, os.O_CREATE|os.O_RDWR, 0664)
fd, err := os.OpenFile(fileFullName, os.O_CREATE|os.O_RDWR, 0o664)
if err != nil {
return nil, fmt.Errorf("file %s is locked, error = %w", filename, err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/roles/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
"syscall"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"

"github.com/milvus-io/milvus/cmd/components"
"github.com/milvus-io/milvus/internal/http"
"github.com/milvus-io/milvus/internal/http/healthz"
Expand All @@ -43,9 +47,6 @@ import (
"github.com/milvus-io/milvus/pkg/util/paramtable"
_ "github.com/milvus-io/milvus/pkg/util/symbolizer" // support symbolizer and crash dump
"github.com/milvus-io/milvus/pkg/util/typeutil"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
)

// all milvus related metrics is in a separate registry
Expand Down
9 changes: 5 additions & 4 deletions cmd/tools/config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"reflect"
"strings"

"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/milvus-io/milvus/pkg/util/typeutil"
"github.com/samber/lo"
"go.uber.org/zap"
"golang.org/x/exp/slices"

"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/milvus-io/milvus/pkg/util/typeutil"
)

type DocContent struct {
Expand Down Expand Up @@ -106,7 +107,7 @@ type YamlMarshaller struct {
}

func (m *YamlMarshaller) writeYamlRecursive(data []DocContent, level int) {
var topLevels = typeutil.NewOrderedMap[string, []DocContent]()
topLevels := typeutil.NewOrderedMap[string, []DocContent]()
for _, d := range data {
key := strings.Split(d.key, ".")[level]

Expand Down
1 change: 0 additions & 1 deletion cmd/tools/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ func main() {
default:
log.Error(fmt.Sprintf("unknown argument %s", args[1]))
}

}
3 changes: 2 additions & 1 deletion cmd/tools/config/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"os"
"sort"

"github.com/milvus-io/milvus/pkg/log"
"github.com/spf13/viper"
"go.uber.org/zap"

"github.com/milvus-io/milvus/pkg/log"
)

func ShowYaml(filepath string) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/tools/datameta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"strings"

"github.com/golang/protobuf/proto"
"go.uber.org/zap"

etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/etcd"
"github.com/milvus-io/milvus/pkg/util/tsoutil"
"go.uber.org/zap"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/tools/migration/allocator/atomic_allocator.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package allocator

import (
"github.com/milvus-io/milvus/pkg/util/typeutil"
"go.uber.org/atomic"

"github.com/milvus-io/milvus/pkg/util/typeutil"
)

const (
Expand Down
4 changes: 1 addition & 3 deletions cmd/tools/migration/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"github.com/blang/semver/v4"

"github.com/milvus-io/milvus/cmd/tools/migration/configs"

"github.com/milvus-io/milvus/cmd/tools/migration/versions"

"github.com/milvus-io/milvus/cmd/tools/migration/meta"
"github.com/milvus-io/milvus/cmd/tools/migration/versions"
"github.com/milvus-io/milvus/pkg/util"
)

Expand Down
6 changes: 3 additions & 3 deletions cmd/tools/migration/backend/backup_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package backend
import (
"encoding/json"

"github.com/milvus-io/milvus/cmd/tools/migration/console"

"github.com/golang/protobuf/proto"

"github.com/milvus-io/milvus/cmd/tools/migration/console"
)

type BackupHeaderVersion int32
Expand Down Expand Up @@ -78,7 +78,7 @@ func (v *BackupHeaderExtra) ToJSONBytes() []byte {
}

func GetExtra(extra []byte) *BackupHeaderExtra {
var v = newDefaultBackupHeaderExtra()
v := newDefaultBackupHeaderExtra()
err := json.Unmarshal(extra, v)
if err != nil {
console.Error(err.Error())
Expand Down
Loading

0 comments on commit 26f06dd

Please sign in to comment.