Skip to content

Commit

Permalink
ci: add more revive linters (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoVeille authored Jul 9, 2024
1 parent a9f56ce commit f43d53c
Show file tree
Hide file tree
Showing 30 changed files with 90 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ linters-settings:
- name: comment-spacings
- name: early-return
- name: defer
- name: deep-exit
- name: unused-receiver

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Options func(c *route)

type ErrCommandNotFound struct{}

func (e ErrCommandNotFound) Error() string {
func (ErrCommandNotFound) Error() string {
return "No Command Found!"
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/gofr/cmd/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func (r *Request) PathParam(key string) string {
return r.params[key]
}

func (r *Request) Context() context.Context {
func (*Request) Context() context.Context {
return context.Background()
}

func (r *Request) HostName() (hostname string) {
func (*Request) HostName() (hostname string) {
hostname, _ = os.Hostname()

return hostname
Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/cmd/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type Responder struct{}

func (r *Responder) Respond(data interface{}, err error) {
func (*Responder) Respond(data interface{}, err error) {
// TODO - provide proper exit codes here. Using os.Exit directly is a problem for tests.
if data != nil {
fmt.Fprintln(os.Stdout, data)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gofr/config/godotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func (e *EnvLoader) read(folder string) {
}
}

func (e *EnvLoader) Get(key string) string {
func (*EnvLoader) Get(key string) string {
return os.Getenv(key)
}

func (e *EnvLoader) GetOrDefault(key, defaultValue string) string {
func (*EnvLoader) GetOrDefault(key, defaultValue string) string {
if val := os.Getenv(key); val != "" {
return val
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/gofr/container/mock_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ func NewMockContainer(t *testing.T) (*Container, Mocks) {
type MockPubSub struct {
}

func (m *MockPubSub) CreateTopic(_ context.Context, _ string) error {
func (*MockPubSub) CreateTopic(_ context.Context, _ string) error {
return nil
}

func (m *MockPubSub) DeleteTopic(_ context.Context, _ string) error {
func (*MockPubSub) DeleteTopic(_ context.Context, _ string) error {
return nil
}

func (m *MockPubSub) Health() datasource.Health {
func (*MockPubSub) Health() datasource.Health {
return datasource.Health{}
}

func (m *MockPubSub) Publish(_ context.Context, _ string, _ []byte) error {
func (*MockPubSub) Publish(_ context.Context, _ string, _ []byte) error {
return nil
}

func (m *MockPubSub) Subscribe(_ context.Context, _ string) (*pubsub.Message, error) {
func (*MockPubSub) Subscribe(_ context.Context, _ string) (*pubsub.Message, error) {
return nil, nil
}
10 changes: 5 additions & 5 deletions pkg/gofr/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,22 @@ func (e errParsing) Error() string {
type noopRequest struct {
}

func (b noopRequest) Context() context.Context {
func (noopRequest) Context() context.Context {
return context.Background()
}

func (b noopRequest) Param(string) string {
func (noopRequest) Param(string) string {
return ""
}

func (b noopRequest) PathParam(string) string {
func (noopRequest) PathParam(string) string {
return ""
}

func (b noopRequest) HostName() string {
func (noopRequest) HostName() string {
return "gofr"
}

func (b noopRequest) Bind(interface{}) error {
func (noopRequest) Bind(interface{}) error {
return nil
}
4 changes: 2 additions & 2 deletions pkg/gofr/crud_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ type userEntity struct {
IsEmployed bool `json:"isEmployed"`
}

func (u *userEntity) TableName() string {
func (*userEntity) TableName() string {
return "user"
}

func (u *userEntity) RestPath() string {
func (*userEntity) RestPath() string {
return "users"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func (e ErrorDB) WithStack() ErrorDB {
return e
}

func (e ErrorDB) StatusCode() int {
func (ErrorDB) StatusCode() int {
return http.StatusInternalServerError
}
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (f file) createJSONReader() (datasource.RowReader, error) {
}

// Peek the first JSON token to determine its type.
func (f file) peekJSONToken(decoder *json.Decoder) (json.Token, error) {
func (file) peekJSONToken(decoder *json.Decoder) (json.Token, error) {
newDecoder := *decoder

token, err := newDecoder.Token()
Expand Down
10 changes: 5 additions & 5 deletions pkg/gofr/datasource/file/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func (f fileSystem) Create(name string) (datasource.File, error) {
return &file{File: newFile, logger: f.logger}, nil
}

func (f fileSystem) Mkdir(name string, perm os.FileMode) error {
func (fileSystem) Mkdir(name string, perm os.FileMode) error {
return os.Mkdir(name, perm)
}

func (f fileSystem) MkdirAll(path string, perm os.FileMode) error {
func (fileSystem) MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}

Expand All @@ -50,14 +50,14 @@ func (f fileSystem) OpenFile(name string, flag int, perm os.FileMode) (datasourc
return &file{File: openFile, logger: f.logger}, nil
}

func (f fileSystem) Remove(name string) error {
func (fileSystem) Remove(name string) error {
return os.Remove(name)
}

func (f fileSystem) RemoveAll(path string) error {
func (fileSystem) RemoveAll(path string) error {
return os.RemoveAll(path)
}

func (f fileSystem) Rename(oldname, newname string) error {
func (fileSystem) Rename(oldname, newname string) error {
return os.Rename(oldname, newname)
}
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/pubsub/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ func (m *Message) bindStruct(i any) error {
return json.Unmarshal(m.Value, i)
}

func (m *Message) HostName() string {
func (*Message) HostName() string {
return ""
}
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/pubsub/mqtt/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ func (m mockMessage) Payload() []byte {
return []byte(m.pyload)
}

func (m mockMessage) Ack() {
func (mockMessage) Ack() {
}
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/pubsub/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (m *MQTT) CreateTopic(_ context.Context, topic string) error {

// DeleteTopic is implemented to adhere to the PubSub Client interface
// Note: there is no concept of deletion.
func (m *MQTT) DeleteTopic(_ context.Context, _ string) error {
func (*MQTT) DeleteTopic(_ context.Context, _ string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/redis/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *redisHook) logQuery(start time.Time, query string, args ...interface{})
}

// DialHook implements the redis.DialHook interface.
func (r *redisHook) DialHook(next redis.DialHook) redis.DialHook {
func (*redisHook) DialHook(next redis.DialHook) redis.DialHook {
return next
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/sql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (d *DB) Select(ctx context.Context, data interface{}, query string, args ..
}
}

func (d *DB) rowsToStruct(rows *sql.Rows, vo reflect.Value) {
func (*DB) rowsToStruct(rows *sql.Rows, vo reflect.Value) {
v := vo
if vo.Kind() == reflect.Ptr {
v = vo.Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpa
}

// Shutdown shuts down the exporter.
func (e *Exporter) Shutdown(context.Context) error {
func (*Exporter) Shutdown(context.Context) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/file/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ func (m *mockReadCloser) Read(p []byte) (int, error) {
return m.Buffer.Read(p)
}

func (m *mockReadCloser) Close() error {
func (*mockReadCloser) Close() error {
return nil
}
22 changes: 11 additions & 11 deletions pkg/gofr/http/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ func (e ErrorEntityNotFound) Error() string {
return fmt.Sprintf("No entity found with %s: %s", e.Name, e.Value)
}

func (e ErrorEntityNotFound) StatusCode() int {
func (ErrorEntityNotFound) StatusCode() int {
return http.StatusNotFound
}

// ErrorEntityAlreadyExist represents an error for when entity is already present in the storage and we are trying to make duplicate entry.
type ErrorEntityAlreadyExist struct {
}

func (e ErrorEntityAlreadyExist) Error() string {
func (ErrorEntityAlreadyExist) Error() string {
return alreadyExistsMessage
}

func (e ErrorEntityAlreadyExist) StatusCode() int {
func (ErrorEntityAlreadyExist) StatusCode() int {
return http.StatusConflict
}

Expand All @@ -45,7 +45,7 @@ func (e ErrorInvalidParam) Error() string {
return fmt.Sprintf("'%d' invalid parameter(s): %s", len(e.Params), strings.Join(e.Params, ", "))
}

func (e ErrorInvalidParam) StatusCode() int {
func (ErrorInvalidParam) StatusCode() int {
return http.StatusBadRequest
}

Expand All @@ -58,39 +58,39 @@ func (e ErrorMissingParam) Error() string {
return fmt.Sprintf("'%d' missing parameter(s): %s", len(e.Params), strings.Join(e.Params, ", "))
}

func (e ErrorMissingParam) StatusCode() int {
func (ErrorMissingParam) StatusCode() int {
return http.StatusBadRequest
}

// ErrorInvalidRoute represents an error for invalid route in a request.
type ErrorInvalidRoute struct{}

func (e ErrorInvalidRoute) Error() string {
func (ErrorInvalidRoute) Error() string {
return "route not registered"
}

func (e ErrorInvalidRoute) StatusCode() int {
func (ErrorInvalidRoute) StatusCode() int {
return http.StatusNotFound
}

// ErrorRequestTimeout represents an error for request which timed out.
type ErrorRequestTimeout struct{}

func (e ErrorRequestTimeout) Error() string {
func (ErrorRequestTimeout) Error() string {
return "request timed out"
}

func (e ErrorRequestTimeout) StatusCode() int {
func (ErrorRequestTimeout) StatusCode() int {
return http.StatusRequestTimeout
}

// ErrorPanicRecovery represents an error for request which panicked.
type ErrorPanicRecovery struct{}

func (e ErrorPanicRecovery) Error() string {
func (ErrorPanicRecovery) Error() string {
return http.StatusText(http.StatusInternalServerError)
}

func (e ErrorPanicRecovery) StatusCode() int {
func (ErrorPanicRecovery) StatusCode() int {
return http.StatusInternalServerError
}
2 changes: 1 addition & 1 deletion pkg/gofr/http/middleware/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type PublicKeys struct {
type JWKNotFound struct {
}

func (i JWKNotFound) Error() string {
func (JWKNotFound) Error() string {
return "JWKS Not Found"
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/gofr/http/middleware/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestOAuthJSONUnmarshalError(t *testing.T) {
type MockProvider struct {
}

func (m *MockProvider) GetWithHeaders(context.Context, string, map[string]interface{},
func (*MockProvider) GetWithHeaders(context.Context, string, map[string]interface{},
map[string]string) (*http.Response, error) {
// Marshal the JSON body
responseBody := map[string]interface{}{
Expand Down Expand Up @@ -305,7 +305,7 @@ func (m *MockProvider) GetWithHeaders(context.Context, string, map[string]interf
type MockErrorProvider struct {
}

func (m *MockErrorProvider) GetWithHeaders(context.Context, string, map[string]interface{},
func (*MockErrorProvider) GetWithHeaders(context.Context, string, map[string]interface{},
map[string]string) (*http.Response, error) {
// Marshal the JSON body
return nil, oauthError{msg: "response error"}
Expand All @@ -322,13 +322,13 @@ func (o oauthError) Error() string {
// CustomReader simulates an error during the Read operation.
type CustomReader struct{}

func (r *CustomReader) Read([]byte) (int, error) {
func (*CustomReader) Read([]byte) (int, error) {
return 0, oauthError{msg: "read error"}
}

type MockReaderErrorProvider struct{}

func (m *MockReaderErrorProvider) GetWithHeaders(context.Context, string, map[string]interface{},
func (*MockReaderErrorProvider) GetWithHeaders(context.Context, string, map[string]interface{},
map[string]string) (*http.Response, error) {
// Create a custom reader that returns an error
body := &CustomReader{}
Expand All @@ -344,7 +344,7 @@ func (m *MockReaderErrorProvider) GetWithHeaders(context.Context, string, map[st

type MockJSONResponseErrorProvider struct{}

func (m *MockJSONResponseErrorProvider) GetWithHeaders(context.Context, string, map[string]interface{},
func (*MockJSONResponseErrorProvider) GetWithHeaders(context.Context, string, map[string]interface{},
map[string]string) (*http.Response, error) {
// Create a body with invalid JSON
body := strings.NewReader("invalid JSON")
Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/http/middleware/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type MockHandlerForTracing struct{}

// ServeHTTP is used for testing if the request context has traceId.
func (r *MockHandlerForTracing) ServeHTTP(w http.ResponseWriter, req *http.Request) {
func (*MockHandlerForTracing) ServeHTTP(w http.ResponseWriter, req *http.Request) {
traceID := otelTrace.SpanFromContext(req.Context()).SpanContext().TraceID().String()
_, _ = w.Write([]byte(traceID))
}
Expand Down
Loading

0 comments on commit f43d53c

Please sign in to comment.