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
checkers: add sortSlice checker #929
Conversation
} | ||
} | ||
|
||
func (c *sortSliceChecker) paramIdents(e *ast.FuncType) (*ast.Ident, *ast.Ident) { |
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.
?
fields := e.Params.List
if len(fields) == 2 {
return fields.Names[0], fields.Names[1]
}
return nil, 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.
This won't handle the case where both idents are a single field.
i, j int - 1 field with 2 names
i int, j int - 2 fields, each with 1 name
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.
oh! got it, nice.
@@ -10,7 +10,7 @@ require ( | |||
github.com/go-toolsmith/astfmt v1.0.0 | |||
github.com/go-toolsmith/astp v1.0.0 | |||
github.com/go-toolsmith/strparse v1.0.0 | |||
github.com/go-toolsmith/typep v1.0.0 | |||
github.com/go-toolsmith/typep v1.0.2 |
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.
<3
Find suspicious sort slice calls. Sorting `slice` argument with a callback that uses another slice is usually incorrect, as only one slice will be modified by Slice call inplace. Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
24376c9
to
ad7ed59
Compare
PTAL. |
Find suspicious sort slice calls.
Sorting
slice
argument with a callback that usesanother slice is usually incorrect, as only one
slice will be modified by Slice call inplace.
Signed-off-by: Iskander Sharipov quasilyte@gmail.com