Skip to content

Commit

Permalink
Org-wide linter (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
carpawell authored Sep 11, 2024
2 parents 3d4a462 + 0656ac6 commit de853f3
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 95 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,7 @@ jobs:
run: go test -race ./...

lint:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master

cover:
name: Coverage
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*.so
*.dylib

.golangci.yml

# Test binary, built with `go test -c`
*.test

Expand Down
58 changes: 0 additions & 58 deletions .golangci.yml

This file was deleted.

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ dep:
@CGO_ENABLED=0 \
go mod tidy -v && echo OK

.golangci.yml:
wget -O $@ https:/nspcc-dev/.github/raw/master/.golangci.yml

# Run linters
lint:
lint: .golangci.yml
@golangci-lint --timeout=5m run

# Run tests with race detection and produce coverage output
Expand All @@ -41,4 +44,4 @@ help:
@echo ''
@echo ' Targets:'
@echo ''
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
2 changes: 1 addition & 1 deletion client/example_container_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ExampleClient_ContainerPut() {
prmDial.SetStreamTimeout(15 * time.Second)

if err = c.Dial(prmDial); err != nil {
panic(fmt.Errorf("dial %v", err))
panic(fmt.Errorf("dial %w", err))
}

// describe new container
Expand Down
2 changes: 1 addition & 1 deletion client/object_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (x *PrmObjectHash) SetRangeList(r ...uint64) {

rs := make([]v2object.Range, ln/2)

for i := 0; i < ln/2; i++ {
for i := range ln / 2 {
rs[i].SetOffset(r[2*i])
rs[i].SetLength(r[2*i+1])
}
Expand Down
2 changes: 1 addition & 1 deletion client/object_replicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestClient_ReplicateObject(t *testing.T) {
initBufPtr := &demuxObj.(*demuxReplicationMessage).msg[0]

var wg sync.WaitGroup
for i := 0; i < 5; i++ {
for range 5 {
wg.Add(1)
go func() {
defer wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestContainer_IterateUserAttributes(t *testing.T) {
mSys := make(map[string]string)
mUsr := make(map[string]string)

for i := 0; i < 10; i++ {
for i := range 10 {
si := strconv.Itoa(i)

keyUsr := "key" + si
Expand Down
2 changes: 1 addition & 1 deletion container/id/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestID_String(t *testing.T) {
func TestID_IsZero(t *testing.T) {
var id cid.ID
require.True(t, id.IsZero())
for i := 0; i < cid.Size; i++ {
for i := range cid.Size {
var id2 cid.ID
id2[i]++
require.False(t, id2.IsZero())
Expand Down
4 changes: 2 additions & 2 deletions netmap/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func newMeanIQRAgg() aggregator {

// newReverseMinNorm returns a normalizer which
// normalize values in range of 0.0 to 1.0 to a minimum value.
func newReverseMinNorm(min float64) normalizer {
return &reverseMinNorm{min: min}
func newReverseMinNorm(minVal float64) normalizer {
return &reverseMinNorm{min: minVal}
}

// newSigmoidNorm returns a normalizer which
Expand Down
2 changes: 1 addition & 1 deletion netmap/network_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func decodeConfigValueBool(val []byte) (bool, error) {

res, err := arr.TryBool()
if err != nil {
return false, fmt.Errorf("invalid bool parameter contract format %s", err)
return false, fmt.Errorf("invalid bool parameter contract format %w", err)
}

return res, nil
Expand Down
2 changes: 1 addition & 1 deletion netmap/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestPlacementPolicy_DeterministicOrder(t *testing.T) {
}

a, b := getIndices(t)
for i := 0; i < 10; i++ {
for range 10 {
x, y := getIndices(t)
require.Equal(t, a, x)
require.Equal(t, b, y)
Expand Down
5 changes: 1 addition & 4 deletions object/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ func TestNewSplitInfoError(t *testing.T) {
)

require.True(t, errors.As(err, &expectedErr))

siErr, ok := err.(*object.SplitInfoError)
require.True(t, ok)
require.Equal(t, si, siErr.SplitInfo())
require.Equal(t, si, expectedErr.SplitInfo())
}

func generateSplitInfo() *object.SplitInfo {
Expand Down
2 changes: 1 addition & 1 deletion object/id/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestID_CalculateIDSignature(t *testing.T) {
func TestID_IsZero(t *testing.T) {
var id oid.ID
require.True(t, id.IsZero())
for i := 0; i < oid.Size; i++ {
for i := range oid.Size {
var id2 oid.ID
id2[i]++
require.False(t, id2.IsZero())
Expand Down
2 changes: 1 addition & 1 deletion object/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestObject_UserAttributes(t *testing.T) {
mSys := make(map[string]string)
mUsr := make(map[string]string)

for i := 0; i < 10; i++ {
for i := range 10 {
si := strconv.Itoa(i)

keyUsr := "key" + si
Expand Down
10 changes: 5 additions & 5 deletions object/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func randomInput(size, sizeLimit uint64) (input, slicer.Options) {
attrNum := rand.Int() % 5
attrs := make([]object.Attribute, attrNum)

for i := 0; i < attrNum; i++ {
for range attrNum {
var attr object.Attribute
attr.SetKey(base64.StdEncoding.EncodeToString(randomData(32)))
attr.SetValue(base64.StdEncoding.EncodeToString(randomData(32)))
Expand Down Expand Up @@ -853,7 +853,7 @@ func TestSlicedObjectsHaveSplitID(t *testing.T) {
writer := &memoryWriter{
opts: opts,
}
sl, err := slicer.New(context.Background(), writer, usr, containerID, usrID, nil)
sl, err := slicer.New(ctx, writer, usr, containerID, usrID, nil)
require.NoError(t, err)

payload := make([]byte, maxObjectSize*overheadAmount)
Expand Down Expand Up @@ -886,13 +886,13 @@ func TestSlicedObjectsHaveSplitID(t *testing.T) {
writer := &memoryWriter{
opts: opts,
}
sl, err := slicer.New(context.Background(), writer, usr, containerID, usrID, nil)
sl, err := slicer.New(ctx, writer, usr, containerID, usrID, nil)
require.NoError(t, err)

payloadWriter, err := sl.InitPut(ctx, nil)
require.NoError(t, err)

for i := uint64(0); i < overheadAmount; i++ {
for range overheadAmount {
payload := make([]byte, maxObjectSize)
//nolint:staticcheck
_, err = rand.Read(payload)
Expand Down Expand Up @@ -925,7 +925,7 @@ func TestSlicedObjectsHaveSplitID(t *testing.T) {
writer := &memoryWriter{
opts: opts,
}
sl, err := slicer.New(context.Background(), writer, usr, containerID, usrID, nil)
sl, err := slicer.New(ctx, writer, usr, containerID, usrID, nil)
require.NoError(t, err)

payload := make([]byte, maxObjectSize-1)
Expand Down
2 changes: 1 addition & 1 deletion pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func (p *innerPool) connection() (internalClient, error) {
return nil, errors.New("no healthy client")
}
attempts := 3 * len(p.clients)
for k := 0; k < attempts; k++ {
for range attempts {
i := p.sampler.Next()
if cp := p.clients[i]; cp.isHealthy() {
return cp, nil
Expand Down
2 changes: 1 addition & 1 deletion pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func TestSwitchAfterErrorThreshold(t *testing.T) {
require.NoError(t, err)
t.Cleanup(pool.Close)

for i := 0; i < errorThreshold; i++ {
for range errorThreshold {
conn, err := pool.connection()
require.NoError(t, err)
require.Equal(t, nodes[0].address, conn.address())
Expand Down
2 changes: 1 addition & 1 deletion pool/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newSampler(probabilities []float64, source rand.Source) *sampler {
sampler.alias = make([]int, n)
// Compute scaled probabilities.
p := make([]float64, n)
for i := 0; i < n; i++ {
for i := range p {
p[i] = probabilities[i] * float64(n)
}
for i, pi := range p {
Expand Down
2 changes: 1 addition & 1 deletion reputation/trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (x *PeerToPeerTrust) SetTrust(t Trust) {

// Trust returns trust set using SetTrust.
//
// Zero PeerToPeerTrust returns zero Trust which is incorect according to the
// Zero PeerToPeerTrust returns zero Trust which is incorrect according to the
// NeoFS API protocol.
func (x PeerToPeerTrust) Trust() (res Trust) {
m := x.m.GetTrust()
Expand Down
2 changes: 1 addition & 1 deletion storagegroup/storagegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (sg *StorageGroup) readFromV2(m storagegroup.StorageGroup, checkFieldPresen
return fmt.Errorf("invalid member #%d: %w", i, err)
}

for j := 0; j < i; j++ {
for j := range i {
if sg.members[j] == sg.members[i] {
return fmt.Errorf("duplicated member %s", sg.members[i])
}
Expand Down
2 changes: 1 addition & 1 deletion user/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestID_String(t *testing.T) {
func TestID_IsZero(t *testing.T) {
var id user.ID
require.True(t, id.IsZero())
for i := 0; i < user.IDSize; i++ {
for i := range user.IDSize {
var id2 user.ID
id2[i]++
require.False(t, id2.IsZero())
Expand Down

0 comments on commit de853f3

Please sign in to comment.