Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Org-wide linter #2943

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,5 @@ jobs:
run: go test -race ./...

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout=5m
name: Lint
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ testfile

# misc
.neofs-cli.yml
.golangci.yml

# debhelpers
**/.debhelper
68 changes: 0 additions & 68 deletions .golangci.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ attribute, which is used for container domain name in NNS contracts (#2954)
- `ObjectService`'s `Put` RPC handler caches up to 10K lists of per-object sorted container nodes (#2901)
- Metabase graveyard scheme (#2929)
- When an error is returned, no additional help output is displayed in cobra-based programs (#2942)
- Use org-wide linter (#2943)

### Removed
- Support for node.key configuration (#2959)
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ test:
@echo "⇒ Running go test"
@go test ./...

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

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

# Run linters in Docker
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-adm/internal/modules/morph/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
var id cid.ID
b := smartcontract.NewBuilder()
for _, cnt := range containers {
id.FromBinary(cnt.Value)
id = cid.NewFromMarshalledContainer(cnt.Value)

Check warning on line 192 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L192

Added line #L192 was not covered by tests
if _, ok := requested[id]; !ok {
continue
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/neofs-adm/internal/modules/morph/estimation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package morph

import (
"crypto/sha256"
"fmt"

"github.com/google/uuid"
Expand Down Expand Up @@ -75,10 +74,7 @@
return fmt.Errorf("container contract hash resolution: %w", err)
}

cIDBytes := make([]byte, sha256.Size)
cID.Encode(cIDBytes)

sID, iter, err := unwrap.SessionIterator(inv.Call(cnrHash, "iterateContainerSizes", epoch, cIDBytes))
sID, iter, err := unwrap.SessionIterator(inv.Call(cnrHash, "iterateContainerSizes", epoch, cID[:]))

Check warning on line 77 in cmd/neofs-adm/internal/modules/morph/estimation.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/estimation.go#L77

Added line #L77 was not covered by tests
if err != nil {
return fmt.Errorf("iterator expansion: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/internal/common/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

err = ReadBinaryOrJSON(cmd, &tok, path)
if err != nil {
return nil, fmt.Errorf("invalid bearer token: %v", err)
return nil, fmt.Errorf("invalid bearer token: %w", err)

Check warning on line 30 in cmd/neofs-cli/internal/common/token.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/internal/common/token.go#L30

Added line #L30 was not covered by tests
}

return &tok, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/accounting/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

balanceOwner, _ := cmd.Flags().GetString(ownerFlag)
if balanceOwner == "" {
idUser = user.ResolveFromECDSAPublicKey(pk.PublicKey)
idUser = user.NewFromECDSAPublicKey(pk.PublicKey)

Check warning on line 40 in cmd/neofs-cli/modules/accounting/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/accounting/balance.go#L40

Added line #L40 was not covered by tests
} else {
return fmt.Errorf("can't decode owner ID wallet address: %w", idUser.DecodeString(balanceOwner))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-cli/modules/acl/extended/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
var containerID cid.ID
if cidArg != "" {
if err := containerID.DecodeString(cidArg); err != nil {
return fmt.Errorf("invalid container ID: %v\n", err)
return fmt.Errorf("invalid container ID: %w\n", err)

Check warning on line 75 in cmd/neofs-cli/modules/acl/extended/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/acl/extended/create.go#L75

Added line #L75 was not covered by tests
}
}

rulesFile, err := getRulesFromFile(fileArg)
if err != nil {
return fmt.Errorf("can't read rules from file: %v\n", err)
return fmt.Errorf("can't read rules from file: %w\n", err)

Check warning on line 81 in cmd/neofs-cli/modules/acl/extended/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/acl/extended/create.go#L81

Added line #L81 was not covered by tests
}

rules = append(rules, rulesFile...)
Expand Down
8 changes: 4 additions & 4 deletions cmd/neofs-cli/modules/acl/extended/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ func TestParseTable(t *testing.T) {
},
}

eaclTable := eacl.NewTable()
var eaclTable eacl.Table

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := util.ParseEACLRule(eaclTable, test.rule)
err := util.ParseEACLRule(&eaclTable, test.rule)
ok := len(test.jsonRecord) > 0
require.Equal(t, ok, err == nil, err)
if ok {
expectedRecord := eacl.NewRecord()
var expectedRecord eacl.Record
err = expectedRecord.UnmarshalJSON([]byte(test.jsonRecord))
require.NoError(t, err)

actualRecord := eaclTable.Records()[len(eaclTable.Records())-1]

equalRecords(t, expectedRecord, &actualRecord)
equalRecords(t, &expectedRecord, &actualRecord)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-cli/modules/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
issuer := tok.Issuer()
cnr.SetOwner(issuer)
} else {
cnr.SetOwner(user.ResolveFromECDSAPublicKey(key.PublicKey))
cnr.SetOwner(user.NewFromECDSAPublicKey(key.PublicKey))

Check warning on line 111 in cmd/neofs-cli/modules/container/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/create.go#L111

Added line #L111 was not covered by tests
}

cnr.SetPlacementPolicy(*placementPolicy)
Expand Down Expand Up @@ -157,7 +157,7 @@
for ; ; t.Reset(waitInterval) {
select {
case <-ctx.Done():
return fmt.Errorf("container creation: %s", common.ErrAwaitTimeout)
return fmt.Errorf("container creation: %w", common.ErrAwaitTimeout)

Check warning on line 160 in cmd/neofs-cli/modules/container/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/create.go#L160

Added line #L160 was not covered by tests
case <-t.C:
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/neofs-cli/modules/container/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
if tok != nil {
common.PrintVerbose(cmd, "Checking session issuer...")

if !tok.Issuer().Equals(owner) {
if tok.Issuer() != owner {

Check warning on line 62 in cmd/neofs-cli/modules/container/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/delete.go#L62

Added line #L62 was not covered by tests
return fmt.Errorf("session issuer differs with the container owner: expected %s, has %s", owner, tok.Issuer())
}
} else {
common.PrintVerbose(cmd, "Checking provided account...")

acc := user.ResolveFromECDSAPublicKey(pk.PublicKey)
acc := user.NewFromECDSAPublicKey(pk.PublicKey)

Check warning on line 68 in cmd/neofs-cli/modules/container/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/delete.go#L68

Added line #L68 was not covered by tests

if !acc.Equals(owner) {
if acc != owner {

Check warning on line 70 in cmd/neofs-cli/modules/container/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/delete.go#L70

Added line #L70 was not covered by tests
return fmt.Errorf("provided account differs with the container owner: expected %s, has %s", owner, acc)
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@
for ; ; t.Reset(waitInterval) {
select {
case <-ctx.Done():
return fmt.Errorf("container deletion: %s", common.ErrAwaitTimeout)
return fmt.Errorf("container deletion: %w", common.ErrAwaitTimeout)

Check warning on line 135 in cmd/neofs-cli/modules/container/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/delete.go#L135

Added line #L135 was not covered by tests
case <-t.C:
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-cli/modules/container/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@
return nil
}

var id cid.ID
cnr.CalculateID(&id)
id := cid.NewFromMarshalledContainer(cnr.Marshal())

Check warning on line 97 in cmd/neofs-cli/modules/container/get.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/get.go#L97

Added line #L97 was not covered by tests
cmd.Println("container ID:", id)

cmd.Println("owner ID:", cnr.Owner())
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/container/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
}

if flagVarListContainerOwner == "" {
idUser = user.ResolveFromECDSAPublicKey(key.PublicKey)
idUser = user.NewFromECDSAPublicKey(key.PublicKey)
} else {

Check warning on line 43 in cmd/neofs-cli/modules/container/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/list.go#L42-L43

Added lines #L42 - L43 were not covered by tests
err := idUser.DecodeString(flagVarListContainerOwner)
if err != nil {
return fmt.Errorf("invalid user ID: %w", err)
Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-cli/modules/container/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ var containerNodesCmd = &cobra.Command{
return fmt.Errorf("unable to get netmap snapshot: %w", err)
}

var id cid.ID
cnr.CalculateID(&id)
id := cid.NewFromMarshalledContainer(cnr.Marshal())

policy := cnr.PlacementPolicy()

Expand Down
8 changes: 4 additions & 4 deletions cmd/neofs-cli/modules/container/set_eacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@
if tok != nil {
common.PrintVerbose(cmd, "Checking session issuer...")

if !tok.Issuer().Equals(owner) {
if tok.Issuer() != owner {

Check warning on line 82 in cmd/neofs-cli/modules/container/set_eacl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/set_eacl.go#L82

Added line #L82 was not covered by tests
return fmt.Errorf("session issuer differs with the container owner: expected %s, has %s", owner, tok.Issuer())
}
} else {
common.PrintVerbose(cmd, "Checking provided account...")

acc := user.ResolveFromECDSAPublicKey(pk.PublicKey)
acc := user.NewFromECDSAPublicKey(pk.PublicKey)

Check warning on line 88 in cmd/neofs-cli/modules/container/set_eacl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/set_eacl.go#L88

Added line #L88 was not covered by tests

if !acc.Equals(owner) {
if acc != owner {

Check warning on line 90 in cmd/neofs-cli/modules/container/set_eacl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/set_eacl.go#L90

Added line #L90 was not covered by tests
return fmt.Errorf("provided account differs with the container owner: expected %s, has %s", owner, acc)
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@
for ; ; t.Reset(waitInterval) {
select {
case <-ctx.Done():
return fmt.Errorf("eACL setting: %s", common.ErrAwaitTimeout)
return fmt.Errorf("eACL setting: %w", common.ErrAwaitTimeout)

Check warning on line 139 in cmd/neofs-cli/modules/container/set_eacl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/set_eacl.go#L139

Added line #L139 was not covered by tests
case <-t.C:
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/container/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

err := common.ReadBinaryOrJSON(cmd, &res, path)
if err != nil {
return nil, fmt.Errorf("read container session: %v", err)
return nil, fmt.Errorf("read container session: %w", err)

Check warning on line 52 in cmd/neofs-cli/modules/container/util.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/container/util.go#L52

Added line #L52 was not covered by tests
}

common.PrintVerbose(cmd, "Session successfully read.")
Expand Down
6 changes: 1 addition & 5 deletions cmd/neofs-cli/modules/control/synchronize_tree.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package control

import (
"crypto/sha256"
"errors"
"fmt"

Expand Down Expand Up @@ -55,12 +54,9 @@

height, _ := cmd.Flags().GetUint64("height")

rawCID := make([]byte, sha256.Size)
cnr.Encode(rawCID)

req := &control.SynchronizeTreeRequest{
Body: &control.SynchronizeTreeRequest_Body{
ContainerId: rawCID,
ContainerId: cnr[:],

Check warning on line 59 in cmd/neofs-cli/modules/control/synchronize_tree.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/synchronize_tree.go#L59

Added line #L59 was not covered by tests
TreeId: treeID,
Height: height,
},
Expand Down
22 changes: 11 additions & 11 deletions cmd/neofs-cli/modules/object/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@
}
}

func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) {
func printObjectID(cmd *cobra.Command, recv func() oid.ID) {

Check warning on line 138 in cmd/neofs-cli/modules/object/head.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/head.go#L138

Added line #L138 was not covered by tests
var strID string

id, ok := recv()
if ok {
id := recv()
if !id.IsZero() {

Check warning on line 142 in cmd/neofs-cli/modules/object/head.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/head.go#L141-L142

Added lines #L141 - L142 were not covered by tests
strID = id.String()
} else {
strID = "<empty>"
Expand All @@ -148,11 +148,11 @@
cmd.Printf("ID: %s\n", strID)
}

func printContainerID(cmd *cobra.Command, recv func() (cid.ID, bool)) {
func printContainerID(cmd *cobra.Command, recv func() cid.ID) {

Check warning on line 151 in cmd/neofs-cli/modules/object/head.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/head.go#L151

Added line #L151 was not covered by tests
var strID string

id, ok := recv()
if ok {
id := recv()
if !id.IsZero() {

Check warning on line 155 in cmd/neofs-cli/modules/object/head.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/head.go#L154-L155

Added lines #L154 - L155 were not covered by tests
strID = id.String()
} else {
strID = "<empty>"
Expand All @@ -162,8 +162,8 @@
}

func printHeader(cmd *cobra.Command, obj *object.Object) error {
printObjectID(cmd, obj.ID)
printContainerID(cmd, obj.ContainerID)
printObjectID(cmd, obj.GetID)
printContainerID(cmd, obj.GetContainerID)

Check warning on line 166 in cmd/neofs-cli/modules/object/head.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/head.go#L165-L166

Added lines #L165 - L166 were not covered by tests
cmd.Printf("Owner: %s\n", obj.OwnerID())
cmd.Printf("CreatedAt: %d\n", obj.CreationEpoch())
cmd.Printf("Size: %d\n", obj.PayloadSize())
Expand Down Expand Up @@ -197,11 +197,11 @@
cmd.Printf("Split ID: %s\n", splitID)
}

if oid, ok := obj.ParentID(); ok {
cmd.Printf("Split ParentID: %s\n", oid)
if oID := obj.GetParentID(); !oID.IsZero() {
cmd.Printf("Split ParentID: %s\n", oID)

Check warning on line 201 in cmd/neofs-cli/modules/object/head.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/head.go#L200-L201

Added lines #L200 - L201 were not covered by tests
}

if prev, ok := obj.PreviousID(); ok {
if prev := obj.GetPreviousID(); !prev.IsZero() {

Check warning on line 204 in cmd/neofs-cli/modules/object/head.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/head.go#L204

Added line #L204 was not covered by tests
cmd.Printf("Split PreviousID: %s\n", prev)
}

Expand Down
Loading
Loading