chore: Format and fix lints (#9336)

* make format

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix linting directives

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* make mockery

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Appease CI linter

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Appease CI linter

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
Thane Thomson
2022-08-30 12:28:46 -04:00
committed by GitHub
parent 7b40167f58
commit cceea4de22
87 changed files with 402 additions and 384 deletions

View File

@@ -1,4 +1,3 @@
// nolint: gosec
package app
import (
@@ -29,7 +28,7 @@ type SnapshotStore struct {
// NewSnapshotStore creates a new snapshot store.
func NewSnapshotStore(dir string) (*SnapshotStore, error) {
store := &SnapshotStore{dir: dir}
if err := os.MkdirAll(dir, 0755); err != nil {
if err := os.MkdirAll(dir, 0o755); err != nil {
return nil, err
}
if err := store.loadMetadata(); err != nil {
@@ -71,7 +70,7 @@ func (s *SnapshotStore) saveMetadata() error {
// save the file to a new file and move it to make saving atomic.
newFile := filepath.Join(s.dir, "metadata.json.new")
file := filepath.Join(s.dir, "metadata.json")
err = os.WriteFile(newFile, bz, 0644) // nolint: gosec
err = os.WriteFile(newFile, bz, 0o644) //nolint: gosec
if err != nil {
return err
}
@@ -92,7 +91,7 @@ func (s *SnapshotStore) Create(state *State) (abci.Snapshot, error) {
Hash: hashItems(state.Values),
Chunks: byteChunks(bz),
}
err = os.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0644)
err = os.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0o644) //nolint:gosec
if err != nil {
return abci.Snapshot{}, err
}

View File

@@ -1,4 +1,3 @@
//nolint: gosec
package app
import (
@@ -12,8 +11,10 @@ import (
"sync"
)
const stateFileName = "app_state.json"
const prevStateFileName = "prev_app_state.json"
const (
stateFileName = "app_state.json"
prevStateFileName = "prev_app_state.json"
)
// State is the application state.
type State struct {
@@ -81,7 +82,7 @@ func (s *State) save() error {
// We write the state to a separate file and move it to the destination, to
// make it atomic.
newFile := fmt.Sprintf("%v.new", s.currentFile)
err = os.WriteFile(newFile, bz, 0644)
err = os.WriteFile(newFile, bz, 0o644) //nolint:gosec
if err != nil {
return fmt.Errorf("failed to write state to %q: %w", s.currentFile, err)
}

View File

@@ -1,4 +1,3 @@
//nolint: gosec
package main
import (
@@ -58,12 +57,12 @@ func NewCLI() *CLI {
// generate generates manifests in a directory.
func (cli *CLI) generate(dir string, groups int) error {
err := os.MkdirAll(dir, 0755)
err := os.MkdirAll(dir, 0o755)
if err != nil {
return err
}
manifests, err := Generate(rand.New(rand.NewSource(randomSeed)))
manifests, err := Generate(rand.New(rand.NewSource(randomSeed))) //nolint:gosec
if err != nil {
return err
}

View File

@@ -1,4 +1,3 @@
//nolint: goconst
package main
import (
@@ -56,6 +55,8 @@ func LoadConfig(file string) (*Config, error) {
// Validate validates the configuration. We don't do exhaustive config
// validation here, instead relying on Testnet.Validate() to handle it.
//
//nolint:goconst
func (cfg Config) Validate() error {
switch {
case cfg.ChainID == "":

View File

@@ -1,4 +1,3 @@
//nolint: gosec
package e2e
import (
@@ -26,9 +25,11 @@ const (
networkIPv6 = "fd80:b10c::/48"
)
type Mode string
type Protocol string
type Perturbation string
type (
Mode string
Protocol string
Perturbation string
)
const (
ModeValidator Mode = "validator"
@@ -396,7 +397,7 @@ func (t Testnet) ArchiveNodes() []*Node {
// RandomNode returns a random non-seed node.
func (t Testnet) RandomNode() *Node {
for {
node := t.Nodes[rand.Intn(len(t.Nodes))]
node := t.Nodes[rand.Intn(len(t.Nodes))] //nolint:gosec
if node.Mode != ModeSeed {
return node
}
@@ -459,7 +460,7 @@ type keyGenerator struct {
func newKeyGenerator(seed int64) *keyGenerator {
return &keyGenerator{
random: rand.New(rand.NewSource(seed)),
random: rand.New(rand.NewSource(seed)), //nolint:gosec
}
}

View File

@@ -5,8 +5,8 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"time"
@@ -234,7 +234,7 @@ func getRandomValidatorIndex(privVals []types.MockPV, vals *types.ValidatorSet)
}
func readPrivKey(keyFilePath string) (crypto.PrivKey, error) {
keyJSONBytes, err := ioutil.ReadFile(keyFilePath)
keyJSONBytes, err := os.ReadFile(keyFilePath)
if err != nil {
return nil, err
}

View File

@@ -1,4 +1,3 @@
//nolint: gosec
package main
import (
@@ -10,7 +9,7 @@ import (
// execute executes a shell command.
func exec(args ...string) error {
cmd := osexec.Command(args[0], args[1:]...)
cmd := osexec.Command(args[0], args[1:]...) //nolint:gosec
out, err := cmd.CombinedOutput()
switch err := err.(type) {
case nil:
@@ -24,7 +23,7 @@ func exec(args ...string) error {
// execVerbose executes a shell command while displaying its output.
func execVerbose(args ...string) error {
cmd := osexec.Command(args[0], args[1:]...)
cmd := osexec.Command(args[0], args[1:]...) //nolint:gosec
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()

View File

@@ -57,7 +57,7 @@ func NewCLI() *CLI {
return err
}
r := rand.New(rand.NewSource(randomSeed)) // nolint: gosec
r := rand.New(rand.NewSource(randomSeed)) //nolint: gosec
chLoadResult := make(chan error)
ctx, loadCancel := context.WithCancel(context.Background())
@@ -203,7 +203,7 @@ func NewCLI() *CLI {
return InjectEvidence(
cmd.Context(),
rand.New(rand.NewSource(randomSeed)), // nolint: gosec
rand.New(rand.NewSource(randomSeed)), //nolint: gosec
cli.testnet,
amount,
)

View File

@@ -1,4 +1,3 @@
// nolint: gosec
package main
import (
@@ -52,7 +51,7 @@ func Setup(testnet *e2e.Testnet) error {
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(testnet.Dir, "docker-compose.yml"), compose, 0644)
err = os.WriteFile(filepath.Join(testnet.Dir, "docker-compose.yml"), compose, 0o644) //nolint:gosec
if err != nil {
return err
}
@@ -75,7 +74,7 @@ func Setup(testnet *e2e.Testnet) error {
if node.Mode == e2e.ModeLight && strings.Contains(dir, "app") {
continue
}
err := os.MkdirAll(dir, 0755)
err := os.MkdirAll(dir, 0o755)
if err != nil {
return err
}
@@ -91,7 +90,7 @@ func Setup(testnet *e2e.Testnet) error {
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(nodeDir, "config", "app.toml"), appCfg, 0644)
err = os.WriteFile(filepath.Join(nodeDir, "config", "app.toml"), appCfg, 0o644) //nolint:gosec
if err != nil {
return err
}
@@ -400,5 +399,5 @@ func UpdateConfigStateSync(node *e2e.Node, height int64, hash []byte) error {
}
bz = regexp.MustCompile(`(?m)^trust_height =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust_height = %v`, height)))
bz = regexp.MustCompile(`(?m)^trust_hash =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust_hash = "%X"`, hash)))
return os.WriteFile(cfgPath, bz, 0644)
return os.WriteFile(cfgPath, bz, 0o644) //nolint:gosec
}

View File

@@ -1,4 +1,3 @@
// nolint: gosec
package addr
import (
@@ -25,7 +24,7 @@ func Fuzz(data []byte) int {
}
// Also, make sure PickAddress always returns a non-nil address.
bias := rand.Intn(100)
bias := rand.Intn(100) //nolint:gosec
if p := addrBook.PickAddress(bias); p == nil {
panic(fmt.Sprintf("picked a nil address (bias: %d, addrBook size: %v)",
bias, addrBook.Size()))

View File

@@ -1,4 +1,3 @@
// nolint: gosec
package main
import (
@@ -26,7 +25,7 @@ func initCorpus(baseDir string) {
// create "corpus" directory
corpusDir := filepath.Join(baseDir, "corpus")
if err := os.MkdirAll(corpusDir, 0755); err != nil {
if err := os.MkdirAll(corpusDir, 0o755); err != nil {
log.Fatalf("Creating %q err: %v", corpusDir, err)
}
@@ -48,7 +47,8 @@ func initCorpus(baseDir string) {
log.Fatalf("can't marshal %v: %v", addr, err)
}
if err := os.WriteFile(filename, bz, 0644); err != nil {
//nolint:gosec
if err := os.WriteFile(filename, bz, 0o644); err != nil {
log.Fatalf("can't write %v to %q: %v", addr, filename, err)
}

View File

@@ -1,4 +1,3 @@
// nolint: gosec
package main
import (
@@ -21,11 +20,12 @@ func main() {
initCorpus(*baseDir)
}
//nolint:gosec
func initCorpus(rootDir string) {
log.SetFlags(0)
corpusDir := filepath.Join(rootDir, "corpus")
if err := os.MkdirAll(corpusDir, 0755); err != nil {
if err := os.MkdirAll(corpusDir, 0o755); err != nil {
log.Fatalf("Creating %q err: %v", corpusDir, err)
}
sizes := []int{0, 1, 2, 17, 5, 31}
@@ -72,7 +72,7 @@ func initCorpus(rootDir string) {
filename := filepath.Join(rootDir, "corpus", fmt.Sprintf("%d", n))
if err := os.WriteFile(filename, bz, 0644); err != nil {
if err := os.WriteFile(filename, bz, 0o644); err != nil {
log.Fatalf("can't write %X to %q: %v", bz, filename, err)
}

View File

@@ -1,4 +1,3 @@
// nolint: gosec
package main
import (
@@ -20,7 +19,7 @@ func initCorpus(baseDir string) {
log.SetFlags(0)
corpusDir := filepath.Join(baseDir, "corpus")
if err := os.MkdirAll(corpusDir, 0755); err != nil {
if err := os.MkdirAll(corpusDir, 0o755); err != nil {
log.Fatal(err)
}
@@ -38,7 +37,8 @@ func initCorpus(baseDir string) {
for i, datum := range data {
filename := filepath.Join(corpusDir, fmt.Sprintf("%d", i))
if err := os.WriteFile(filename, []byte(datum), 0644); err != nil {
//nolint:gosec
if err := os.WriteFile(filename, []byte(datum), 0o644); err != nil {
log.Fatalf("can't write %v to %q: %v", datum, filename, err)
}