-
Notifications
You must be signed in to change notification settings - Fork 348
chore: enable gocritic #2682
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
base: main
Are you sure you want to change the base?
chore: enable gocritic #2682
Conversation
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (44.66%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.
Additional details and impacted files@@ Coverage Diff @@
## main #2682 +/- ##
===========================================
- Coverage 79.43% 44.66% -34.77%
===========================================
Files 456 414 -42
Lines 47320 43897 -3423
===========================================
- Hits 37586 19603 -17983
- Misses 6971 22448 +15477
+ Partials 2763 1846 -917 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
| intFromString := func(s string) (int, error) { | ||
| return strconv.Atoi(s) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the unlambda rule - basically don't wrap a function in a lambda if the lambda is exactly the same as the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like lambdas in general because they make reading stacktraces a pain in the behind
| switch { | ||
| case foundCount == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some if/elseif/else rewriting to cases
internal/graph/lookupresources3.go
Outdated
| cursor := (*index.dbCursor) | ||
| return dsIndexPrefix + index.chunkID + ":" + cursor.String(), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gocritic was complaining that you could get rid of the deref here, except that you can't because the compiler doesn't correctly recognize the interface. Separating the assignment fixes things.
| newArgs := append(args, strValue) | ||
| newArgs := make([]any, 0, len(args)+len(strValue)) | ||
| newArgs = append(newArgs, args) | ||
| newArgs = append(newArgs, strValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are functionally equivalent, but gocritic doesn't like it when you use append and assign to a new slice, so this makes it more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is the problem. I'm not sure why it's semantically different.
| datastore.WithRequestHedgingEnabled(false), | ||
| ) | ||
| if err != nil { | ||
| log.Fatalf("unable to start memdb datastore: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was complaining here that log.Fatalf prevents defer blocks from running. t.Fatalf should be equivalent and also work around that.
| asTuples := slicez.Map(testfixtures.StandardRelationships, func(item string) tuple.Relationship { | ||
| return tuple.MustParse(item) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same unlambda thing here.
80b1618 to
6f258a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
| } | ||
|
|
||
| return dsIndexPrefix + index.chunkID + ":" + (*index.dbCursor).String(), nil | ||
| return dsIndexPrefix + index.chunkID + ":" + index.dbCursor.RelationshipReference.String(), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure how this deref worked previously - this both makes things a little clearer and also satisfies gocritic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except that it doesn't work 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this explain the broken tests or are you talking about something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this was the test failure but it's not 🤔
|
|
||
| checkedUpdate = true | ||
| } else { | ||
| // we wait for a checkpoint right after the update. Checkpoints could happen at any time off band. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment should be moved too
6f258a0 to
5db047d
Compare
Description
Getting close to done with linting things! This enables
gocriticacross the repo.Changes
Will annotate.
Testing
Review. See that tests pass.