From 07734e17a62735b78bbac29a61b5c210c370c10e Mon Sep 17 00:00:00 2001 From: Vasco Guita Date: Wed, 23 Nov 2022 14:08:53 +0100 Subject: [PATCH 1/2] Enable revive linter and solve issues --- .golangci.yaml | 1 - changelog/unreleased/enhancement-revive.md | 3 +++ internal/http/services/ocmd/shares.go | 2 +- pkg/app/provider/wopi/wopi.go | 2 +- pkg/ocm/invite/manager/json/json.go | 2 +- pkg/sysinfo/sysinfo.go | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/enhancement-revive.md diff --git a/.golangci.yaml b/.golangci.yaml index e6b41a7da8..3dbe66cdf8 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -41,7 +41,6 @@ linters: - containedctx # TODO: consider enabling the 'containedctx' linter to detect struct contained context.Context field. - whitespace # TODO: consider enabling the 'whitespace' linter to detect leading and trailing whitespaces. - unparam # TODO: consider enabling the 'unparam' linter to report unused function parameters. - - revive # TODO: consider enabling the 'revive' linter to configure custom rules and define a strict preset for enhancing development & code review processes. - nakedret # TODO: consider enabling the 'nakedret' linter to find naked returns in functions greater than a specified function length. - dupword # TODO: consider enabling the 'dupword' linter to check for duplicate words in the source code. - makezero # TODO: consider enabling the 'makezero' linter to find slice declarations with non-zero initial length. diff --git a/changelog/unreleased/enhancement-revive.md b/changelog/unreleased/enhancement-revive.md new file mode 100644 index 0000000000..2f0e8ed850 --- /dev/null +++ b/changelog/unreleased/enhancement-revive.md @@ -0,0 +1,3 @@ +Enhancement: Enable revive linter in golangci-lint and solve issues + +https://github.com/cs3org/reva/pull/3465 \ No newline at end of file diff --git a/internal/http/services/ocmd/shares.go b/internal/http/services/ocmd/shares.go index d4435d3b08..197ea8903c 100644 --- a/internal/http/services/ocmd/shares.go +++ b/internal/http/services/ocmd/shares.go @@ -141,7 +141,7 @@ func (h *sharesHandler) createShare(w http.ResponseWriter, r *http.Request) { return } - var shareWithParts []string = strings.Split(shareWith, "@") + var shareWithParts = strings.Split(shareWith, "@") userRes, err := gatewayClient.GetUser(ctx, &userpb.GetUserRequest{ UserId: &userpb.UserId{OpaqueId: shareWithParts[0]}, SkipFetchingUserGroups: true, }) diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index 436d4d7463..1e172f16e1 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -161,7 +161,7 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc q.Add("appviewurl", viewAppURL) } } - var access string = "edit" + var access = "edit" if resource.GetSize() == 0 { if _, ok := p.appURLs["editnew"]; ok { access = "editnew" diff --git a/pkg/ocm/invite/manager/json/json.go b/pkg/ocm/invite/manager/json/json.go index 039a0c4ddf..9849e245d9 100644 --- a/pkg/ocm/invite/manager/json/json.go +++ b/pkg/ocm/invite/manager/json/json.go @@ -239,7 +239,7 @@ func (m *manager) ForwardInvite(ctx context.Context, invite *invitepb.InviteToke if e != nil { return errors.Wrap(e, "json: error reading request body") } - return errors.Wrap(errors.New(fmt.Sprintf("%s: %s", resp.Status, string(respBody))), "json: error sending accept post request") + return errors.Wrap(fmt.Errorf("%s: %s", resp.Status, string(respBody)), "json: error sending accept post request") } return nil diff --git a/pkg/sysinfo/sysinfo.go b/pkg/sysinfo/sysinfo.go index fc19764e20..c74156a4aa 100644 --- a/pkg/sysinfo/sysinfo.go +++ b/pkg/sysinfo/sysinfo.go @@ -34,7 +34,7 @@ type SystemInformation struct { var ( // SysInfo provides global system information. - SysInfo *SystemInformation = &SystemInformation{} + SysInfo = &SystemInformation{} ) // ToJSON converts the system information to JSON. From 4504b88f86fb0a33892ce15f1cc58a49aec72a29 Mon Sep 17 00:00:00 2001 From: Vasco Guita Date: Wed, 23 Nov 2022 14:14:48 +0100 Subject: [PATCH 2/2] Enable gocritic linter and solve issues --- .golangci.yaml | 1 - changelog/unreleased/enhancement-gocritic.md | 3 +++ internal/grpc/interceptors/eventsmiddleware/events.go | 6 ++++-- pkg/storage/fs/owncloud/owncloud.go | 4 ++-- pkg/storage/fs/owncloudsql/owncloudsql.go | 6 +++--- pkg/utils/utils.go | 2 ++ 6 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 changelog/unreleased/enhancement-gocritic.md diff --git a/.golangci.yaml b/.golangci.yaml index 3dbe66cdf8..3c0ae8f5b2 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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. diff --git a/changelog/unreleased/enhancement-gocritic.md b/changelog/unreleased/enhancement-gocritic.md new file mode 100644 index 0000000000..d57336b4d8 --- /dev/null +++ b/changelog/unreleased/enhancement-gocritic.md @@ -0,0 +1,3 @@ +Enhancement: Enable gocritic linter in golangci-lint and solve issues + +https://github.com/cs3org/reva/pull/3467 \ No newline at end of file diff --git a/internal/grpc/interceptors/eventsmiddleware/events.go b/internal/grpc/interceptors/eventsmiddleware/events.go index d3a37d253d..7d8067218d 100644 --- a/internal/grpc/interceptors/eventsmiddleware/events.go +++ b/internal/grpc/interceptors/eventsmiddleware/events.go @@ -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 { @@ -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) } diff --git a/pkg/storage/fs/owncloud/owncloud.go b/pkg/storage/fs/owncloud/owncloud.go index 5220158164..000c78e990 100644 --- a/pkg/storage/fs/owncloud/owncloud.go +++ b/pkg/storage/fs/owncloud/owncloud.go @@ -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 = "", "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]) } } @@ -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). diff --git a/pkg/storage/fs/owncloudsql/owncloudsql.go b/pkg/storage/fs/owncloudsql/owncloudsql.go index a445e3b83f..ed4d9fc9d7 100644 --- a/pkg/storage/fs/owncloudsql/owncloudsql.go +++ b/pkg/storage/fs/owncloudsql/owncloudsql.go @@ -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). @@ -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 } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 1c0f43d2cb..539acf5b57 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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" )