Conversation
|
@rvantonder for review, thanks! |
rvantonder
left a comment
There was a problem hiding this comment.
hey, thanks! two of the rules will have false positives without type info, so maybe just comment those out with a note and re-request review
| ############################################ | ||
| #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]]...)' |
There was a problem hiding this comment.
This only works if :[[y]] is a slice type, and not a map. If it is a map, this will produce a false positive / uncompilable code. You can read more on this kind of thing in the blog here: https://comby.dev/blog/2022/08/31/comby-with-types.
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#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#S1031 # | ||
| ############################################ | ||
| [S1031] | ||
| match='if :[[s]] != nil { for _, :[[x]] := range :[[s]] { :[body] } }' | ||
| rewrite=''' | ||
| for _, :[[x]] := range :[[s]] { | ||
| :[body] | ||
| }''' |
There was a problem hiding this comment.
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#SA4021 # | ||
| ############################################ | ||
| [SA4021] | ||
| match=':[[a]] = append(:[[b]])' | ||
| rewrite=':[[a]] = :[[b]]' | ||
|
|
||
| ############################################ | ||
| #https://staticcheck.io/docs/checks#SA4024 # | ||
| ############################################ | ||
| [SA4024] | ||
| match='if len(:[[a]]) < 0 {:[body]}' | ||
| rewrite='' |
No description provided.