Add lint checks: gofmt, goimports, golint

- gofmt - Gofmt checks whether code was gofmt-ed. By default this tool runs
  with -s option to check for code simplification
- goimports - Goimports does everything that gofmt does. Additionally it checks
  unused imports
- golint - Golint differs from gofmt. Gofmt reformats Go source code, whereas
  golint prints out style mistakes
    - checks the uncommented exported functions & types

Update the code to fix the lint checks.
This commit is contained in:
arnaucube
2020-08-31 12:26:35 +02:00
parent 3bd91ec736
commit cbbcb65c8c
21 changed files with 98 additions and 51 deletions

View File

@@ -13,10 +13,14 @@ import (
var eof = rune(0)
var errof = fmt.Errorf("eof in parseline")
var ecomment = fmt.Errorf("comment in parseline")
var enewbatch = fmt.Errorf("newbatch")
var errComment = fmt.Errorf("comment in parseline")
var errNewBatch = fmt.Errorf("newbatch")
// TypeNewBatch is used for testing purposes only, and represents the
// common.TxType of a new batch
var TypeNewBatch common.TxType = "TxTypeNewBatch"
//nolint
const (
ILLEGAL token = iota
WS
@@ -25,6 +29,7 @@ const (
IDENT // val
)
// Instruction is the data structure that represents one line of code
type Instruction struct {
Literal string
From string
@@ -35,6 +40,7 @@ type Instruction struct {
Type common.TxType // D: Deposit, T: Transfer, E: ForceExit
}
// Instructions contains the full Set of Instructions representing a full code
type Instructions struct {
Instructions []*Instruction
Accounts []string
@@ -64,6 +70,7 @@ func (i Instruction) String() string {
return buf.String()
}
// Raw returns a string with the raw representation of the Instruction
func (i Instruction) Raw() string {
buf := bytes.NewBufferString("")
fmt.Fprintf(buf, "%s", i.From)
@@ -104,8 +111,8 @@ func isDigit(ch rune) bool {
return (ch >= '0' && ch <= '9')
}
// NewScanner creates a new scanner with the given io.Reader
func NewScanner(r io.Reader) *scanner {
// newScanner creates a new scanner with the given io.Reader
func newScanner(r io.Reader) *scanner {
return &scanner{r: bufio.NewReader(r)}
}
@@ -196,7 +203,7 @@ type Parser struct {
// NewParser creates a new parser from a io.Reader
func NewParser(r io.Reader) *Parser {
return &Parser{s: NewScanner(r)}
return &Parser{s: newScanner(r)}
}
func (p *Parser) scan() (tok token, lit string) {
@@ -239,10 +246,10 @@ func (p *Parser) parseLine() (*Instruction, error) {
c.Literal += lit
if lit == "/" {
_, _ = p.s.r.ReadString('\n')
return nil, ecomment
return nil, errComment
} else if lit == ">" {
_, _ = p.s.r.ReadString('\n')
return nil, enewbatch
return nil, errNewBatch
}
c.From = lit
@@ -342,11 +349,11 @@ func (p *Parser) Parse() (Instructions, error) {
if err == errof {
break
}
if err == ecomment {
if err == errComment {
i++
continue
}
if err == enewbatch {
if err == errNewBatch {
i++
inst := &Instruction{Type: TypeNewBatch}
instructions.Instructions = append(instructions.Instructions, inst)

View File

@@ -15,7 +15,7 @@ package test
// > and here the comment
// move one batch forward
// Set0 has 3 batches, 29 different accounts, with:
// SetTest0 has 3 batches, 29 different accounts, with:
// - 3 TokenIDs
// - 29+5+10 L1 txs (deposits & exits)
// - 21+53+7 L2 transactions

View File

@@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/require"
)
// Account contains the data related to a testing account
type Account struct {
BJJ *babyjub.PrivateKey
Addr ethCommon.Address
@@ -151,6 +152,8 @@ func GenerateTestTxs(t *testing.T, instructions Instructions) ([][]*common.L1Tx,
return l1Txs, coordinatorL1Txs, poolL2Txs
}
// GenerateTestTxsFromSet reurns the L1 & L2 transactions for a given Set of
// Instructions code
func GenerateTestTxsFromSet(t *testing.T, set string) ([][]*common.L1Tx, [][]*common.L1Tx, [][]*common.PoolL2Tx) {
parser := NewParser(strings.NewReader(set))
instructions, err := parser.Parse()