Add staticcheck #203

Merged
fyrchik merged 1 commit from dstepanov-yadro/frostfs-node:refactoring/staticcheck into master 2023-07-26 21:07:57 +00:00

https://staticcheck.io/ is not the same as golang-cli staticcheck linter.

https://staticcheck.io/ is not the same as golang-cli staticcheck linter.
dstepanov-yadro force-pushed refactoring/staticcheck from 95f67b250f to 7927f48961 2023-04-03 14:08:40 +00:00 Compare
dstepanov-yadro requested review from storage-core-committers 2023-04-03 14:09:09 +00:00
dstepanov-yadro requested review from storage-core-developers 2023-04-03 14:09:09 +00:00
Member

Typo in commit message "[#203] pilarama: Refactor tests" -> [#203] pilorama...

Typo in commit message "[#203] pilarama: Refactor tests" -> `[#203] pilorama...`
acid-ant approved these changes 2023-04-03 14:41:25 +00:00
carpawell requested review from storage-core-committers 2023-04-03 15:11:39 +00:00
carpawell reviewed 2023-04-03 15:13:27 +00:00
carpawell left a comment
Contributor

I do believe it is a good thing but do we have any issue/discussion about that?

Also, we usually end commit messages (body, not header) with a period.

I do believe it is a good thing but do we have any issue/discussion about that? Also, we usually end commit messages (body, not header) with a period.
@ -286,6 +286,7 @@ func parseNNSResolveResult(res stackitem.Item) (util.Uint160, error) {
func nnsIsAvailable(c Client, nnsHash util.Uint160, name string) (bool, error) {
switch ct := c.(type) {
case *rpcclient.Client:
//lint:ignore SA1019 https://git.frostfs.info/TrueCloudLab/frostfs-node/issues/202
Contributor

can that be fixed in one place like it was already done?

can that be fixed in one place like it was already [done](https://git.frostfs.info/TrueCloudLab/frostfs-node/src/commit/a69c6d1ec9e43f49e6e588d8770ea05ccbcef050/.golangci.yml#L27-L28)?
Author
Member

It is possible. But I think that we should not disable this check for the entire project.

It is possible. But I think that we should not disable this check for the entire project.
@ -79,3 +79,2 @@
commonCmd.ExitOnErr(cmd, "",
fmt.Errorf("Container wasn't removed because LOCK objects were found.\n"+
"Use --%s flag to remove anyway.", commonflags.ForceFlag))
fmt.Errorf("container wasn't removed because LOCK objects were found.\n"+
Contributor

that is a CLI util output, is that change really necessary?

that is a CLI util output, is that change really necessary?
Author
Member

Anyway there is a check for the format of the error text.

Fixed error text format to match other errors.

Anyway there is a check for the format of the error text. Fixed error text format to match other errors.
Owner

I believe cmd.PrintErrLn called inside ExitOnErr should print Error: prefix.

I believe `cmd.PrintErrLn` called inside `ExitOnErr` should print `Error: ` prefix.
Author
Member

There is no prefix

There is no prefix
Author
Member

I do believe it is a good thing but do we have any issue/discussion about that?

This is my initiative. We can discuss it here.

> I do believe it is a good thing but do we have any issue/discussion about that? This is my initiative. We can discuss it here.
fyrchik reviewed 2023-04-03 16:22:18 +00:00
Makefile Outdated
@ -134,1 +134,4 @@
# Run staticcheck
staticcheck:
@go install honnef.co/go/tools/cmd/staticcheck@latest
Owner

Can I still run this target without network connection?

Can I still run this target without network connection?
Author
Member

No. Fixed.

No. Fixed.
fyrchik marked this conversation as resolved
Owner
  • I'd suggest avoiding local hooks that may be used in other repos in favor of creating our own reusable hook collection in a separate repo
  • Maybe it would be better to transform all lint/check related make targets into pre-commit hooks and make a make target to run pre-commit run -a -hook-stage manual for those who don't like to have pre-commit enabled in local repo clone
- I'd suggest avoiding local hooks that may be used in other repos in favor of creating our own reusable hook collection in a separate repo - Maybe it would be better to transform all lint/check related make targets into pre-commit hooks and make a make target to run `pre-commit run -a -hook-stage manual` for those who don't like to have pre-commit enabled in local repo clone
aarifullin reviewed 2023-04-03 22:17:53 +00:00
@ -86,3 +86,3 @@
info1 := b1.Shards[i].GetBlobstor()
info2 := b2.Shards[i].GetBlobstor()
return compareBlobstorInfo(info1, info2)
if !compareBlobstorInfo(info1, info2) {
Member

Interesting...

Interesting...
Author
Member

False positive?

False positive?
Owner

I think it is interesting that staticcheck can find this.
The rule is probably "see if we return on every branch in the loop body".

Shouldn't catch this, though:

var x = true
if x {
    return compareBlobstorInfo(info1, info2)
}
I think it is interesting that staticcheck can find this. The rule is probably "see if we return on every branch in the loop body". Shouldn't catch this, though: ``` var x = true if x { return compareBlobstorInfo(info1, info2) } ```
fyrchik marked this conversation as resolved
aarifullin reviewed 2023-04-03 22:22:52 +00:00
@ -60,3 +59,3 @@
// Returns nil, nil if the tombstone has been removed
// or marked for removal.
func (s Source) Tombstone(ctx context.Context, a oid.Address, _ uint64) (*object.Object, error) {
func (s Source) Tombstone(ctx context.Context, a oid.Address, _ uint64) (*objectSDK.Object, error) {
Member

Was that linter suggestion/warning? This PR has truncated *SDK suffix in many places but here it's been added. Maybe we should keep object and just remove objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"?

Was that linter suggestion/warning? This PR has truncated `*SDK` suffix in many places but here it's been added. Maybe we should keep `object` and just remove `objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"`?
Author
Member

Fixed.

Fixed.
Owner

We have object package in core and api. To improve readability our unwritten rule is to use objectSDK and objectAPI explicitly.

We have `object` package in core and api. To improve readability our unwritten rule is to use `objectSDK` and `objectAPI` explicitly.
Author
Member

Now we know this rule. Fixed to objectSDK.

Now we know this rule. Fixed to objectSDK.
Owner

We wanted to write a linter for this at one point.

We wanted to write a linter for this at one point.
fyrchik marked this conversation as resolved
dstepanov-yadro force-pushed refactoring/staticcheck from 7927f48961 to 3492eccc2a 2023-04-04 06:37:22 +00:00 Compare
Author
Member

Typo in commit message "[#203] pilarama: Refactor tests" -> [#203] pilorama...

fixed

> Typo in commit message "[#203] pilarama: Refactor tests" -> `[#203] pilorama...` fixed
dstepanov-yadro force-pushed refactoring/staticcheck from 3492eccc2a to 54d015c94b 2023-04-04 06:46:18 +00:00 Compare
dstepanov-yadro force-pushed refactoring/staticcheck from 54d015c94b to 7fd95ce34b 2023-04-04 06:52:04 +00:00 Compare
aarifullin approved these changes 2023-04-04 07:04:18 +00:00
aarifullin left a comment
Member

LGTM

LGTM
dstepanov-yadro force-pushed refactoring/staticcheck from 7fd95ce34b to 1e7e8d110f 2023-04-04 07:37:38 +00:00 Compare
Author
Member
  • I'd suggest avoiding local hooks that may be used in other repos in favor of creating our own reusable hook collection in a separate repo

We will discuss it. Currently replaced local hook with external.

  • Maybe it would be better to transform all lint/check related make targets into pre-commit hooks and make a make target to run pre-commit run -a -hook-stage manual for those who don't like to have pre-commit enabled in local repo clone

Done.

> - I'd suggest avoiding local hooks that may be used in other repos in favor of creating our own reusable hook collection in a separate repo We will discuss it. Currently replaced local hook with external. > - Maybe it would be better to transform all lint/check related make targets into pre-commit hooks and make a make target to run `pre-commit run -a -hook-stage manual` for those who don't like to have pre-commit enabled in local repo clone Done.
Author
Member

Typo in commit message "[#203] pilarama: Refactor tests" -> [#203] pilorama...

Fixed

> Typo in commit message "[#203] pilarama: Refactor tests" -> `[#203] pilorama...` Fixed
Author
Member

Also, we usually end commit messages (body, not header) with a period.

Fixed.

> Also, we usually end commit messages (body, not header) with a period. Fixed.
dstepanov-yadro force-pushed refactoring/staticcheck from 1e7e8d110f to 13e6c0040a 2023-04-04 11:49:04 +00:00 Compare
dstepanov-yadro force-pushed refactoring/staticcheck from 13e6c0040a to 2f4207b7e8 2023-04-04 13:35:41 +00:00 Compare
aarifullin approved these changes 2023-04-05 13:40:06 +00:00
dstepanov-yadro force-pushed refactoring/staticcheck from 2f4207b7e8 to 9027695371 2023-04-06 13:34:00 +00:00 Compare
fyrchik approved these changes 2023-04-06 14:26:03 +00:00
fyrchik merged commit 9027695371 into master 2023-04-06 14:26:16 +00:00
fyrchik referenced this pull request from a commit 2023-04-06 14:26:17 +00:00
fyrchik referenced this pull request from a commit 2023-04-06 14:26:17 +00:00
fyrchik referenced this pull request from a commit 2023-04-06 14:26:17 +00:00
fyrchik referenced this pull request from a commit 2023-04-06 14:26:17 +00:00
fyrchik referenced this pull request from a commit 2023-04-06 14:26:17 +00:00
fyrchik referenced this pull request from a commit 2023-04-06 14:26:17 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#203
No description provided.