Skip to content

Commit

Permalink
A few code cleanups as suggested by staticcheck
Browse files Browse the repository at this point in the history
This commits adds in a few suggestions that I got from staticcheck. I also cleaned up a bit further in some cases.

/home/jacob/Downloads/gval/evaluable.go
  (300, 25)  SA1012  do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use
  (332, 25)  SA1012  do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use

/home/jacob/Downloads/gval/language.go
  (258, 2)  SA6003  should range over string, not []rune(string)

/home/jacob/Downloads/gval/operator.go
  (107, 2)  S1023  redundant return statement

/home/jacob/Downloads/gval/parse.go
  (123, 3)  S1005  unnecessary assignment to the blank identifier

/home/jacob/Downloads/gval/parser.go
  (22, 46)  S1023  redundant return statement
  (84, 2)   S1023  redundant return statement

/home/jacob/Downloads/gval/random_test.go
  (16, 2)   U1000  var empty3 is unused
  (105, 2)  U1000  var panics is unused
  • Loading branch information
Jacalz committed Apr 24, 2021
1 parent 2271a5a commit 7bc0058
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 15 deletions.
4 changes: 2 additions & 2 deletions evaluable.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func regEx(a, b Evaluable) (Evaluable, error) {
return matched, err
}, nil
}
s, err := b.EvalString(nil, nil)
s, err := b.EvalString(context.TODO(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func notRegEx(a, b Evaluable) (Evaluable, error) {
return !matched, err
}, nil
}
s, err := b.EvalString(nil, nil)
s, err := b.EvalString(context.TODO(), nil)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions language.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ func (l *Language) makePrefixKey(key string) interface{} {
}

func (l *Language) makeInfixKey(key string) string {
runes := []rune(key)
for _, r := range runes {
for _, r := range key {
l.operatorSymbols[r] = struct{}{}
}
return key
Expand Down
1 change: 0 additions & 1 deletion operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (op *infix) initiate(name string) {
return f(a, b)
}, nil
}
return
}

type opFunc func(a, b interface{}) (interface{}, error)
Expand Down
3 changes: 1 addition & 2 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ func (p *Parser) parseOperator(c context.Context, stack *stageStack, eval Evalua
p.Camouflage("operator")
return stage{Evaluable: eval}, nil
}
operator, _ := p.operators[op]
switch operator := operator.(type) {
switch operator := p.operators[op].(type) {
case *infix:
return stage{
Evaluable: eval,
Expand Down
3 changes: 1 addition & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Parser struct {
func newParser(expression string, l Language) *Parser {
sc := scanner.Scanner{}
sc.Init(strings.NewReader(expression))
sc.Error = func(*scanner.Scanner, string) { return }
sc.Error = func(*scanner.Scanner, string) {}
sc.Filename = expression + "\t"
p := &Parser{scanner: sc, Language: l}
p.resetScannerProperties()
Expand Down Expand Up @@ -81,7 +81,6 @@ func (p *Parser) Camouflage(unit string, expected ...rune) {
panic(fmt.Errorf("can only Camouflage() after Scan(): %v", p.camouflage))
}
p.camouflage = p.Expected(unit, expected...)
return
}

// Peek returns the next Unicode character in the source without advancing
Expand Down
7 changes: 1 addition & 6 deletions random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var (
hello = "hello"
empty struct{}
empty2 *string
empty3 *int

values = []interface{}{
-1,
Expand Down Expand Up @@ -101,13 +100,9 @@ var (
"\n",
"\000",
}

panics = 0
)

const (
SEED = 1487873697990155515
)
const SEED = 1487873697990155515

func BenchmarkRandom(bench *testing.B) {
rand.Seed(SEED)
Expand Down

0 comments on commit 7bc0058

Please sign in to comment.