all: upgrade golangci-lint and formatters (#240)

This commit is contained in:
Michael McLoughlin
2022-03-27 15:31:26 -07:00
committed by GitHub
parent 553930530f
commit 72b8db9c80
24 changed files with 179 additions and 118 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"go/build"
"log"
"os"
@@ -43,12 +44,17 @@ func main() {
log.SetPrefix("avogen: ")
log.SetFlags(0)
flag.Parse()
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
// Build generator.
t := flag.Arg(0)
builder := generators[t]
if builder == nil {
log.Fatalf("unknown generator type '%s'", t)
return fmt.Errorf("unknown generator type '%s'", t)
}
g := builder(printer.NewArgvConfig())
@@ -58,7 +64,7 @@ func main() {
if *output != "" {
f, err := os.Create(*output)
if err != nil {
log.Fatal(err)
return err
}
defer f.Close()
w = f
@@ -71,7 +77,7 @@ func main() {
l := load.NewLoaderFromDataDir(*datadir)
r, err := l.Load()
if err != nil {
log.Fatal(err)
return err
}
is = r
}
@@ -81,10 +87,12 @@ func main() {
// Write.
if _, err := w.Write(b); err != nil {
log.Fatal(err)
return err
}
if generr != nil {
log.Fatal(generr)
return generr
}
return nil
}

View File

@@ -187,11 +187,17 @@ func (t *Table) SuffixesTypeName() string {
// SuffixesConst returns the constant for a list of suffixes. Suffixes is a
// generated array type, so the list is a value not slice type.
func (t *Table) SuffixesConst(suffixes inst.Suffixes) string {
return t.SuffixesTypeName() + t.SuffixesList(suffixes)
}
// SuffixesList returns the constant literal for a list of suffixes, type name
// not included. Use SuffxesConst if the type is required.
func (t *Table) SuffixesList(suffixes inst.Suffixes) string {
var parts []string
for _, suffix := range suffixes {
parts = append(parts, t.SuffixConst(suffix))
}
return t.SuffixesTypeName() + "{" + strings.Join(parts, ", ") + "}"
return "{" + strings.Join(parts, ", ") + "}"
}
// SuffixesClass returns the enumeration representing all suffixes classes.

View File

@@ -6,10 +6,9 @@ import (
"strings"
"github.com/mmcloughlin/avo/internal/api"
"github.com/mmcloughlin/avo/internal/inst"
"github.com/mmcloughlin/avo/internal/prnt"
"github.com/mmcloughlin/avo/printer"
"github.com/mmcloughlin/avo/internal/inst"
)
type ctorstest struct {

View File

@@ -134,7 +134,7 @@ func (t *optab) suffixesType(is []inst.Instruction) {
var entries []string
for _, class := range inst.SuffixesClasses(is) {
for _, suffixes := range class {
entry := fmt.Sprintf("%s: %#v", t.table.SuffixesConst(suffixes), suffixes.Strings())
entry := fmt.Sprintf("%s: %s", t.table.SuffixesList(suffixes), stringsliteral(suffixes.Strings()))
entries = append(entries, entry)
}
}
@@ -177,7 +177,7 @@ func (t *optab) isasEnum(is []inst.Instruction) {
// Mapping method to produce the list of ISAs.
lists := map[string]string{}
for _, isas := range inst.ISACombinations(is) {
lists[api.ISAsIdentifier(isas)] = fmt.Sprintf("%#v", isas)
lists[api.ISAsIdentifier(isas)] = stringsliteral(isas)
}
t.mapping(e, "List", "[]string", "nil", lists)
}
@@ -286,3 +286,14 @@ func (t *optab) stringmethod(e *Enum) {
}
t.mapping(e, "String", "string", `""`, s)
}
func stringsliteral(ss []string) string {
if ss == nil {
return "nil"
}
var quoted []string
for _, s := range ss {
quoted = append(quoted, strconv.Quote(s))
}
return "{" + strings.Join(quoted, ", ") + "}"
}

View File

@@ -855,7 +855,7 @@ func dedupe(fs []inst.Form) []inst.Form {
return uniq
}
// sortforms sorts a list of forms
// sortforms sorts a list of forms.
func sortforms(fs []inst.Form) {
sort.Slice(fs, func(i, j int) bool {
return sortkey(fs[i]) < sortkey(fs[j])

View File

@@ -32,7 +32,7 @@ func Assembles(t *testing.T, asm []byte) {
defer clean()
asmfilename := filepath.Join(dir, "asm.s")
if err := ioutil.WriteFile(asmfilename, asm, 0600); err != nil {
if err := ioutil.WriteFile(asmfilename, asm, 0o600); err != nil {
t.Fatal(err)
}
@@ -96,11 +96,13 @@ func GoTool() string {
// goexec runs a "go" command and checks the output.
func goexec(t *testing.T, arg ...string) {
t.Helper()
Exec(t, GoTool(), arg...)
}
// Logger builds a logger that writes to the test object.
func Logger(tb testing.TB) *log.Logger {
tb.Helper()
return log.New(Writer(tb), "test", log.LstdFlags)
}
@@ -110,6 +112,7 @@ type writer struct {
// Writer builds a writer that logs all writes to the test object.
func Writer(tb testing.TB) io.Writer {
tb.Helper()
return writer{tb}
}