Skip to content

Commit

Permalink
Use revive instead of golint (dapr#4555)
Browse files Browse the repository at this point in the history
* Use revive instead of golint

Signed-off-by: pigletfly <[email protected]>

* Fixed test

Signed-off-by: Alessandro (Ale) Segala <[email protected]>

Co-authored-by: Alessandro (Ale) Segala <[email protected]>
Co-authored-by: Yaron Schneider <[email protected]>
Co-authored-by: Artur Souza <[email protected]>
  • Loading branch information
4 people authored May 5, 2022
1 parent f471c46 commit ade2935
Show file tree
Hide file tree
Showing 54 changed files with 161 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dapr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
GOVER: 1.17
GOLANGCILINT_VER: v1.31
GOLANGCILINT_VER: v1.45.2
GOOS: ${{ matrix.target_os }}
GOARCH: ${{ matrix.target_arch }}
GOPROXY: https://proxy.golang.org
Expand Down
28 changes: 27 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ linters-settings:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: default
# locale: default
ignore-words:
- someword
lll:
Expand Down Expand Up @@ -247,6 +247,32 @@ linters:
- exhaustive
- noctx
- gci
- golint
- tparallel
- paralleltest
- wrapcheck
- tagliatelle
- ireturn
- exhaustivestruct
- errchkjson
- contextcheck
- gomoddirectives
- godot
- cyclop
- varnamelen
- gosec
- errorlint
- forcetypeassert
- ifshort
- maintidx
- nilnil
- predeclared
- tenv
- thelper
- wastedassign
- containedctx
- gosimple
- forbidigo
issues:
exclude:
# staticcheck
Expand Down
2 changes: 1 addition & 1 deletion pkg/actors/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// ErrActorDisposed is the error when runtime tries to hold the lock of the disposed actor.
var ErrActorDisposed error = errors.New("actor is already disposed")
var ErrActorDisposed = errors.New("actor is already disposed")

// actor represents single actor object and maintains its turn-based concurrency.
type actor struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/actors/actor_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"go.uber.org/atomic"
)

var ErrMaxStackDepthExceeded error = errors.New("Maximum stack depth exceeded")
var ErrMaxStackDepthExceeded = errors.New("Maximum stack depth exceeded")

