-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,11 +188,12 @@ func checkFilterColumnMatchesFilter(colName string, filter datastore.Relationshi | |
| foundCount++ | ||
| } | ||
| } | ||
| if foundCount == 0 { | ||
| switch { | ||
| case foundCount == 0: | ||
|
Comment on lines
+191
to
+192
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some if/elseif/else rewriting to cases |
||
| return columnFilterNoMatch, nil | ||
| } else if foundCount < len(filter.OptionalSubjectsSelectors) { | ||
| case foundCount < len(filter.OptionalSubjectsSelectors): | ||
| return columnFilterForceNoMatch, nil | ||
| } else { | ||
| default: | ||
| return columnFilterMatch, nil | ||
| } | ||
|
|
||
|
|
@@ -207,11 +208,12 @@ func checkFilterColumnMatchesFilter(colName string, filter datastore.Relationshi | |
| foundCount++ | ||
| } | ||
| } | ||
| if foundCount == 0 { | ||
| switch { | ||
| case foundCount == 0: | ||
| return columnFilterNoMatch, nil | ||
| } else if foundCount < len(filter.OptionalSubjectsSelectors) { | ||
| case foundCount < len(filter.OptionalSubjectsSelectors): | ||
| return columnFilterForceNoMatch, nil | ||
| } else { | ||
| default: | ||
| return columnFilterMatch, nil | ||
| } | ||
|
|
||
|
|
@@ -226,11 +228,12 @@ func checkFilterColumnMatchesFilter(colName string, filter datastore.Relationshi | |
| foundCount++ | ||
| } | ||
| } | ||
| if foundCount == 0 { | ||
| switch { | ||
| case foundCount == 0: | ||
| return columnFilterNoMatch, nil | ||
| } else if foundCount < len(filter.OptionalSubjectsSelectors) { | ||
| case foundCount < len(filter.OptionalSubjectsSelectors): | ||
| return columnFilterForceNoMatch, nil | ||
| } else { | ||
| default: | ||
| return columnFilterMatch, nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1399,7 +1399,7 @@ | |
| return dsIndexPrefix + index.chunkID, nil | ||
| } | ||
|
|
||
| return dsIndexPrefix + index.chunkID + ":" + (*index.dbCursor).String(), nil | ||
| return dsIndexPrefix + index.chunkID + ":" + index.dbCursor.RelationshipReference.String(), nil | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except that it doesn't work 🤔
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this was the test failure but it's not 🤔 |
||
| } | ||
|
|
||
| type datastoreIndex struct { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import ( | |
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "log" | ||
| "testing" | ||
| "time" | ||
|
|
||
|
|
@@ -276,7 +275,7 @@ func TestRetryPolicy(t *testing.T) { | |
| datastore.WithRequestHedgingEnabled(false), | ||
| ) | ||
| if err != nil { | ||
| log.Fatalf("unable to start memdb datastore: %s", err) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was complaining here that |
||
| t.Fatalf("unable to start memdb datastore: %s", err) | ||
| } | ||
|
|
||
| var interceptor countingInterceptor | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -406,9 +406,7 @@ func foreachTxType( | |
| } | ||
|
|
||
| func sortedStandardData(resourceType string, order options.SortOrder) []tuple.Relationship { | ||
| asTuples := slicez.Map(testfixtures.StandardRelationships, func(item string) tuple.Relationship { | ||
| return tuple.MustParse(item) | ||
| }) | ||
|
Comment on lines
-409
to
-411
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same unlambda thing here. |
||
| asTuples := slicez.Map(testfixtures.StandardRelationships, tuple.MustParse) | ||
|
|
||
| filteredToType := slicez.Filter(asTuples, func(item tuple.Relationship) bool { | ||
| return item.Resource.ObjectType == resourceType | ||
|
|
@@ -433,9 +431,7 @@ func sortedStandardData(resourceType string, order options.SortOrder) []tuple.Re | |
| } | ||
|
|
||
| func sortedStandardDataBySubject(subjectType string, order options.SortOrder) []tuple.Relationship { | ||
| asTuples := slicez.Map(testfixtures.StandardRelationships, func(item string) tuple.Relationship { | ||
| return tuple.MustParse(item) | ||
| }) | ||
| asTuples := slicez.Map(testfixtures.StandardRelationships, tuple.MustParse) | ||
|
|
||
| filteredToType := slicez.Filter(asTuples, func(item tuple.Relationship) bool { | ||
| if subjectType == "" { | ||
|
|
||
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
unlambdarule - 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