Skip to content

Commit

Permalink
chore(*): enable revive linter (#399)
Browse files Browse the repository at this point in the history
enable `revive` linter

Signed-off-by: Soren Yang <lsytj0413@gmail.com>
  • Loading branch information
lsytj0413 authored Dec 6, 2023
1 parent 86f3768 commit c7f7fd3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
11 changes: 10 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ linters:
- ineffassign
- staticcheck
- unused
# - revive
- revive
- asasalint
- asciicheck
- bodyclose
Expand Down Expand Up @@ -64,6 +64,15 @@ linters-settings:
local-prefixes: github.com/streamnative/oxia
goconst:
ignore-tests: true
revive:
rules:
- name: var-naming
severity: warning
disabled: false
arguments:
- ["ID", "RPC"]
- [""]
- - upperCaseConst: false

issues:
fix: true
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (l LogLevelError) Error() string {

func init() {
rootCmd.PersistentFlags().StringVarP(&logLevelStr, "log-level", "l", common.DefaultLogLevel.String(), "Set logging level [debug|info|warn|error]")
rootCmd.PersistentFlags().BoolVarP(&common.LogJson, "log-json", "j", false, "Print logs in JSON format")
rootCmd.PersistentFlags().BoolVarP(&common.LogJSON, "log-json", "j", false, "Print logs in JSON format")
rootCmd.PersistentFlags().BoolVar(&common.PprofEnable, "profile", false, "Enable pprof profiler")
rootCmd.PersistentFlags().StringVar(&common.PprofBindAddress, "profile-bind-address", "127.0.0.1:6060", "Bind address for pprof")

Expand Down
6 changes: 3 additions & 3 deletions common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const DefaultLogLevel = slog.LevelInfo
var (
// LogLevel Used for flags.
LogLevel slog.Level
// LogJson Used for flags.
LogJson bool
// LogJSON Used for flags.
LogJSON bool
)

// ParseLogLevel will convert the slog level configuration to slog.Level values.
Expand Down Expand Up @@ -76,7 +76,7 @@ func ConfigureLogger() {
Stack().
Logger()

if !LogJson {
if !LogJSON {
zerologLogger = log.Output(zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.StampMicro,
Expand Down
2 changes: 1 addition & 1 deletion maelstrom/coordinator_rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (m *maelstromShardAssignmentClient) Send(response *proto.ShardAssignments)
Type: MsgTypeShardAssignmentsResponse,
MsgId: msgIdGenerator.Add(1),
},
OxiaMsg: toJson(response),
OxiaMsg: toJSON(response),
StreamId: m.streamId,
},
}
Expand Down
4 changes: 2 additions & 2 deletions maelstrom/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (d *dispatcher) RpcRequest(ctx context.Context, dest string, msgType MsgTyp
Type: msgType,
MsgId: msgId,
},
OxiaMsg: toJson(message),
OxiaMsg: toJSON(message),
},
}

Expand Down Expand Up @@ -372,7 +372,7 @@ var protoMarshal = protojson.MarshalOptions{
EmitUnpopulated: true,
}

func toJson(message pb.Message) []byte {
func toJSON(message pb.Message) []byte {
r, err := protoMarshal.Marshal(message)
if err != nil {
slog.Error(
Expand Down
4 changes: 2 additions & 2 deletions maelstrom/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (m *maelstromGrpcProvider) sendResponse(req *Message[OxiaMessage], msgType
MsgId: msgIdGenerator.Add(1),
InReplyTo: &req.Body.MsgId,
},
OxiaMsg: toJson(response),
OxiaMsg: toJSON(response),
},
})
if err != nil {
Expand Down Expand Up @@ -366,7 +366,7 @@ func (m *maelstromReplicateServerStream) Send(response *proto.Ack) error {
Type: MsgTypeAck,
MsgId: msgIdGenerator.Add(1),
},
OxiaMsg: toJson(response),
OxiaMsg: toJSON(response),
StreamId: m.streamId,
},
})
Expand Down
2 changes: 1 addition & 1 deletion maelstrom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (l LogLevelError) Error() string {

func init() {
rootCmd.PersistentFlags().StringVarP(&logLevelStr, "log-level", "l", common.DefaultLogLevel.String(), "Set logging level [debug|info|warn|error]")
rootCmd.PersistentFlags().BoolVarP(&common.LogJson, "log-json", "j", false, "Print logs in JSON format")
rootCmd.PersistentFlags().BoolVarP(&common.LogJSON, "log-json", "j", false, "Print logs in JSON format")
}

func configureLogLevel(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion maelstrom/replication_rpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (m *maelstromReplicateClient) Send(request *proto.Append) error {
Type: MsgTypeAppend,
MsgId: msgIdGenerator.Add(1),
},
OxiaMsg: toJson(request),
OxiaMsg: toJSON(request),
StreamId: m.streamId,
},
})
Expand Down
6 changes: 3 additions & 3 deletions server/leader_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func AssertProtoEqual(t *testing.T, expected, actual pb.Message) {
protoMarshal := protojson.MarshalOptions{
EmitUnpopulated: true,
}
expectedJson, _ := protoMarshal.Marshal(expected)
actualJson, _ := protoMarshal.Marshal(actual)
assert.Equal(t, string(expectedJson), string(actualJson))
expectedJSON, _ := protoMarshal.Marshal(expected)
actualJSON, _ := protoMarshal.Marshal(actual)
assert.Equal(t, string(expectedJSON), string(actualJSON))
}
}

Expand Down

0 comments on commit c7f7fd3

Please sign in to comment.