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

chore(*): enable more revive linter rules #408

Merged
merged 1 commit into from
Dec 14, 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
80 changes: 79 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ linters-settings:
goconst:
ignore-tests: true
revive:
enable-all-rules: true
rules:
- name: var-naming
severity: warning
Expand All @@ -73,9 +74,62 @@ linters-settings:
- ["ID", "RPC"]
- [""]
- - upperCaseConst: false
- name: line-length-limit
severity: warning
disabled: false
arguments:
- 120
- name: add-constant
severity: warning
disabled: false
arguments:
- maxLitCount: "3"
allowStrs: '""'
allowInts: '0,1,2,3,4,5,6,7,8,9,10,11,16,17,20,22,32,64,100,128,1000,1024,0644,0755,0600'
allowFloats: "0.0,0.,0.5,0.50,0.95,0.99,0.999,1.0,1.,2.0,2.,80.0,100.0"
ignoreFuncs: 'slog\.*,metrics\.*'
- name: cognitive-complexity
severity: warning
disabled: true
arguments:
- 8
- name: cyclomatic
severity: warning
disabled: true
arguments:
- 3
- name: function-length
severity: warning
disabled: true
arguments: [10, 0]
- name: line-length-limit
severity: warning
disabled: true
arguments: [80]
- name: function-result-limit
severity: warning
disabled: false
arguments:
- 4
- name: flag-parameter
severity: warning
disabled: true
- name: deep-exit
severity: warning
disabled: true
- name: max-public-structs
severity: warning
disabled: true
arguments:
- 3
- name: bare-return
severity: warning
disabled: true

issues:
fix: true
max-same-issues: 0
max-issues-per-linter: 0
exclude-rules:
- path: _test\.go
linters:
Expand All @@ -93,4 +147,28 @@ issues:
- path: _test\.go
linters:
- gocritic
text: "exitAfterDefer|singleCaseSwitch"
text: "exitAfterDefer|singleCaseSwitch"
- path: _test\.go
linters:
- revive
text: "add-constant|cognitive-complexity|unused-parameter|unused-receiver|function-length|line-length-limit|unhandled-error|deep-exit|unchecked-type-assertion"
- path: \.go
linters:
- revive
text: "confusing-naming.*only by capitalization.*"
- path: maelstrom/
linters:
- revive
text: "unchecked-type-assertion|unhandled-error|unused-receiver|unused-parameter|add-constant"
- path: _grpc\.go
linters:
- revive
text: "blank-imports"
- path: server/kv/
linters:
- revive
text: "exported"
- path: server/wal/
linters:
- revive
text: "exported|unchecked-type-assertion"
4 changes: 2 additions & 2 deletions cmd/client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/streamnative/oxia/cmd/client/list"
"github.com/streamnative/oxia/cmd/client/notifications"
"github.com/streamnative/oxia/cmd/client/put"
oxia_common "github.com/streamnative/oxia/common"
oxiacommon "github.com/streamnative/oxia/common"
"github.com/streamnative/oxia/oxia"
)

Expand All @@ -38,7 +38,7 @@ var (
)

func init() {
defaultServiceAddress := fmt.Sprintf("localhost:%d", oxia_common.DefaultPublicPort)
defaultServiceAddress := fmt.Sprintf("localhost:%d", oxiacommon.DefaultPublicPort)
Cmd.PersistentFlags().StringVarP(&common.Config.ServiceAddr, "service-address", "a", defaultServiceAddress, "Service address")
Cmd.PersistentFlags().StringVarP(&common.Config.Namespace, "namespace", "n", oxia.DefaultNamespace, "The Oxia namespace to use")
Cmd.PersistentFlags().DurationVar(&common.Config.BatchLinger, "batch-linger", oxia.DefaultBatchLinger, "Max time requests will be staged to be included in a batch")
Expand Down
6 changes: 3 additions & 3 deletions cmd/client/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
)

func TestClientCmd(t *testing.T) {
server, err := server.NewStandalone(server.NewTestConfig(t.TempDir()))
standaloneServer, err := server.NewStandalone(server.NewTestConfig(t.TempDir()))
assert.NoError(t, err)

serviceAddress := fmt.Sprintf("localhost:%d", server.RpcPort())
serviceAddress := fmt.Sprintf("localhost:%d", standaloneServer.RpcPort())

stdin := bytes.NewBufferString("")
stdout := bytes.NewBufferString("")
Expand Down Expand Up @@ -197,5 +197,5 @@ func TestClientCmd(t *testing.T) {
stderr.Reset()
})
}
_ = server.Close()
_ = standaloneServer.Close()
}
2 changes: 1 addition & 1 deletion cmd/client/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ClientConfig struct {
RequestTimeout time.Duration
}

