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

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
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 @@ -12,6 +12,7 @@ Changelog for NeoFS Node

### Changed
- `ObjectService`'s `Put` RPC handler caches up to 10K lists of per-object sorted container nodes (#2901)
- Use org-wide linter (#2943)

### Removed

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
4 changes: 2 additions & 2 deletions cmd/neofs-adm/internal/modules/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func TestGenerateConfigExample(t *testing.T) {
require.Equal(t, 100000000, v.GetInt("network.fee.withdraw"))

var i int
for i = 0; i < n; i++ {
for i = range n {
key := "credentials." + glagolitsa.LetterByIndex(i)
require.Equal(t, "password", v.GetString(key))
}

key := "credentials." + glagolitsa.LetterByIndex(i)
key := "credentials." + glagolitsa.LetterByIndex(i+1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use n here?

require.Equal(t, "", v.GetString(key))
}
4 changes: 2 additions & 2 deletions cmd/neofs-adm/internal/modules/morph/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func TestGenerateAlphabet(t *testing.T) {
buf.Reset()
v.Set(alphabetWalletsFlag, walletDir)
require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, strconv.FormatUint(size, 10)))
for i := uint64(0); i < size; i++ {
for i := range uint64(size) {
buf.WriteString(strconv.FormatUint(i, 10) + "\r")
}

require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil))

for i := uint64(0); i < size; i++ {
for i := range uint64(size) {
p := filepath.Join(walletDir, glagolitsa.LetterByIndex(int(i))+".json")
w, err := wallet.NewWalletFromFile(p)
require.NoError(t, err, "wallet doesn't exist")
Expand Down
10 changes: 5 additions & 5 deletions cmd/neofs-adm/internal/modules/morph/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@
continue
}

fee, sizeDelta := fee.Calculate(ef, verificationScript)
netFee += fee
newFee, sizeDelta := fee.Calculate(ef, verificationScript)
netFee += newFee

Check warning on line 216 in cmd/neofs-adm/internal/modules/morph/local_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/local_client.go#L215-L216

Added lines #L215 - L216 were not covered by tests
size += sizeDelta
}

fee := l.bc.FeePerByte()
netFee += int64(size) * fee
feePerByte := l.bc.FeePerByte()
netFee += int64(size) * feePerByte

Check warning on line 221 in cmd/neofs-adm/internal/modules/morph/local_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/local_client.go#L220-L221

Added lines #L220 - L221 were not covered by tests

return netFee, nil
}
Expand Down Expand Up @@ -319,7 +319,7 @@

script, err := b.Script()
if err != nil {
return nil, fmt.Errorf("BUG: invalid parameters for '%s': %v", method, err)
return nil, fmt.Errorf("BUG: invalid parameters for '%s': %w", method, err)

Check warning on line 322 in cmd/neofs-adm/internal/modules/morph/local_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/local_client.go#L322

Added line #L322 was not covered by tests
}

return c.InvokeScript(script, signers)
Expand Down
8 changes: 4 additions & 4 deletions cmd/neofs-adm/internal/modules/morph/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

w, err := wallet.NewWalletFromFile(p)
if err != nil {
return fmt.Errorf("can't open wallet: %v", err)
return fmt.Errorf("can't open wallet: %w", err)

Check warning on line 34 in cmd/neofs-adm/internal/modules/morph/notary.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/notary.go#L34

Added line #L34 was not covered by tests
}

accHash := w.GetChangeAddress()
Expand All @@ -50,12 +50,12 @@
prompt := fmt.Sprintf("Enter password for %s >", address.Uint160ToString(accHash))
pass, err := input.ReadPassword(prompt)
if err != nil {
return fmt.Errorf("can't get password: %v", err)
return fmt.Errorf("can't get password: %w", err)

Check warning on line 53 in cmd/neofs-adm/internal/modules/morph/notary.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/notary.go#L53

Added line #L53 was not covered by tests
}

err = acc.Decrypt(pass, keys.NEP2ScryptParams())
if err != nil {
return fmt.Errorf("can't unlock account: %v", err)
return fmt.Errorf("can't unlock account: %w", err)

Check warning on line 58 in cmd/neofs-adm/internal/modules/morph/notary.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/notary.go#L58

Added line #L58 was not covered by tests
}

