Skip to content

Commit

Permalink
checkers: micro optimizes (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
peakle committed Jan 15, 2022
1 parent f0a10a0 commit 319a0d4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions checkers/boolExprSimplify_checker.go
@@ -1,7 +1,6 @@
package checkers

import (
"fmt"
"go/ast"
"go/token"
"strconv"
Expand Down Expand Up @@ -295,7 +294,7 @@ func (c *boolExprSimplifyChecker) foldRanges(cur *astutil.Cursor) bool {
if match(&comb) {
lhs.Op = token.EQL
v := c1 + comb.resDelta
lhs.Y.(*ast.BasicLit).Value = fmt.Sprint(v)
lhs.Y.(*ast.BasicLit).Value = strconv.FormatInt(v, 10)
cur.Replace(lhs)
return true
}
Expand All @@ -317,7 +316,7 @@ func (c *boolExprSimplifyChecker) foldRanges(cur *astutil.Cursor) bool {
if match(&comb) {
lhs.Op = token.NEQ
v := c1 + comb.resDelta
lhs.Y.(*ast.BasicLit).Value = fmt.Sprint(v)
lhs.Y.(*ast.BasicLit).Value = strconv.FormatInt(v, 10)
cur.Replace(lhs)
return true
}
Expand Down
7 changes: 4 additions & 3 deletions checkers/regexpSimplify_checker.go
Expand Up @@ -8,9 +8,10 @@ import (
"strings"
"unicode/utf8"

"github.com/quasilyte/regex/syntax"

"github.com/go-critic/go-critic/checkers/internal/astwalk"
"github.com/go-critic/go-critic/framework/linter"
"github.com/quasilyte/regex/syntax"
)

func init() {
Expand Down Expand Up @@ -497,9 +498,9 @@ func (c *regexpSimplifyChecker) simplifyCharRange(rng syntax.Expr) string {
case 0:
return lo
case 1:
return fmt.Sprintf("%s%s", lo, hi)
return lo + hi
case 2:
return fmt.Sprintf("%s%s%s", lo, string(lo[0]+1), hi)
return lo + string(lo[0]+1) + hi
}
}

Expand Down
3 changes: 2 additions & 1 deletion framework/lintmain/internal/lintdoc/doc.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"reflect"
"text/template"

"github.com/go-critic/go-critic/framework/linter"
Expand Down Expand Up @@ -71,7 +72,7 @@ Checker parameters:
templateData.Checker = info
templateData.ParamTypes = make(map[string]string)
for pname, p := range info.Params {
templateData.ParamTypes[pname] = fmt.Sprintf("%T", p.Value)
templateData.ParamTypes[pname] = reflect.TypeOf(p.Value).String()
}

tmpl := template.Must(template.New("doc").Parse(tmplString))
Expand Down
2 changes: 1 addition & 1 deletion framework/linttest/integration.go
Expand Up @@ -74,7 +74,7 @@ func (cfg *IntegrationTest) runTest(t *testing.T, gocritic, gopath string) {
if err != nil {
t.Errorf("read golden file: %v", err)
}
want = strings.TrimSpace(string(data))
want = string(bytes.TrimSpace(data))
goldenDataCache[goldenFile] = want
}

Expand Down

0 comments on commit 319a0d4

Please sign in to comment.