diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-04-25 15:15:52 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-04-26 18:12:22 +0200 |
commit | 51fbf3da9ee34a8143df5baeda6032c1747446d2 (patch) | |
tree | f5edbd047f5e4aea72b710403a0aa208b238c83b /pkg/k8s.io/apimachinery | |
parent | 216d9243077f478a9c7ffda1c6e0b1fcbad9ee76 (diff) | |
download | podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.gz podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.bz2 podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.zip |
enable gocritic linter
The linter ensures a common code style.
- use switch/case instead of else if
- use if instead of switch/case for single case statement
- add space between comment and text
- detect the use of defer with os.Exit()
- use short form var += "..." instead of var = var + "..."
- detect problems with append()
```
newSlice := append(orgSlice, val)
```
This could lead to nasty bugs because the orgSlice will be changed in
place if it has enough capacity too hold the new elements. Thus we
newSlice might not be a copy.
Of course most of the changes are just cosmetic and do not cause any
logic errors but I think it is a good idea to enforce a common style.
This should help maintainability.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/k8s.io/apimachinery')
-rw-r--r-- | pkg/k8s.io/apimachinery/pkg/api/resource/amount.go | 4 | ||||
-rw-r--r-- | pkg/k8s.io/apimachinery/pkg/api/resource/math.go | 8 | ||||
-rw-r--r-- | pkg/k8s.io/apimachinery/pkg/apis/meta/v1/types.go | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go b/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go index a8866a43e..9f76f9154 100644 --- a/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go +++ b/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go @@ -231,13 +231,13 @@ func (a int64Amount) AsCanonicalBytes(out []byte) (result []byte, exponent int32 if !ok { return infDecAmount{a.AsDec()}.AsCanonicalBytes(out) } - exponent = exponent - 1 + exponent-- case 2, -1: amount, ok = int64MultiplyScale100(amount) if !ok { return infDecAmount{a.AsDec()}.AsCanonicalBytes(out) } - exponent = exponent - 2 + exponent -= 2 } return strconv.AppendInt(out, amount, 10), exponent } diff --git a/pkg/k8s.io/apimachinery/pkg/api/resource/math.go b/pkg/k8s.io/apimachinery/pkg/api/resource/math.go index 7b4fa5a36..9d03f5c05 100644 --- a/pkg/k8s.io/apimachinery/pkg/api/resource/math.go +++ b/pkg/k8s.io/apimachinery/pkg/api/resource/math.go @@ -171,7 +171,7 @@ func negativeScaleInt64(base int64, scale Scale) (result int64, exact bool) { if !fraction && value%10 != 0 { fraction = true } - value = value / 10 + value /= 10 if value == 0 { if fraction { if base > 0 { @@ -265,18 +265,18 @@ func removeInt64Factors(value int64, base int64) (result int64, times int32) { case 10: for result >= 10 && result%10 == 0 { times++ - result = result / 10 + result /= 10 } // allow the compiler to optimize the common cases case 1024: for result >= 1024 && result%1024 == 0 { times++ - result = result / 1024 + result /= 1024 } default: for result >= base && result%base == 0 { times++ - result = result / base + result /= base } } if negative { diff --git a/pkg/k8s.io/apimachinery/pkg/apis/meta/v1/types.go b/pkg/k8s.io/apimachinery/pkg/apis/meta/v1/types.go index 697817774..39073c06b 100644 --- a/pkg/k8s.io/apimachinery/pkg/apis/meta/v1/types.go +++ b/pkg/k8s.io/apimachinery/pkg/apis/meta/v1/types.go @@ -1156,7 +1156,7 @@ type ManagedFieldsEntry struct { Time *Time `json:"time,omitempty"` // Fields is tombstoned to show why 5 is a reserved protobuf tag. - //Fields *Fields `json:"fields,omitempty"` + // Fields *Fields `json:"fields,omitempty"` // FieldsType is the discriminator for the different fields format and version. // There is currently only one possible value: "FieldsV1" |