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

all: fix some go-critic linter warnings #23709

Merged
merged 5 commits into from Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion accounts/abi/reflect.go
Expand Up @@ -124,7 +124,7 @@ func setSlice(dst, src reflect.Value) error {
slice := reflect.MakeSlice(dst.Type(), src.Len(), src.Len())
for i := 0; i < src.Len(); i++ {
if src.Index(i).Kind() == reflect.Struct {
if err := set(slice.Index(i), src.Index(i)); err != nil {
if err := setStruct(slice.Index(i), src.Index(i)); err != nil {
return err
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/evm/internal/t8ntool/transition.go
Expand Up @@ -419,15 +419,15 @@ func dispatchOutput(ctx *cli.Context, baseDir string, result *ExecutionResult, a
return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err))
}
os.Stdout.Write(b)
os.Stdout.Write([]byte("\n"))
os.Stdout.WriteString("\n")
}
if len(stdErrObject) > 0 {
b, err := json.MarshalIndent(stdErrObject, "", " ")
if err != nil {
return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err))
}
os.Stderr.Write(b)
os.Stderr.Write([]byte("\n"))
os.Stderr.WriteString("\n")
}
return nil
}
4 changes: 2 additions & 2 deletions cmd/faucet/faucet.go
Expand Up @@ -741,7 +741,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c
return "", "", "", common.Address{}, errors.New("No Ethereum address found to fund")
}
var avatar string
if parts = regexp.MustCompile("src=\"([^\"]+twimg.com/profile_images[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 {
if parts = regexp.MustCompile("src=\"([^\"]+twimg\\.com/profile_images[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 {
fjl marked this conversation as resolved.
Show resolved Hide resolved
avatar = parts[1]
}
return username + "@twitter", username, avatar, address, nil
Expand Down Expand Up @@ -867,7 +867,7 @@ func authFacebook(url string) (string, string, common.Address, error) {
return "", "", common.Address{}, errors.New("No Ethereum address found to fund")
}
var avatar string
if parts = regexp.MustCompile("src=\"([^\"]+fbcdn.net[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 {
if parts = regexp.MustCompile("src=\"([^\"]+fbcdn\\.net[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 {
fjl marked this conversation as resolved.
Show resolved Hide resolved
avatar = parts[1]
}
return username + "@facebook", avatar, address, nil
Expand Down
4 changes: 2 additions & 2 deletions core/bloombits/generator_test.go
Expand Up @@ -70,7 +70,7 @@ func BenchmarkGenerator(b *testing.B) {
if err != nil {
b.Fatalf("failed to create bloombit generator: %v", err)
}
for j, bloom := range input {
for j, bloom := range &input {
if err := gen.AddBloom(uint(j), bloom); err != nil {
b.Fatalf("bloom %d: failed to add: %v", i, err)
}
Expand All @@ -89,7 +89,7 @@ func BenchmarkGenerator(b *testing.B) {
if err != nil {
b.Fatalf("failed to create bloombit generator: %v", err)
}
for j, bloom := range input {
for j, bloom := range &input {
if err := gen.AddBloom(uint(j), bloom); err != nil {
b.Fatalf("bloom %d: failed to add: %v", i, err)
}
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/handler_test.go
Expand Up @@ -466,7 +466,7 @@ func testGetNodeData(t *testing.T, protocol uint) {
if (bw != nil && bh == nil) || (bw == nil && bh != nil) {
t.Errorf("test %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw)
}
if bw != nil && bh != nil && bw.Cmp(bw) != 0 {
if bw != nil && bh != nil && bw.Cmp(bh) != 0 {
fjl marked this conversation as resolved.
Show resolved Hide resolved
t.Errorf("test %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw)
}
}
Expand Down
4 changes: 2 additions & 2 deletions node/api.go
Expand Up @@ -218,7 +218,7 @@ func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, api
}

// StartRPC starts the HTTP RPC API server.
// This method is deprecated. Use StartHTTP instead.
// Deprecated: use StartHTTP instead.
func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
log.Warn("Deprecation warning", "method", "admin.StartRPC", "use-instead", "admin.StartHTTP")
return api.StartHTTP(host, port, cors, apis, vhosts)
Expand All @@ -231,7 +231,7 @@ func (api *privateAdminAPI) StopHTTP() (bool, error) {
}

// StopRPC shuts down the HTTP server.
// This method is deprecated. Use StopHTTP instead.
// Deprecated: use StopHTTP instead.
func (api *privateAdminAPI) StopRPC() (bool, error) {
log.Warn("Deprecation warning", "method", "admin.StopRPC", "use-instead", "admin.StopHTTP")
return api.StopHTTP()
Expand Down
4 changes: 3 additions & 1 deletion signer/core/signed_data.go
Expand Up @@ -29,6 +29,7 @@ import (
"strconv"
"strings"
"unicode"
"unicode/utf8"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -100,7 +101,8 @@ func (t *Type) isReferenceType() bool {
return false
}
// Reference types must have a leading uppercase character
return unicode.IsUpper([]rune(t.Type)[0])
r, _ := utf8.DecodeRuneInString(t.Type)
return unicode.IsUpper(r)
}

type Types map[string][]Type
Expand Down
2 changes: 1 addition & 1 deletion signer/core/validation.go
Expand Up @@ -21,7 +21,7 @@ import (
"regexp"
)

var printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ]+$")
var printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,\\-./:;<=>?@[\\]^_`{|}~ ]+$")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The \\ is already there, later in the string, [\\]

Copy link
Contributor Author

@quasilyte quasilyte Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string is not unescaped, \\ is \, not \\.
So I'm escaping the - to avoid the weird char range; please read the commit message description about it. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, rtfm me :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we unescape this too one level and use the backtick operators as the outer delimiters? Seems like it would make things easier

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible to use backquote with this string because it contains the backquote character.


// ValidatePasswordFormat returns an error if the password is too short, or consists of characters
// outside the range of the printable 7bit ascii set
Expand Down