mirror of
https://github.com/mgechev/revive.git
synced 2025-11-29 22:28:23 +02:00
* Refactoring on atomic rule: -Main modification: move func gofmt to utils.go * Refactoring on constant-logical-expr rule Simplifies equality check of subexpressions by using gofmt function
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/printer"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"regexp"
|
||||
@@ -179,3 +181,11 @@ func isExprABooleanLit(n ast.Node) (lexeme string, ok bool) {
|
||||
|
||||
return oper.Name, (oper.Name == trueName || oper.Name == falseName)
|
||||
}
|
||||
|
||||
// gofmt returns a string representation of the expression.
|
||||
func gofmt(x ast.Expr) string {
|
||||
buf := bytes.Buffer{}
|
||||
fs := token.NewFileSet()
|
||||
printer.Fprint(&buf, fs, x)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user