Skip to content

Commit

Permalink
Enable gocritic linter and solve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vascoguita committed Nov 23, 2022
1 parent 0a1257d commit 3c2525f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ linters:
- gofumpt # TODO: consider enabling the 'gofumpt' linter to check whether code was gofumpt-ed.
- godox # TODO: consider enabling the 'godox' linter to detect FIXME, TODO and other comment keywords.
- godot # TODO: consider enabling the 'godot' linter to if comments end in a period.
- gocritic # TODO: consider enabling the 'gocritic' linter to check for bugs, performance and style issues.
- goconst # TODO: consider enabling the 'goconst' linter to find repeated strings that could be replaced by a constant.
- gocognit # TODO: consider enabling the 'gocognit' linter to compute and check the cognitive complexity of functions.
- gochecknoinits # TODO: consider enabling the 'gochecknoinits' linter to check that no init functions are present in Go code.
Expand Down
3 changes: 3 additions & 0 deletions changelog/unreleased/enhancement-gocritic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Enable gocritic linter in golangci-lint and solve issues

https://github.com/cs3org/reva/pull/3467
6 changes: 4 additions & 2 deletions internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
// NewUnary returns a new unary interceptor that emits events when needed
// no lint because of the switch statement that should be extendable
//
//nolint:gocritic

func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error) {
publisher, err := publisherFromConfig(m)
if err != nil {
Expand All @@ -57,7 +57,9 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
}

var ev interface{}
switch v := res.(type) {

// gocritic is disabled because the use of .(type) outside type switch is forbidden
switch v := res.(type) { //nolint:gocritic
case *collaboration.CreateShareResponse:
ev = ShareCreated(v)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (fs *ocfs) toInternalPath(ctx context.Context, sp string) (ip string) {
ip = filepath.Join(fs.c.DataDirectory, layout, "files")
} else {
// parts = "<username>", "foo/bar.txt"
ip = filepath.Join(fs.c.DataDirectory, layout, "files", filepath.Join(segments[1]))
ip = filepath.Join(fs.c.DataDirectory, layout, "files", segments[1])
}

}
Expand Down Expand Up @@ -2349,7 +2349,7 @@ func (fs *ocfs) propagate(ctx context.Context, leafPath string) error {
Int("i", i).
Interface("parts", parts).
Msg("propagating change")
if err := os.Chtimes(filepath.Join(root), fi.ModTime(), fi.ModTime()); err != nil {
if err := os.Chtimes(root, fi.ModTime(), fi.ModTime()); err != nil {
appctx.GetLogger(ctx).Error().
Err(err).
Str("leafPath", leafPath).
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/fs/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1906,12 +1906,12 @@ func (fs *owncloudsqlfs) propagate(ctx context.Context, leafPath string) error {
Str("leafPath", leafPath).
Str("currentPath", currentPath).
Msg("propagating change")
parentFi, err := os.Stat(filepath.Join(currentPath))
parentFi, err := os.Stat(currentPath)
if err != nil {
return err
}
if fi.ModTime().UnixNano() > parentFi.ModTime().UnixNano() {
if err := os.Chtimes(filepath.Join(currentPath), fi.ModTime(), fi.ModTime()); err != nil {
if err := os.Chtimes(currentPath, fi.ModTime(), fi.ModTime()); err != nil {
appctx.GetLogger(ctx).Error().
Err(err).
Str("leafPath", leafPath).
Expand All @@ -1920,7 +1920,7 @@ func (fs *owncloudsqlfs) propagate(ctx context.Context, leafPath string) error {
return err
}
}
fi, err = os.Stat(filepath.Join(currentPath))
fi, err = os.Stat(currentPath)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/registry"
"github.com/cs3org/reva/pkg/registry/memory"

// gocritic is disabled because google.golang.org/protobuf/proto does not provide a method to convert MessageV1 to MessageV2
"github.com/golang/protobuf/proto" //nolint:staticcheck
"google.golang.org/protobuf/encoding/protojson"
)
Expand Down

0 comments on commit 3c2525f

Please sign in to comment.