func (config *ClientConfig) NewClient() (oxia.AsyncClient, error) {
func (*ClientConfig) NewClient() (oxia.AsyncClient, error) {
return oxia.NewAsyncClient(Config.ServiceAddr,
oxia.WithBatchLinger(Config.BatchLinger),
oxia.WithRequestTimeout(Config.RequestTimeout),
Expand Down
22 changes: 9 additions & 13 deletions cmd/client/common/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,21 @@ func ReadStdin(stdin io.Reader, input Input, queue QueryQueue) {
for {
scanner.Scan()
b := scanner.Bytes()
if len(b) != 0 {
query, err := input.Unmarshal(b)
if err != nil {
panic(err)
}
queue.Add(query)
} else {
if len(b) == 0 {
break
}

query, err := input.Unmarshal(b)
if err != nil {
panic(err)
}
queue.Add(query)
}
}

func writeOutputCh(out io.Writer, valuesCh <-chan any) {
for {
if value, ok := <-valuesCh; ok {
writeOutput(out, value)
} else {
break
}
for value := range valuesCh {
writeOutput(out, value)
}
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/client/del/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var Cmd = &cobra.Command{
RunE: exec,
}

func exec(cmd *cobra.Command, args []string) error {
func exec(cmd *cobra.Command, _ []string) error {
loop, _ := common.NewCommandLoop(cmd.OutOrStdout())
defer func() {
loop.Complete()
Expand Down Expand Up @@ -106,20 +106,20 @@ type QueryInput struct {
KeyMaximum *string `json:"key_maximum,omitempty"`
}

func (query QueryInput) Unmarshal(b []byte) (common.Query, error) {
func (QueryInput) Unmarshal(b []byte) (common.Query, error) {
q := QueryInput{}
err := json.Unmarshal(b, &q)
if q.Key == nil {
return QueryByRange{
KeyMinimum: *q.KeyMinimum,
KeyMaximum: *q.KeyMaximum,
}, err
} else {
return QueryByKey{
Key: *q.Key,
ExpectedVersion: q.ExpectedVersion,
}, err
}

return QueryByKey{
Key: *q.Key,
ExpectedVersion: q.ExpectedVersion,
}, err
}

type QueryByKey struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/client/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var Cmd = &cobra.Command{
RunE: exec,
}

func exec(cmd *cobra.Command, args []string) error {
func exec(cmd *cobra.Command, _ []string) error {
loop, err := common.NewCommandLoop(cmd.OutOrStdout())
if err != nil {
return err
Expand Down Expand Up @@ -105,7 +105,7 @@ func (query Query) Perform(client oxia.AsyncClient) common.Call {
return call
}

func (query Query) Unmarshal(b []byte) (common.Query, error) {
func (Query) Unmarshal(b []byte) (common.Query, error) {
q := Query{}
err := json.Unmarshal(b, &q)
return q, err
Expand Down
26 changes: 13 additions & 13 deletions cmd/client/list/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var Cmd = &cobra.Command{
RunE: exec,
}

func exec(cmd *cobra.Command, args []string) error {
func exec(cmd *cobra.Command, _ []string) error {
loop, _ := common.NewCommandLoop(cmd.OutOrStdout())
defer func() {
loop.Complete()
Expand Down Expand Up @@ -92,7 +92,7 @@ func (query Query) Perform(client oxia.AsyncClient) common.Call {
}
}

func (query Query) Unmarshal(b []byte) (common.Query, error) {
func (Query) Unmarshal(b []byte) (common.Query, error) {
q := Query{}
err := json.Unmarshal(b, &q)
return q, err
Expand All @@ -108,19 +108,19 @@ func (call Call) Complete() <-chan any {
emptyOutput := true
for {
result, ok := <-call.clientCall
if ok {
emptyOutput = false
if result.Err != nil {
ch <- common.OutputError{
Err: result.Err.Error(),
}
} else {
ch <- Output{
Keys: result.Keys,
}
if !ok {
break
}

emptyOutput = false
if result.Err != nil {
ch <- common.OutputError{
Err: result.Err.Error(),
}
} else {
break
ch <- Output{
Keys: result.Keys,
}
}
}
if emptyOutput {
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/notifications/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var Cmd = &cobra.Command{
RunE: exec,
}

func exec(cmd *cobra.Command, args []string) error {
func exec(_ *cobra.Command, _ []string) error {
client, err := common.Config.NewClient()
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions cmd/client/put/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var Cmd = &cobra.Command{
RunE: exec,
}

func exec(cmd *cobra.Command, args []string) error {
func exec(cmd *cobra.Command, _ []string) error {
loop, err := common.NewCommandLoop(cmd.OutOrStdout())
if err != nil {
return err
Expand Down Expand Up @@ -132,7 +132,7 @@ func (query Query) Perform(client oxia.AsyncClient) common.Call {
return call
}

func (query Query) Unmarshal(b []byte) (common.Query, error) {
func (Query) Unmarshal(b []byte) (common.Query, error) {
q := Query{}
err := json.Unmarshal(b, &q)
return q, err
Expand All @@ -146,9 +146,9 @@ func convertValue(binary bool, value string) ([]byte, error) {
return nil, ErrBase64ValueInvalid
}
return decoded, nil
} else {
return []byte(value), nil
}

return []byte(value), nil
}

type Call struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func init() {
rootCmd.AddCommand(pebble.Cmd)
}

func configureLogLevel(cmd *cobra.Command, args []string) error {
func configureLogLevel(_ *cobra.Command, _ []string) error {
logLevel, err := common.ParseLogLevel(logLevelStr)
if err != nil {
return LogLevelError(logLevelStr)
Expand Down
4 changes: 2 additions & 2 deletions common/batch/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (b *batcherImpl) failCall(call any, err error) {

func (b *batcherImpl) Run() {
var batch Batch
var timer *time.Timer = nil
var timeout <-chan time.Time = nil
var timer *time.Timer
var timeout <-chan time.Time

newBatch := func() {
batch = b.batchFactory()
Expand Down
Loading
Loading