diff --git a/.golangci.yaml b/.golangci.yaml index 553bbc20..d22f033c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -29,7 +29,7 @@ linters: - staticcheck - revive - gosec - - exportloopref + - copyloopvar - prealloc linters-settings: gocritic: diff --git a/go/grpc/gogoreflection/serverreflection.go b/go/grpc/gogoreflection/serverreflection.go index 31b73652..f5544c12 100644 --- a/go/grpc/gogoreflection/serverreflection.go +++ b/go/grpc/gogoreflection/serverreflection.go @@ -184,7 +184,7 @@ func fqn(prefix, name string) string { // fileDescForType gets the file descriptor for the given type. // The given type should be a proto message. func (s *serverReflectionServer) fileDescForType(st reflect.Type) (*dpb.FileDescriptorProto, error) { - m, ok := reflect.Zero(reflect.PtrTo(st)).Interface().(protoMessage) + m, ok := reflect.Zero(reflect.PointerTo(st)).Interface().(protoMessage) if !ok { return nil, fmt.Errorf("failed to create message from type: %v", st) } @@ -232,7 +232,7 @@ func typeForName(name string) (reflect.Type, error) { } func fileDescContainingExtension(st reflect.Type, ext int32) (*dpb.FileDescriptorProto, error) { - m, ok := reflect.Zero(reflect.PtrTo(st)).Interface().(proto.Message) + m, ok := reflect.Zero(reflect.PointerTo(st)).Interface().(proto.Message) if !ok { return nil, fmt.Errorf("failed to create message from type: %v", st) } @@ -247,7 +247,7 @@ func fileDescContainingExtension(st reflect.Type, ext int32) (*dpb.FileDescripto } func (s *serverReflectionServer) allExtensionNumbersForType(st reflect.Type) ([]int32, error) { - m, ok := reflect.Zero(reflect.PtrTo(st)).Interface().(proto.Message) + m, ok := reflect.Zero(reflect.PointerTo(st)).Interface().(proto.Message) if !ok { return nil, fmt.Errorf("failed to create message from type: %v", st) } diff --git a/go/inventory/v1/resourcepair.go b/go/inventory/v1/resourcepair.go index 5332da19..5a1aa7ec 100644 --- a/go/inventory/v1/resourcepair.go +++ b/go/inventory/v1/resourcepair.go @@ -68,7 +68,7 @@ func (m *ResourcePair) SubMilliNLZ(val types.ResourceValue) bool { } allocated := m.Allocated.DeepCopy() - allocated.Add(*resource.NewMilliQuantity(int64(val.Value()), resource.DecimalSI)) + allocated.Add(*resource.NewMilliQuantity(int64(val.Value()), resource.DecimalSI)) // nolint: gosec allocatable := m.Allocatable.DeepCopy() @@ -91,7 +91,7 @@ func (m *ResourcePair) SubNLZ(val types.ResourceValue) bool { } allocated := m.Allocated.DeepCopy() - allocated.Add(*resource.NewQuantity(int64(val.Value()), resource.DecimalSI)) + allocated.Add(*resource.NewQuantity(int64(val.Value()), resource.DecimalSI)) // nolint: gosec allocatable := m.Allocatable.DeepCopy() diff --git a/go/manifest/v2beta3/manifest_cross_validation_test.go b/go/manifest/v2beta3/manifest_cross_validation_test.go index ffd64f65..07238272 100644 --- a/go/manifest/v2beta3/manifest_cross_validation_test.go +++ b/go/manifest/v2beta3/manifest_cross_validation_test.go @@ -63,7 +63,7 @@ func TestManifestWithDeployment(t *testing.T) { } func TestManifestWithDeploymentMultipleCount(t *testing.T) { - addl := uint32(tutil.RandRangeInt(1, 20)) + addl := uint32(tutil.RandRangeInt(1, 20)) // nolint: gosec m := simpleManifest(addl) deployment := simpleDeployment(t, m[0].Services[0].Expose, addl) diff --git a/go/manifest/v2beta3/serviceexpose.go b/go/manifest/v2beta3/serviceexpose.go index dc764834..2d80d875 100644 --- a/go/manifest/v2beta3/serviceexpose.go +++ b/go/manifest/v2beta3/serviceexpose.go @@ -96,13 +96,13 @@ func (s *ServiceExpose) checkAgainstResources(res *dtypes.ResourceUnit, eps vali } func (s *ServiceExpose) IsIngress() bool { - return s.Proto == TCP && s.Global && 80 == s.GetExternalPort() + return s.Proto == TCP && s.Global && uint32(80) == s.GetExternalPort() } -func (s *ServiceExpose) GetExternalPort() int32 { +func (s *ServiceExpose) GetExternalPort() uint32 { if s.ExternalPort == 0 { - return int32(s.Port) + return s.Port } - return int32(s.ExternalPort) + return s.ExternalPort } diff --git a/go/node/client/v1beta3/testutil/base.go b/go/node/client/v1beta3/testutil/base.go index a206bcd6..dc80fa97 100644 --- a/go/node/client/v1beta3/testutil/base.go +++ b/go/node/client/v1beta3/testutil/base.go @@ -95,7 +95,7 @@ func Resources(t testing.TB) dtypes.ResourceUnits { coin := sdk.NewDecCoin(CoinDenom, sdk.NewInt(rand.Int63n(9999)+1)) res := dtypes.ResourceUnit{ Resources: types.Resources{ - ID: uint32(i) + 1, + ID: uint32(i) + 1, // nolint: gosec CPU: &types.CPU{ Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().Unit.Min.CPU)), }, diff --git a/go/node/market/v1beta5/escrow.go b/go/node/market/v1beta5/escrow.go index 761d5f7d..9a335094 100644 --- a/go/node/market/v1beta5/escrow.go +++ b/go/node/market/v1beta5/escrow.go @@ -58,5 +58,5 @@ func LeaseIDFromEscrowAccount(id etypes.AccountID, pid string) (v1.LeaseID, bool v1.MakeBidID( v1.MakeOrderID( dtypesv1.MakeGroupID( - did, uint32(gseq)), uint32(oseq)), owner)), true + did, uint32(gseq)), uint32(oseq)), owner)), true // nolint: gosec } diff --git a/go/testutil/base.go b/go/testutil/base.go index a2cd7959..3fd6dc02 100644 --- a/go/testutil/base.go +++ b/go/testutil/base.go @@ -96,7 +96,7 @@ func Resources(t testing.TB) []dtypes.ResourceUnit { coin := sdk.NewDecCoin(CoinDenom, sdk.NewInt(rand.Int63n(9999)+1)) res := dtypes.ResourceUnit{ Resources: types.Resources{ - ID: uint32(i) + 1, + ID: uint32(i) + 1, // nolint: gosec CPU: &types.CPU{ Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().Unit.Min.CPU)), }, diff --git a/go/testutil/deployment.go b/go/testutil/deployment.go index 229b8242..ab502a91 100644 --- a/go/testutil/deployment.go +++ b/go/testutil/deployment.go @@ -56,7 +56,7 @@ func DeploymentGroups(t testing.TB, did dtypes.DeploymentID, gseq uint32) dtypes count := rand.Intn(5) + 5 // nolint:gosec vals := make(dtypesv1beta4.Groups, 0, count) for i := 0; i < count; i++ { - vals = append(vals, DeploymentGroup(t, did, gseq+uint32(i))) + vals = append(vals, DeploymentGroup(t, did, gseq+uint32(i))) // nolint: gosec } return vals } diff --git a/go/testutil/v1beta3/base.go b/go/testutil/v1beta3/base.go index ebf6f2ad..1e8bf5ab 100644 --- a/go/testutil/v1beta3/base.go +++ b/go/testutil/v1beta3/base.go @@ -72,7 +72,7 @@ func RandStorageQuantity() uint64 { func ResourcesList(t testing.TB, startID uint32) dtypes.ResourceUnits { require.GreaterOrEqual(t, startID, uint32(1)) - count := uint32(rand.Intn(10)) + 1 + count := uint32(rand.Intn(10)) + 1 // nolint: gosec vals := make(dtypes.ResourceUnits, 0, count) for i := uint32(0); i < count; i++ { diff --git a/go/testutil/v1beta3/deployment.go b/go/testutil/v1beta3/deployment.go index 28d590e6..3b78cf35 100644 --- a/go/testutil/v1beta3/deployment.go +++ b/go/testutil/v1beta3/deployment.go @@ -57,7 +57,7 @@ func DeploymentGroups(t testing.TB, did dtypes.DeploymentID, gseq uint32) dtypes count := rand.Intn(5) + 5 // nolint:gosec vals := make(dtypesv1beta4.Groups, 0, count) for i := 0; i < count; i++ { - vals = append(vals, DeploymentGroup(t, did, gseq+uint32(i))) + vals = append(vals, DeploymentGroup(t, did, gseq+uint32(i))) // nolint: gosec } return vals }