Skip to content

Commit

Permalink
Enable the stylecheck, whitespace, dupword, godot and dogsled linters…
Browse files Browse the repository at this point in the history
… and solve issues
  • Loading branch information
Vasco Guita authored and gmgigi96 committed Nov 23, 2022
1 parent 62a595e commit edd5a5e
Show file tree
Hide file tree
Showing 362 changed files with 1,294 additions and 1,748 deletions.
5 changes: 0 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ linters:
- testpackage # TODO: consider enabling the 'testpackage' linter to make sure that separate _test packages are used.
- gosec # TODO: consider enabling the 'gosec' linter to inspect source code for security problems.
- tagliatelle # TODO: consider enabling the 'tagliatelle' linter to check the struct tags.
- stylecheck # TODO: consider enabling the 'stylecheck' linter to enforce style rules.
- thelper # TODO: consider enabling the 'thelper' linter to detect golang test helpers without t.Helper() call and check the consistency of test helpers.
- predeclared # TODO: consider enabling the 'predeclared' linter to find code that shadows one of Go's predeclared identifiers.
- paralleltest # TODO: consider enabling the 'paralleltest' linter to detect missing usage of t.Parallel() method in Go test.
Expand All @@ -37,16 +36,13 @@ linters:
- contextcheck # TODO: consider enabling the 'contextcheck' linter to check whether the function uses a non-inherited context.
- asasalint # TODO: consider enabling the 'asasalint' linter to check for pass []any as any in variadic func(...any).
- 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.
- 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.
- lll # TODO: consider enabling the 'lll' linter to report long lines.
- gomoddirectives # TODO: consider enabling the 'gomoddirectives' linter to manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
- 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.
- 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 All @@ -56,7 +52,6 @@ linters:
- gocyclo # TODO: consider enabling the 'gocyclo' linter to compute and check the cyclomatic complexity of functions.
- forbidigo # TODO: consider enabling the 'forbidigo' linter to forbid identifiers.
- dupl # TODO: consider enabling the 'dupl' linter to detect code cloning.
- dogsled # TODO: consider enabling the 'dogsled' linter to check assignments with too many blank identifiers (e.g. x, , , _, := f()).
- golint # deprecated since v1.41.0 - replaced by 'revive'.
- ifshort # deprecated since v1.48.0
- structcheck # deprecated since v1.49.0 - replaced by 'unused'.
Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/enhancement-stylecheck.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Enable the style linters

We've enabled the stylecheck, whitespace, dupword, godot and dogsled linters in golangci-lint and solved the related issues.

https://github.com/cs3org/reva/pull/3475
3 changes: 1 addition & 2 deletions cmd/reva/app-tokens-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func appTokensCreateCommand() *command {
}

