Skip to content

Commit

Permalink
Org-wide linter (#2943)
Browse files Browse the repository at this point in the history
Closes #2940.
  • Loading branch information
roman-khimov authored Oct 7, 2024
2 parents b528d44 + 3ebb2d8 commit 624f636
Show file tree
Hide file tree
Showing 140 changed files with 510 additions and 716 deletions.
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 @@ -20,6 +20,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 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
var id cid.ID
b := smartcontract.NewBuilder()
for _, cnt := range containers {
id.FromBinary(cnt.Value)
id = cid.NewFromMarshalledContainer(cnt.Value)
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 @@ func estimationsFunc(cmd *cobra.Command, _ []string) error {
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[:]))
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 @@ func ReadBearerToken(cmd *cobra.Command, flagname string) (*bearer.Token, error)

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)
}

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 @@ var accountingBalanceCmd = &cobra.Command{

balanceOwner, _ := cmd.Flags().GetString(ownerFlag)
if balanceOwner == "" {
idUser = user.ResolveFromECDSAPublicKey(pk.PublicKey)
idUser = user.NewFromECDSAPublicKey(pk.PublicKey)
} 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 @@ func createEACL(cmd *cobra.Command, _ []string) error {
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)
}
}

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)
}

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 @@ It will be stored in sidechain when inner ring will accepts it.`,
issuer := tok.Issuer()
cnr.SetOwner(issuer)
} else {
cnr.SetOwner(user.ResolveFromECDSAPublicKey(key.PublicKey))
cnr.SetOwner(user.NewFromECDSAPublicKey(key.PublicKey))
}

cnr.SetPlacementPolicy(*placementPolicy)
Expand Down Expand Up @@ -157,7 +157,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
for ; ; t.Reset(waitInterval) {
select {
case <-ctx.Done():
return fmt.Errorf("container creation: %s", common.ErrAwaitTimeout)
return fmt.Errorf("container creation: %w", common.ErrAwaitTimeout)
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 @@ Only owner of the container has a permission to remove container.`,
if tok != nil {
common.PrintVerbose(cmd, "Checking session issuer...")

if !tok.Issuer().Equals(owner) {
if tok.Issuer() != owner {
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)

if !acc.Equals(owner) {
if acc != owner {
return fmt.Errorf("provided account differs with the container owner: expected %s, has %s", owner, acc)
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ Only owner of the container has a permission to remove container.`,
for ; ; t.Reset(waitInterval) {
select {
case <-ctx.Done():
return fmt.Errorf("container deletion: %s", common.ErrAwaitTimeout)
return fmt.Errorf("container deletion: %w", common.ErrAwaitTimeout)
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 @@ func prettyPrintContainer(cmd *cobra.Command, cnr container.Container, jsonEncod
return nil
}

var id cid.ID
cnr.CalculateID(&id)
id := cid.NewFromMarshalledContainer(cnr.Marshal())
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,7 +39,7 @@ var listContainersCmd = &cobra.Command{
}

if flagVarListContainerOwner == "" {
idUser = user.ResolveFromECDSAPublicKey(key.PublicKey)
idUser = user.NewFromECDSAPublicKey(key.PublicKey)
} else {
err := idUser.DecodeString(flagVarListContainerOwner)
if err != nil {
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 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
if tok != nil {
common.PrintVerbose(cmd, "Checking session issuer...")

if !tok.Issuer().Equals(owner) {
if tok.Issuer() != owner {
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)

if !acc.Equals(owner) {
if acc != owner {
return fmt.Errorf("provided account differs with the container owner: expected %s, has %s", owner, acc)
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
for ; ; t.Reset(waitInterval) {
select {
case <-ctx.Done():
return fmt.Errorf("eACL setting: %s", common.ErrAwaitTimeout)
return fmt.Errorf("eACL setting: %w", common.ErrAwaitTimeout)
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 @@ func getSession(cmd *cobra.Command) (*session.Container, error) {

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)
}

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 @@ func synchronizeTree(cmd *cobra.Command, _ []string) error {

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

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

req := &control.SynchronizeTreeRequest{
Body: &control.SynchronizeTreeRequest_Body{
ContainerId: rawCID,
ContainerId: cnr[:],
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 marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) {
}
}

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

id, ok := recv()
if ok {
id := recv()
if !id.IsZero() {
strID = id.String()
} else {
strID = "<empty>"
Expand All @@ -148,11 +148,11 @@ func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) {
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) {
var strID string

id, ok := recv()
if ok {
id := recv()
if !id.IsZero() {
strID = id.String()
} else {
strID = "<empty>"
Expand All @@ -162,8 +162,8 @@ func printContainerID(cmd *cobra.Command, recv func() (cid.ID, bool)) {
}

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)
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 @@ func printSplitHeader(cmd *cobra.Command, obj *object.Object) error {
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)
}

if prev, ok := obj.PreviousID(); ok {
if prev := obj.GetPreviousID(); !prev.IsZero() {
cmd.Printf("Split PreviousID: %s\n", prev)
}

Expand Down
Loading

0 comments on commit 624f636

Please sign in to comment.