gasStr, err := cmd.Flags().GetString(refillGasAmountFlag)
Expand Down Expand Up @@ -86,7 +86,7 @@

height, err := c.GetBlockCount()
if err != nil {
return fmt.Errorf("can't get current height: %v", err)
return fmt.Errorf("can't get current height: %w", err)

Check warning on line 89 in cmd/neofs-adm/internal/modules/morph/notary.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/notary.go#L89

Added line #L89 was not covered by tests
}

act, err := actor.New(c, []actor.SignerAccount{{
Expand Down
6 changes: 3 additions & 3 deletions cmd/neofs-adm/internal/modules/morph/verified_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

w, err := wallet.NewWalletFromFile(viper.GetString(walletFlag))
if err != nil {
return fmt.Errorf("decode Neo wallet from file: %v", err)
return fmt.Errorf("decode Neo wallet from file: %w", err)

Check warning on line 123 in cmd/neofs-adm/internal/modules/morph/verified_domains.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/verified_domains.go#L123

Added line #L123 was not covered by tests
}

var accAddr util.Uint160
Expand All @@ -141,12 +141,12 @@
prompt := fmt.Sprintf("Enter password for %s >", address.Uint160ToString(accAddr))
pass, err := input.ReadPassword(prompt)
if err != nil {
return fmt.Errorf("failed to read account password: %v", err)
return fmt.Errorf("failed to read account password: %w", err)

Check warning on line 144 in cmd/neofs-adm/internal/modules/morph/verified_domains.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/verified_domains.go#L144

Added line #L144 was not covered by tests
}

err = acc.Decrypt(pass, keys.NEP2ScryptParams())
if err != nil {
return fmt.Errorf("failed to unlock the account with password: %v", err)
return fmt.Errorf("failed to unlock the account with password: %w", err)

Check warning on line 149 in cmd/neofs-adm/internal/modules/morph/verified_domains.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/verified_domains.go#L149

Added line #L149 was not covered by tests
}

n3Client, err := getN3Client(vpr)
Expand Down
10 changes: 5 additions & 5 deletions cmd/neofs-cli/modules/acl/extended/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestParseTable(t *testing.T) {
tests := [...]struct {
name string // test name
rule string // input extended ACL rule
jsonRecord string // produced record after successfull parsing
jsonRecord string // produced record after successful parsing
}{
{
name: "valid rule with multiple filters",
Expand Down Expand Up @@ -68,21 +68,21 @@ func TestParseTable(t *testing.T) {
},
}

eaclTable := eacl.NewTable()
eaclTable := eacl.ConstructTable(nil)

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()
expectedRecord := eacl.ConstructRecord(eacl.ActionUnspecified, eacl.OperationUnspecified, nil, eacl.Filter{})
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
14 changes: 8 additions & 6 deletions cmd/neofs-cli/modules/util/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
func eaclTargetsToString(ts []eacl.Target) string {
b := bytes.NewBuffer(nil)
for _, t := range ts {
keysExists := len(t.BinaryKeys()) > 0
keysExists := len(t.RawSubjects()) > 0

Check warning on line 86 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L86

Added line #L86 was not covered by tests
switch t.Role() {
case eacl.RoleUser:
b.WriteString("User")
Expand All @@ -107,7 +107,7 @@
}
}

for i, pub := range t.BinaryKeys() {
for i, pub := range t.RawSubjects() {

Check warning on line 110 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L110

Added line #L110 was not covered by tests
if i != 0 {
b.WriteString(" ")
}
Expand Down Expand Up @@ -183,7 +183,7 @@
for _, ruleStr := range rules {
err := ParseEACLRule(table, ruleStr)
if err != nil {
return fmt.Errorf("can't create extended acl record from rule '%s': %v", ruleStr, err)
return fmt.Errorf("can't create extended acl record from rule '%s': %w", ruleStr, err)

Check warning on line 186 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L186

Added line #L186 was not covered by tests
}
}
return nil
Expand All @@ -199,7 +199,7 @@
func ParseEACLRule(table *eacl.Table, rule string) error {
r, err := shlex.Split(rule)
if err != nil {
return fmt.Errorf("can't parse rule '%s': %v", rule, err)
return fmt.Errorf("can't parse rule '%s': %w", rule, err)

Check warning on line 202 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L202

Added line #L202 was not covered by tests
}
return parseEACLTable(table, r)
}
Expand Down Expand Up @@ -286,8 +286,10 @@
continue
}

var target eacl.Target
eacl.SetTargetECDSAKeys(&target, pubs...)
target := eacl.NewTargetByRole(eacl.RoleUnspecified)
for _, pub := range pubs {
target.SetRawSubjects(append(target.RawSubjects(), (*keys.PublicKey)(pub).Bytes()))

Check warning on line 291 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L289-L291

Added lines #L289 - L291 were not covered by tests
}
targets = append(targets, target)
case "address": // targets
var (
Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ func (c *cfg) configWatcher(ctx context.Context) {
rcfg.AddShard(optsWithID.configID, optsWithID.shOpts)
}

// nolint:contextcheck
err = c.cfgObject.cfgLocalStorage.localStorage.Reload(rcfg)
if err != nil {
c.log.Error("storage engine configuration update", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/object/replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
// all the errors in the stackitem relate only cases when it is
// impossible to use serialized values (too many values, unsupported
// types, etc.), unexpected errors at all
panic(fmt.Errorf("unexpected stackitem map serialization failure: %v", err))
panic(fmt.Errorf("unexpected stackitem map serialization failure: %w", err))

Check warning on line 57 in pkg/core/object/replicate.go

View check run for this annotation

Codecov / codecov/patch

pkg/core/object/replicate.go#L57

Added line #L57 was not covered by tests
}

return result
Expand Down
4 changes: 2 additions & 2 deletions pkg/innerring/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func TestIsAutoDeploymentMode(t *testing.T) {
err = os.Setenv(envKey, "not a boolean")
require.NoError(t, err)

b, err = isAutoDeploymentMode(v)
_, err = isAutoDeploymentMode(v)
require.Error(t, err)

err = os.Setenv(envKey, "false")
Expand Down Expand Up @@ -571,7 +571,7 @@ fschain_autodeploy: true

v.Set("fschain_autodeploy", "not a boolean")

b, err = isAutoDeploymentMode(v)
_, err = isAutoDeploymentMode(v)
require.Error(t, err)

v.Set("fschain_autodeploy", "false")
Expand Down
4 changes: 2 additions & 2 deletions pkg/innerring/internal/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
if err != nil {
closeErr := bcStorage.Close()
if closeErr != nil {
err = fmt.Errorf("%w; also failed to close blockchain storage: %v", err, closeErr)
err = fmt.Errorf("%w; also failed to close blockchain storage: %w", err, closeErr)

Check warning on line 424 in pkg/innerring/internal/blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/internal/blockchain/blockchain.go#L424

Added line #L424 was not covered by tests
}
}
}()
Expand Down Expand Up @@ -518,7 +518,7 @@
if err != nil {
closeErr := x.storage.Close()
if closeErr != nil {
err = fmt.Errorf("%w; also failed to close blockchain storage: %v", err, closeErr)
err = fmt.Errorf("%w; also failed to close blockchain storage: %w", err, closeErr)

Check warning on line 521 in pkg/innerring/internal/blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/internal/blockchain/blockchain.go#L521

Added line #L521 was not covered by tests
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion pkg/innerring/nns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (x *testInvoker) TraverseIterator(sessionID uuid.UUID, iterator *result.Ite

func TestNeoFSNNS_CheckDomainRecord(t *testing.T) {
var contractAddr util.Uint160
rand.Read(contractAddr[:])
_, _ = rand.Read(contractAddr[:])
const domain = "l2.l1.tld"
searchedRecord := "abcdef"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ func TestValidator_Verify(t *testing.T) { // test record with valid but random v

require.NoError(t, validator.Verify(n))
})

t.Run("invalid SN expansion", func(t *testing.T) {

t.Run("invalid Country", func(t *testing.T) {
n := nodeInfoWithSomeAttrs()
addLocodeAttr(&n, [2]string{"RU", "SPB"})
Expand Down
Loading
Loading