Last active
July 10, 2020 09:03
-
-
Save quasilyte/3d12aea1ee9ab7eb74445ff0e447c9c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gorules | |
import "github.com/quasilyte/go-ruleguard/dsl/fluent" | |
func useMathBits(m fluent.Matcher) { | |
m.Match(`$X >> $N | $X << (8 - $N)`, | |
`$X << $N | $X >> (8 - $N)`, | |
`$X >> (8 - $N) | $X << $N`, | |
`$X << (8 - $N) | $X >> $N`, | |
`$X >> $N | $X << (16 - $N)`, | |
`$X << $N | $X >> (16 - $N)`, | |
`$X >> (16 - $N) | $X << $N`, | |
`$X << (16 - $N) | $X >> $N`, | |
`$X >> $N | $X << (32 - $N)`, | |
`$X << $N | $X >> (32 - $N)`, | |
`$X >> (32 - $N) | $X << $N`, | |
`$X << (32 - $N) | $X >> $N`, | |
`$X >> $N | $X << (64 - $N)`, | |
`$X << $N | $X >> (64 - $N)`, | |
`$X >> (64 - $N) | $X << $N`, | |
`$X << (64 - $N) | $X >> $N`). | |
Report(`Try using math/bits instead`) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gorules | |
import "github.com/quasilyte/go-ruleguard/dsl/fluent" | |
func useMathBits(m fluent.Matcher) { | |
// Suggest() is a rewrite template for a match. | |
// If no Report is defined, it's also used to infer the warning text | |
// when autofixing is disabled. | |
m.Match(`$x << $n | $x >> (8 - $n) `,). | |
Suggest(`bits.RotateLeft8($x, $n)`) | |
m.Match(`$x << $n | $x >> (16 - $n) `,). | |
Suggest(`bits.RotateLeft16($x, $n)`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment