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

Org-wide linter #2943

wants to merge 18 commits into from

Conversation

End-rey
Copy link
Contributor

@End-rey End-rey commented Sep 19, 2024

Closes #2940.

Error: `Non-wrapping format verb for fmt.Errorf. Use `%w` to format errors`
and `comparing with != || == will fail on wrapped errors. Use errors.Is to
check for a specific error`.

Signed-off-by: Andrey Butusov <[email protected]>
Error: `Error return value is not checked`.

Signed-off-by: Andrey Butusov <[email protected]>
Error: `for loop can be changed to use an integer range (Go 1.22+)`.

Signed-off-by: Andrey Butusov <[email protected]>
Errors: `unnecessary leading newline` and `unnecessary trailing newline`.

Signed-off-by: Andrey Butusov <[email protected]>
Error: `SA4004: the surrounding loop is unconditionally terminated`.

Signed-off-by: Andrey Butusov <[email protected]>
Error in `cmd/neofs-node/config.go`: `Function
`Reload->Init->init->listenEvents` should pass the context
parameter`.

Signed-off-by: Andrey Butusov <[email protected]>
Error: `Comment should end in a period`.

Signed-off-by: Andrey Butusov <[email protected]>
Signed-off-by: Andrey Butusov <[email protected]>
Error: `duplicated-imports`.

Signed-off-by: Andrey Butusov <[email protected]>
Errors: `S1023: redundant `return` statement` and `S1019: should use
make(chan *Move) instead`.

Signed-off-by: Andrey Butusov <[email protected]>
Use:
- `eacl.Target.RawSubjects` instead of `eacl.Target.BinaryKeys`
- `eacl.NewTargetByRole` with `eacl.Target.SetRawSubjects` for targets with
public keys
- `eacl.ConstructTable` instead of `eacl.NewTable`
- `eacl.ConstructRecord` instead of `eacl.NewRecord`
- `object.Object.GetID` instead of `object.Object.ID`
- `object.Object.GetContainerID` instead of `object.Object.ContainerID`
- comparing with == instead of `ID.Equals`
- `cid.NewFromMarshalledContainer(cnr.Marshal())` instead of `cid.ID
.CalculateID`
- `user.NewFromECDSAPublicKey` instead of `user.ResolveFromECDSAPublicKey`
- direct copy instead of `ID.Encode`
- direct assign instead of `ID.SetSHA256`

Signed-off-by: Andrey Butusov <[email protected]>
Error: `struct literal uses unkeyed fields`.

Signed-off-by: Andrey Butusov <[email protected]>
Update to `math/rand/v2` and use `crypto/rand` for `rand.Read`.

Signed-off-by: Andrey Butusov <[email protected]>
Signed-off-by: Andrey Butusov <[email protected]>
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 10.00000% with 36 lines in your changes missing coverage. Please review.

Project coverage is 23.91%. Comparing base (4f22042) to head (7468c36).

Files with missing lines Patch % Lines
pkg/local_object_storage/engine/tree.go 0.00% 8 Missing ⚠️
cmd/neofs-cli/modules/util/acl.go 0.00% 7 Missing ⚠️
...d/neofs-adm/internal/modules/morph/local_client.go 0.00% 5 Missing ⚠️
cmd/neofs-adm/internal/modules/morph/notary.go 0.00% 4 Missing ⚠️
...ct_storage/blobstor/fstree/fstree_write_generic.go 0.00% 4 Missing ⚠️
...ofs-adm/internal/modules/morph/verified_domains.go 0.00% 3 Missing ⚠️
pkg/innerring/internal/blockchain/blockchain.go 0.00% 2 Missing ⚠️
pkg/core/object/replicate.go 0.00% 1 Missing ⚠️
pkg/morph/client/netmap/config.go 0.00% 1 Missing ⚠️
pkg/services/tree/signature.go 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2943      +/-   ##
==========================================
- Coverage   23.91%   23.91%   -0.01%     
==========================================
  Files         776      776              
  Lines       45721    45722       +1     
==========================================
- Hits        10936    10934       -2     
- Misses      33925    33927       +2     
- Partials      860      861       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@End-rey End-rey marked this pull request as draft September 19, 2024 17:10
@@ -60,7 +60,7 @@ func (w *genericWriter) writeData(_ oid.ID, p string, data []byte) error {
for i := range retryCount {
tmpPath := p + "#" + strconv.FormatUint(uint64(i), 10)
err := w.writeAndRename(tmpPath, p, data)
if err != syscall.EEXIST || i == retryCount-1 {
if errors.Is(err, syscall.EEXIST) || i == retryCount-1 {
Copy link
Member

Choose a reason for hiding this comment

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

Bug.

@@ -74,9 +74,9 @@ func TestCounters(t *testing.T) {
dir := t.TempDir()
sh, mm := shardWithMetrics(t, dir)

sh.SetMode(mode.ReadOnly)
_ = sh.SetMode(mode.ReadOnly)
Copy link
Member

Choose a reason for hiding this comment

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

Can be checked with require.NoError()

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?

@@ -60,11 +60,11 @@ func TestDB_Delete(t *testing.T) {

// check if they marked as already removed

ok, err := metaExists(db, object.AddressOf(child))
ok, _ := metaExists(db, object.AddressOf(child))
Copy link
Member

Choose a reason for hiding this comment

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

Wow. It looks like a test bug in fact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, I added err to require.Error and everything all right.

ok, err := metaExists(db, object.AddressOf(child))
require.Error(t, apistatus.ObjectAlreadyRemoved{})
require.False(t, ok)

But there is err == nil and ok is false, i think it is wrong.
ok, err = metaExists(db, object.AddressOf(parent))
require.Error(t, apistatus.ObjectAlreadyRemoved{})
require.False(t, ok)

@@ -179,7 +179,7 @@ func TestDB_Exists(t *testing.T) {
require.False(t, gotObj)
require.ErrorIs(t, err, meta.ErrObjectIsExpired)

gotObj, err = metaExists(db, object.AddressOf(nonExp))
gotObj, _ = metaExists(db, object.AddressOf(nonExp))
Copy link
Member

Choose a reason for hiding this comment

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

This better be checked for nil.

@@ -224,7 +224,7 @@ func testForestTreeDrop(t *testing.T, s Forest) {
require.NoError(t, err)
}
}
list, err := s.TreeList(cid)
list, _ := s.TreeList(cid)
Copy link
Member

Choose a reason for hiding this comment

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

require.NoError(t, err)?

@@ -20,9 +20,9 @@ func TestWriteCacheObjectLoss(t *testing.T) {

objects := make([]*objectSDK.Object, objCount)
for i := range objects {
size := smallSize
size := smallSize / 2
// if i%2 == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Drop commented out code? Why is it here?

@@ -101,6 +101,7 @@ func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool

return true
}

Copy link
Member

Choose a reason for hiding this comment

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

Whitespace change.

@@ -684,7 +685,7 @@ func prepareRandomTree(nodeCount, opCount int) []Move {
Child: uint64(i) + 1,
}
//nolint:staticcheck
Copy link
Member

Choose a reason for hiding this comment

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

Drop these comments then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adapt org-wide linter
2 participants