-
Notifications
You must be signed in to change notification settings - Fork 1
Add SA4021 #3
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?
Add SA4021 #3
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 |
|---|---|---|
|
|
@@ -130,15 +130,43 @@ rewrite='for :[1] := range' | |
| match='for true {:[x]}' | ||
| rewrite='for {:[x]}' | ||
|
|
||
| ############################################ | ||
| #https://staticcheck.io/docs/checks#S1009 # | ||
| ############################################ | ||
| [S1009] | ||
| match='if :[[x]] != nil && len(:[[x]]) != 0 {:[body]}' | ||
| rewrite='if len(:[[x]]) != 0 {:[body]}' | ||
| [S1009_01] | ||
| match='if :[[x]] == nil || len(:[[x]]) == 0 {:[body]}' | ||
| rewrite='if len(:[[x]]) == 0 {:[body]}' | ||
|
|
||
| ############################################ | ||
| # https://staticcheck.io/docs/checks#S1010 # | ||
| ############################################ | ||
| # Small chance of FP: if builtin `len` is reassigned. | ||
| [S1010_01] | ||
| [S1010] | ||
| match=':[s.][:len(:[s])]' | ||
| rewrite=':[s.][:]' | ||
|
|
||
| ############################################ | ||
| #https://staticcheck.io/docs/checks#S1011 # | ||
| ############################################ | ||
| [S1011] | ||
| match='for _, :[[e]] := range :[[y]] { :[[x]] = append(:[[x]], :[[e]]) }' | ||
| rewrite=':[[x]] = append(:[[x]], :[[y]]...)' | ||
| [S1011_01] | ||
| match='for :[[i]] := range :[[y]] { :[[x]] = append(:[[x]], :[[y]][i]) }' | ||
| rewrite=':[[x]] = append(:[[x]], :[[y]]...)' | ||
| [S1011_02] | ||
| match='for :[[i]] := range :[[y]] { :[[x]] = append(:[[x]], :[[y]][i]) }' | ||
| rewrite=':[[x]] = append(:[[x]], :[[y]]...)' | ||
| [S1011_03] | ||
| match=''' | ||
| for :[[i]] := range :[[y]] { | ||
| v := :[[y]][:[[i]]] | ||
| :[[x]] = append(:[[x]], :[[v]]) | ||
| }''' | ||
| rewrite=':[[x]] = append(:[[x]], :[[y]]...)' | ||
|
Comment on lines
+151
to
+169
Member
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. This only works if Many projects don't expose type information in a way comby can access it right now, so I don't think this is a good rule to include. Feel free to remove or comment it out and explain that this needs type information / link to the blog post. |
||
|
|
||
| ############################################ | ||
| # https://staticcheck.io/docs/checks#S1012 # | ||
|
|
@@ -338,6 +366,15 @@ rewrite='fmt.Errorf(:[1])' | |
| match='for :[~_], :[r.] := range []rune(:[s.])' | ||
| rewrite='for _, :[r] := range :[s]' | ||
|
|
||
| ############################################ | ||
| # https://staticcheck.io/docs/checks#S1031 # | ||
| ############################################ | ||
| [S1031] | ||
| match='if :[[s]] != nil { for _, :[[x]] := range :[[s]] { :[body] } }' | ||
| rewrite=''' | ||
| for _, :[[x]] := range :[[s]] { | ||
| :[body] | ||
| }''' | ||
|
Comment on lines
+369
to
+377
Member
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. Also needs type info, this is the exact example in the blog post https://comby.dev/blog/2022/08/31/comby-with-types :-) Right now we can't include this kind of rule. |
||
|
|
||
| ############################################ | ||
| # https://staticcheck.io/docs/checks#S1032 # | ||
|
|
@@ -461,3 +498,17 @@ rewrite='fmt.Sprintf(":[1]\n", :[2])' | |
| [S1039] | ||
| match='fmt.Sprintf("%s", ":[s]")' | ||
| rewrite='":[s]"' | ||
|
|
||
| ############################################ | ||
| #https://staticcheck.io/docs/checks#SA4021 # | ||
| ############################################ | ||
| [SA4021] | ||
| match=':[[a]] = append(:[[b]])' | ||
| rewrite=':[[a]] = :[[b]]' | ||
|
|
||
| ############################################ | ||
| #https://staticcheck.io/docs/checks#SA4024 # | ||
| ############################################ | ||
| [SA4024] | ||
| match='if len(:[[a]]) < 0 {:[body]}' | ||
| rewrite='' | ||
|
Comment on lines
+501
to
+514
Member
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. Looks good! |
||
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.
looks good to me!