type ActorLock struct {
methodLock *sync.Mutex
Expand Down
11 changes: 7 additions & 4 deletions pkg/actors/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func NewActors(
tracingSpec configuration.TracingSpec,
features []configuration.FeatureSpec,
resiliency resiliency.Provider,
stateStoreName string) Actors {
stateStoreName string,
) Actors {
var transactionalStore state.TransactionalStore
if stateStore != nil {
features := stateStore.Features()
Expand Down Expand Up @@ -344,7 +345,8 @@ func (a *actorsRuntime) callRemoteActorWithRetry(
numRetries int,
backoffInterval time.Duration,
fn func(ctx context.Context, targetAddress, targetID string, req *invokev1.InvokeMethodRequest) (*invokev1.InvokeMethodResponse, error),
targetAddress, targetID string, req *invokev1.InvokeMethodRequest) (*invokev1.InvokeMethodResponse, error) {
targetAddress, targetID string, req *invokev1.InvokeMethodRequest,
) (*invokev1.InvokeMethodResponse, error) {
for i := 0; i < numRetries; i++ {
resp, err := fn(ctx, targetAddress, targetID, req)
if err == nil {
Expand Down Expand Up @@ -445,7 +447,8 @@ func (a *actorsRuntime) callLocalActor(ctx context.Context, req *invokev1.Invoke
func (a *actorsRuntime) callRemoteActor(
ctx context.Context,
targetAddress, targetID string,
req *invokev1.InvokeMethodRequest) (*invokev1.InvokeMethodResponse, error) {
req *invokev1.InvokeMethodRequest,
) (*invokev1.InvokeMethodResponse, error) {
conn, err := a.grpcConnectionFn(context.TODO(), targetAddress, targetID, a.config.Namespace, false, false, false)
if err != nil {
return nil, err
Expand Down Expand Up @@ -960,7 +963,7 @@ func (m *ActorMetadata) calculateEtag(partitionID uint32) *string {

func (m *ActorMetadata) removeReminderFromPartition(reminderRefs []actorReminderReference, actorType, actorID, reminderName string) ([]Reminder, string, *string) {
// First, we find the partition
var partitionID uint32 = 0
var partitionID uint32
if m.RemindersMetadata.PartitionCount > 0 {
for _, reminderRef := range reminderRefs {
if reminderRef.reminder.ActorType == actorType && reminderRef.reminder.ActorID == actorID && reminderRef.reminder.Name == reminderName {
Expand Down
1 change: 0 additions & 1 deletion pkg/actors/actors_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/actors/internal/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func NewActorPlacement(
serverAddr []string, clientCert *dapr_credentials.CertChain,
appID, runtimeHostName string, actorTypes []string,
appHealthFn func() bool,
afterTableUpdateFn func()) *ActorPlacement {
afterTableUpdateFn func(),
) *ActorPlacement {
return &ActorPlacement{
actorTypes: actorTypes,
appID: appID,
Expand Down
2 changes: 1 addition & 1 deletion pkg/actors/internal/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (s *testServer) ReportDaprStatus(srv placementv1pb.Placement_ReportDaprStat
return nil
} else if err != nil {
s.recvError = err
return nil
return err
}
s.recvCount.Inc()
s.lastHost = req
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/standalone_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const configPrefix = "."

func writeTempConfig(path, content string) error {
return os.WriteFile(filepath.Join(configPrefix, path), []byte(content), fs.FileMode(0644))
return os.WriteFile(filepath.Join(configPrefix, path), []byte(content), fs.FileMode(0o644))
}

func TestLoadComponentsFromFile(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func sortAndValidateSecretsConfiguration(conf *Configuration) error {
// IsSecretAllowed Check if the secret is allowed to be accessed.
func (c SecretsScope) IsSecretAllowed(key string) bool {
// By default, set allow access for the secret store.
var access string = AllowAccess
access := AllowAccess
// Check and set deny access.
if strings.EqualFold(c.DefaultAccess, DenyAccess) {
access = DenyAccess
Expand Down
4 changes: 2 additions & 2 deletions pkg/credentials/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
func GetServerOptions(certChain *CertChain) ([]grpc.ServerOption, error) {
opts := []grpc.ServerOption{}
if certChain == nil {
return opts, nil
return nil, nil
}

cp := x509.NewCertPool()
cp.AppendCertsFromPEM(certChain.RootCA)

cert, err := tls.X509KeyPair(certChain.Cert, certChain.Key)
if err != nil {
return opts, nil
return nil, err
}

// nolint:gosec
Expand Down
6 changes: 2 additions & 4 deletions pkg/credentials/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ func TestServerOptions(t *testing.T) {
Cert: []byte(nil),
Key: []byte(nil),
}
opts, err := GetServerOptions(chain)
assert.Nil(t, err)
assert.NotNil(t, opts)
assert.Len(t, opts, 0)
_, err := GetServerOptions(chain)
assert.Error(t, err)
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/diagnostics/http_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func UpdateSpanStatusFromHTTPStatus(span *trace.Span, code int) {

// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#status
func traceStatusFromHTTPCode(httpCode int) trace.Status {
var code codes.Code = codes.Unknown
code := codes.Unknown
switch httpCode {
case http.StatusUnauthorized:
code = codes.Unauthenticated
Expand Down
3 changes: 2 additions & 1 deletion pkg/grpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ func NewAPI(
accessControlList *config.AccessControlList,
appProtocol string,
getComponentsFn func() []components_v1alpha.Component,
shutdown func()) API {
shutdown func(),
) API {
transactionalStateStores := map[string]state.TransactionalStore{}
for key, store := range stateStores {
if state.FeatureTransactional.IsPresent(store.Features()) {
Expand Down
1 change: 1 addition & 0 deletions pkg/http/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,7 @@ func (c fakeStateStore) BulkGet(req []state.GetRequest) (bool, []state.BulkGetRe
}

func (c fakeStateStore) Init(metadata state.Metadata) error {
//nolint:staticcheck
c.counter = 0
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/injector/pod_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const (
)

func (i *injector) getPodPatchOperations(ar *v1.AdmissionReview,
namespace, image, imagePullPolicy string, kubeClient kubernetes.Interface, daprClient scheme.Interface) ([]PatchOperation, error) {
namespace, image, imagePullPolicy string, kubeClient kubernetes.Interface, daprClient scheme.Interface,
) ([]PatchOperation, error) {
req := ar.Request
var pod corev1.Pod
if err := json.Unmarshal(req.Object.Raw, &pod); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/messaging/direct_messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func NewDirectMessaging(
appChannel channel.AppChannel,
clientConnFn messageClientConnection,
resolver nr.Resolver,
tracingSpec config.TracingSpec, maxRequestBodySize int, proxy Proxy, readBufferSize int, streamRequestBody bool) DirectMessaging {
tracingSpec config.TracingSpec, maxRequestBodySize int, proxy Proxy, readBufferSize int, streamRequestBody bool,
) DirectMessaging {
hAddr, _ := utils.GetHostAddress()
hName, _ := os.Hostname()

Expand Down Expand Up @@ -142,7 +143,8 @@ func (d *directMessaging) invokeWithRetry(
backoffInterval time.Duration,
app remoteApp,
fn func(ctx context.Context, appID, namespace, appAddress string, req *invokev1.InvokeMethodRequest) (*invokev1.InvokeMethodResponse, error),
req *invokev1.InvokeMethodRequest) (*invokev1.InvokeMethodResponse, error) {
req *invokev1.InvokeMethodRequest,
) (*invokev1.InvokeMethodResponse, error) {
for i := 0; i < numRetries; i++ {
resp, err := fn(ctx, app.id, app.namespace, app.address, req)
if err == nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/messaging/grpc_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (p *proxy) intercept(ctx context.Context, fullName string) (context.Context
appID := v[0]

if p.remoteAppFn == nil {
return ctx, nil, errors.Errorf("failed to proxy request: proxy not initialized. daprd startup may be incomplete.")
return ctx, nil, errors.Errorf("failed to proxy request: proxy not initialized. daprd startup may be incomplete")
}

target, isLocal, err := p.isLocalInternal(appID)
Expand Down Expand Up @@ -128,7 +128,7 @@ func (p *proxy) IsLocal(appID string) (bool, error) {

func (p *proxy) isLocalInternal(appID string) (remoteApp, bool, error) {
if p.remoteAppFn == nil {
return remoteApp{}, false, errors.Errorf("failed to proxy request: proxy not initialized. daprd startup may be incomplete.")
return remoteApp{}, false, errors.Errorf("failed to proxy request: proxy not initialized. daprd startup may be incomplete")
}

target, err := p.remoteAppFn(appID)
Expand Down
6 changes: 4 additions & 2 deletions pkg/metrics/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (o *Options) MetricsPort() uint64 {
// AttachCmdFlags attaches metrics options to command flags.
func (o *Options) AttachCmdFlags(
stringVar func(p *string, name string, value string, usage string),
boolVar func(p *bool, name string, value bool, usage string)) {
boolVar func(p *bool, name string, value bool, usage string),
) {
stringVar(
&o.Port,
"metrics-port",
Expand All @@ -66,7 +67,8 @@ func (o *Options) AttachCmdFlags(

// AttachCmdFlag attaches single metrics option to command flags.
func (o *Options) AttachCmdFlag(
stringVar func(p *string, name string, value string, usage string)) {
stringVar func(p *string, name string, value string, usage string),
) {
stringVar(
&o.Port,
"metrics-port",
Expand Down
3 changes: 2 additions & 1 deletion pkg/operator/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ type chanGracefully struct {
}

func initChanGracefully(ch chan *componentsapi.Component) (
c *chanGracefully) {
c *chanGracefully,
) {
return &chanGracefully{
ch: ch,
isClosed: false,
Expand Down
2 changes: 1 addition & 1 deletion pkg/placement/raft/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/pkg/errors"
)

const defaultDirPermission = 0755
const defaultDirPermission = 0o755

func ensureDir(dirName string) error {
info, err := os.Stat(dirName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/placement/raft/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestEnsureDir(t *testing.T) {
})

t.Run("ensure the existing directory", func(t *testing.T) {
err := os.Mkdir(testDir, 0700)
err := os.Mkdir(testDir, 0o700)
assert.NoError(t, err)
err = ensureDir(testDir)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/resiliency/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestPolicyRetry(t *testing.T) {
fn := func(ctx context.Context) error {
if called < maxCalls {
called++
return errors.Errorf("Called (%d) vs Max (%d)!", called, maxCalls)
return errors.Errorf("Called (%d) vs Max (%d)", called, maxCalls)
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/runtime/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func NewRuntimeConfig(
id string, placementAddresses []string,
controlPlaneAddress, allowedOrigins, globalConfig, componentsPath, appProtocol, mode string,
httpPort, internalGRPCPort, apiGRPCPort int, apiListenAddresses []string, publicPort *int, appPort, profilePort int,
enableProfiling bool, maxConcurrency int, mtlsEnabled bool, sentryAddress string, appSSL bool, maxRequestBodySize int, unixDomainSocket string, readBufferSize int, streamRequestBody bool, gracefulShutdownDuration time.Duration, enableAPILogging bool) *Config {
enableProfiling bool, maxConcurrency int, mtlsEnabled bool, sentryAddress string, appSSL bool, maxRequestBodySize int, unixDomainSocket string, readBufferSize int, streamRequestBody bool, gracefulShutdownDuration time.Duration, enableAPILogging bool,
) *Config {
return &Config{
ID: id,
HTTPPort: httpPort,
Expand Down
6 changes: 3 additions & 3 deletions pkg/runtime/pubsub/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func testDeclarativeSubscriptionV2() subscriptionsapi_v2alpha1.Subscription {

func writeSubscriptionToDisk(subscription interface{}, filePath string) {
b, _ := yaml.Marshal(subscription)
os.WriteFile(filePath, b, 0600)
os.WriteFile(filePath, b, 0o600)
}

func TestDeclarativeSubscriptionsV1(t *testing.T) {
dir := filepath.Join(".", "components")
os.Mkdir(dir, 0777)
os.Mkdir(dir, 0o777)
defer os.RemoveAll(dir)

t.Run("load single valid subscription", func(t *testing.T) {
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestDeclarativeSubscriptionsV1(t *testing.T) {

func TestDeclarativeSubscriptionsV2(t *testing.T) {
dir := filepath.Join(".", "componentsV2")
os.Mkdir(dir, 0777)
os.Mkdir(dir, 0o777)
defer os.RemoveAll(dir)

t.Run("load single valid subscription", func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/runtime/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
)

var (
timeoutSeconds int = 60
requestTimeoutMillis int = 500
periodMillis int = 100
urlFormat string = "http://localhost:%s/v1.0/healthz/outbound"
timeoutSeconds = 60
requestTimeoutMillis = 500
periodMillis = 100
urlFormat = "http://localhost:%s/v1.0/healthz/outbound"
)

func waitUntilDaprOutboundReady(daprHTTPPort string) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/sentry/ca/certificate_authority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func getTestCertAuth() CertificateAuthority {
}

func writeTestCredentialsToDisk() {
os.WriteFile("ca.crt", []byte(rootCert), 0644)
os.WriteFile("issuer.crt", []byte(issuerCert), 0644)
os.WriteFile("issuer.key", []byte(issuerKey), 0644)
os.WriteFile("ca.crt", []byte(rootCert), 0o644)
os.WriteFile("issuer.crt", []byte(issuerCert), 0o644)
os.WriteFile("issuer.key", []byte(issuerKey), 0o644)
}

func cleanupCredentials() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/sentry/certs/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ func CredentialsExist(conf config.SentryConfig) (bool, error) {

/* #nosec. */
func storeSelfhosted(rootCertPem, issuerCertPem, issuerKeyPem []byte, rootCertPath, issuerCertPath, issuerKeyPath string) error {
err := os.WriteFile(rootCertPath, rootCertPem, 0644)
err := os.WriteFile(rootCertPath, rootCertPem, 0o644)
if err != nil {
return errors.Wrapf(err, "failed saving file to %s", rootCertPath)
}

err = os.WriteFile(issuerCertPath, issuerCertPem, 0644)
err = os.WriteFile(issuerCertPath, issuerCertPem, 0o644)
if err != nil {
return errors.Wrapf(err, "failed saving file to %s", issuerCertPath)
}

err = os.WriteFile(issuerKeyPath, issuerKeyPem, 0644)
err = os.WriteFile(issuerKeyPath, issuerKeyPem, 0o644)
if err != nil {
return errors.Wrapf(err, "failed saving file to %s", issuerKeyPath)
}
Expand Down
Loading

0 comments on commit ade2935

Please sign in to comment.