Skip to content
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

micro optimizes #1194

Merged
merged 2 commits into from Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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