cmd.Action = func(w ...io.Writer) error {

createOpts := &appTokenCreateOpts{
Expiration: *expiration,
Label: *label,
Expand Down Expand Up @@ -215,7 +214,7 @@ func getPathScope(ctx context.Context, client gateway.GatewayAPIClient, path, pe
return scope.AddResourceInfoScope(statResponse.GetInfo(), role, scopes)
}

// parse permission string in the form of "rw" to create a role
// parse permission string in the form of "rw" to create a role.
func parsePermission(perm string) (authpb.Role, error) {
switch perm {
case "r":
Expand Down
1 change: 0 additions & 1 deletion cmd/reva/app-tokens-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func appTokensListCommand() *command {
cmd.Usage = func() string { return "Usage: token-list" }

cmd.Action = func(w ...io.Writer) error {

client, err := getClient()
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/reva/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func (c *Completer) shareReceivedArgumentCompleter() []prompt.Suggest {
}

func executeCommand(cmd *command, args ...string) (bytes.Buffer, error) {

var b bytes.Buffer
var err error

Expand Down
4 changes: 2 additions & 2 deletions cmd/reva/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"io"
)

// Command is the representation to create commands
// Command is the representation to create commands.
type command struct {
*flag.FlagSet
Name string
Expand All @@ -34,7 +34,7 @@ type command struct {
ResetFlags func()
}

// newCommand creates a new command
// newCommand creates a new command.
func newCommand(name string) *command {
fs := flag.NewFlagSet(name, flag.ExitOnError)
cmd := &command{
Expand Down
5 changes: 2 additions & 3 deletions cmd/reva/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/c-bata/go-prompt"
)

// Completer provides completion command handler
// Completer provides completion command handler.
type Completer struct {
Commands []*command
DisableArgPrompt bool
Expand All @@ -45,7 +45,7 @@ func (c *Completer) init() {
c.lsDirArguments = new(argumentCompleter)
}

// Complete provides completion to prompt
// Complete provides completion to prompt.
func (c *Completer) Complete(d prompt.Document) []prompt.Suggest {
if d.TextBeforeCursor() == "" {
return []prompt.Suggest{}
Expand Down Expand Up @@ -80,7 +80,6 @@ func (c *Completer) argumentCompleter(args ...string) []prompt.Suggest {
}

switch args[0] {

case "login":
if len(args) == 2 {
return prompt.FilterHasPrefix(c.loginArgumentCompleter(), args[1], true)
Expand Down
6 changes: 3 additions & 3 deletions cmd/reva/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"time"
)

// Executor provides exec command handler
// Executor provides exec command handler.
type Executor struct {
Timeout int64
}

// Execute provides execute commands
// Execute provides execute commands.
func (e *Executor) Execute(s string) {
s = strings.TrimSpace(s)
switch s {
Expand Down Expand Up @@ -109,7 +109,7 @@ func executeWithContext(ctx context.Context, cmd *command) error {
}()
select {
case <-ctx.Done():
return errors.New("Cancelled by user")
return errors.New("cancelled by user")
case err := <-c:
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/reva/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
"fmt"
"log"

"google.golang.org/grpc/credentials"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
ins "google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func init() {
}

func main() {

if host != "" {
conf = &config{host}
if err := writeConfig(conf); err != nil {
Expand Down
16 changes: 7 additions & 9 deletions cmd/reva/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ import (
"path/filepath"
"strconv"

"github.com/cs3org/reva/internal/http/services/datagateway"
"github.com/pkg/errors"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/eventials/go-tus"
"github.com/eventials/go-tus/memorystore"
"github.com/studio-b12/gowebdav"

// TODO(labkode): this should not come from this package.
"github.com/cs3org/reva/internal/grpc/services/storageprovider"
"github.com/cs3org/reva/internal/http/services/datagateway"
"github.com/cs3org/reva/pkg/crypto"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rhttp"
"github.com/cs3org/reva/pkg/utils"
"github.com/eventials/go-tus"
"github.com/eventials/go-tus/memorystore"
"github.com/pkg/errors"
"github.com/studio-b12/gowebdav"
)

func uploadCommand() *command {
Expand Down Expand Up @@ -292,7 +291,6 @@ func computeXS(t provider.ResourceChecksumType, r io.Reader) (string, error) {
return "", nil
default:
return "", fmt.Errorf("invalid checksum: %s", t)

}
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/revad/internal/grace/grace.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (w *Watcher) WritePID() error {
// w.log.Info().Msg("error reading pidfile")
//}

// If we get here, then the pidfile didn't exist or we are are in graceful reload and thus we overwrite
// If we get here, then the pidfile didn't exist or we are in graceful reload and thus we overwrite
// or the pid in it doesn't belong to the user running this app.
err := os.WriteFile(w.pidFile, []byte(fmt.Sprintf("%d", os.Getpid())), 0664)
if err != nil {
Expand Down Expand Up @@ -208,7 +208,6 @@ func (w *Watcher) GetListeners(servers map[string]Server) (map[string]net.Listen
} else {
lns[k] = ln
}

}

// kill parent
Expand Down Expand Up @@ -241,7 +240,6 @@ func (w *Watcher) GetListeners(servers map[string]Server) (map[string]net.Listen
return nil, err
}
lns[k] = ln

}
w.lns = lns
return lns, nil
Expand Down
3 changes: 1 addition & 2 deletions cmd/revad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/cs3org/reva/cmd/revad/internal/grace"
"github.com/cs3org/reva/cmd/revad/runtime"
"github.com/cs3org/reva/pkg/sysinfo"

"github.com/google/uuid"
)

Expand Down Expand Up @@ -71,7 +70,7 @@ func main() {
// the pid flag has been set we abort as the pid flag
// is meant to work only with one main configuration.
if len(confs) != 1 && *pidFlag != "" {
fmt.Fprintf(os.Stderr, "cannot run with with multiple configurations and one pid file, remote the -p flag\n")
fmt.Fprintf(os.Stderr, "cannot run with multiple configurations and one pid file, remote the -p flag\n")
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/revad/runtime/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package runtime

import (
// These are all the extensions points for REVA
// These are all the extensions points for REVA.
_ "github.com/cs3org/reva/internal/grpc/interceptors/loader"
_ "github.com/cs3org/reva/internal/grpc/services/loader"
_ "github.com/cs3org/reva/internal/http/interceptors/auth/credential/loader"
Expand Down
6 changes: 0 additions & 6 deletions internal/grpc/interceptors/auth/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ func expandAndVerifyScope(ctx context.Context, req interface{}, tokenScope map[s
if err = resolveUserShare(ctx, ref, tokenScope[k], client, mgr); err == nil {
return nil
}

}
log.Err(err).Msgf("error resolving reference %s under scope %+v", ref.String(), k)
}

}

if checkLightweightScope(ctx, req, tokenScope, client) {
Expand Down Expand Up @@ -289,7 +287,6 @@ func checkIfNestedResource(ctx context.Context, ref *provider.Reference, parent
}

return strings.HasPrefix(childPath, parentPath), nil

}

func extractRefForReaderRole(req interface{}) (*provider.Reference, bool) {
Expand All @@ -314,7 +311,6 @@ func extractRefForReaderRole(req interface{}) (*provider.Reference, bool) {
}

return nil, false

}

func extractRefForUploaderRole(req interface{}) (*provider.Reference, bool) {
Expand All @@ -333,7 +329,6 @@ func extractRefForUploaderRole(req interface{}) (*provider.Reference, bool) {
}

return nil, false

}

func extractRefForEditorRole(req interface{}) (*provider.Reference, bool) {
Expand All @@ -350,7 +345,6 @@ func extractRefForEditorRole(req interface{}) (*provider.Reference, bool) {
}

return nil, false

}

func extractRef(req interface{}, tokenScope map[string]*authpb.Scope) (*provider.Reference, bool) {
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/cs3org/reva/pkg/events"
)

// ShareCreated converts response to event
// ShareCreated converts response to event.
func ShareCreated(r *collaboration.CreateShareResponse) events.ShareCreated {
e := events.ShareCreated{
Sharer: r.Share.Creator,
Expand Down
5 changes: 2 additions & 3 deletions internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import (
"context"
"fmt"

"go-micro.dev/v4/util/log"
"google.golang.org/grpc"

"github.com/asim/go-micro/plugins/events/nats/v4"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
"github.com/cs3org/reva/pkg/events"
"github.com/cs3org/reva/pkg/events/server"
"github.com/cs3org/reva/pkg/rgrpc"
"go-micro.dev/v4/util/log"
"google.golang.org/grpc"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions internal/grpc/interceptors/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package loader

import (
// Load core GRPC services
// Load core GRPC services.
_ "github.com/cs3org/reva/internal/grpc/interceptors/eventsmiddleware"
_ "github.com/cs3org/reva/internal/grpc/interceptors/readonly"
// Add your own service here
// Add your own service here.
)
1 change: 0 additions & 1 deletion internal/grpc/interceptors/recovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package recovery

import (
"context"

"runtime/debug"

"github.com/cs3org/reva/pkg/appctx"
Expand Down
3 changes: 1 addition & 2 deletions internal/grpc/services/applicationauth/applicationauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ func parseConfig(m map[string]interface{}) (*config, error) {
return c, nil
}

// New creates a app auth provider svc
// New creates a app auth provider svc.
func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {

c, err := parseConfig(m)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func parseConfig(m map[string]interface{}) (*config, error) {
return c, nil
}

// New creates a new AppProviderService
// New creates a new AppProviderService.
func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
c, err := parseConfig(m)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/grpc/services/appprovider/appprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

func Test_parseConfig(t *testing.T) {

tests := []struct {
name string
m map[string]interface{}
Expand Down
6 changes: 2 additions & 4 deletions internal/grpc/services/appregistry/appregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ package appregistry
import (
"context"

"google.golang.org/grpc"

registrypb "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
"github.com/cs3org/reva/pkg/app"
"github.com/cs3org/reva/pkg/app/registry/registry"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rgrpc"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/mitchellh/mapstructure"
"google.golang.org/grpc"
)

func init() {
Expand Down Expand Up @@ -63,9 +62,8 @@ func (c *config) init() {
}
}

// New creates a new StorageRegistryService
// New creates a new StorageRegistryService.
func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {

c, err := parseConfig(m)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit edd5a5e

Please sign in to comment.