diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 50037f8..e78d5d5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -23,8 +23,14 @@ jobs: with: go-version: '1.21' + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3.7.0 + - name: Build run: go build -v ./... - name: Test run: go test -v ./... + + - name: Test concurrency + run: go test -v -race ./... -run Concurrency diff --git a/expreduce.go b/expreduce.go index b7a0606..28b6a2c 100644 --- a/expreduce.go +++ b/expreduce.go @@ -34,10 +34,13 @@ func main() { if err != nil { log.Fatal(err) } - pprof.StartCPUProfile(f) + if err := pprof.StartCPUProfile(f); err != nil { + log.Fatal(err) + } defer pprof.StopCPUProfile() } if *netprofile { + //nolint:errcheck go http.ListenAndServe(":8080", nil) } @@ -63,7 +66,9 @@ func main() { defer f.Close() buf := new(bytes.Buffer) - buf.ReadFrom(f) + if _, err := buf.ReadFrom(f); err != nil { + log.Fatal(err) + } scriptText := buf.String() expreduce.EvalInterpMany(scriptText, *initfile, es) } @@ -76,7 +81,9 @@ func main() { defer f.Close() buf := new(bytes.Buffer) - buf.ReadFrom(f) + if _, err := buf.ReadFrom(f); err != nil { + log.Fatal(err) + } scriptText := buf.String() scriptSession(es, scriptText, *scriptfile) } else { diff --git a/expreduce/builtin_random.go b/expreduce/builtin_random.go index b2401c2..3662866 100644 --- a/expreduce/builtin_random.go +++ b/expreduce/builtin_random.go @@ -34,6 +34,7 @@ func getRandomDefinitions() (defs []Definition) { asInt, isInt := this.GetParts()[1].(*atoms.Integer) if isInt { + //nolint:staticcheck rand.Seed(asInt.Val.Int64()) return atoms.NewSymbol("System`Null") } diff --git a/expreduce/builtin_system.go b/expreduce/builtin_system.go index 6a01e0f..18ddebe 100644 --- a/expreduce/builtin_system.go +++ b/expreduce/builtin_system.go @@ -6,7 +6,6 @@ import ( "encoding/gob" "flag" "fmt" - "io/ioutil" "log" "math/big" "os" @@ -125,7 +124,7 @@ func tryReadFile(fn expreduceapi.Ex, es expreduceapi.EvalStateInterface) ([]byte } pathsToTry = append(pathsToTry, rawFn) for _, rawPath := range pathsToTry { - dat, err := ioutil.ReadFile(rawPath) + dat, err := os.ReadFile(rawPath) if err != nil { continue } @@ -305,7 +304,10 @@ func getSystemDefinitions() (defs []Definition) { if err != nil { log.Fatal(err) } - pprof.WriteHeapProfile(f) + err = pprof.WriteHeapProfile(f) + if err != nil { + log.Fatal(err) + } f.Close() } fmt.Println(es.GetTimeCounter().String()) @@ -728,7 +730,9 @@ func getSystemDefinitions() (defs []Definition) { file, err := os.Create(filename) if err == nil { // Write the header. - file.Write(exprFileHeader) + if _, err := file.Write(exprFileHeader); err != nil { + panic(err) + } compressedWriter := zlib.NewWriter(file) encoder := gob.NewEncoder(compressedWriter) if err := encoder.Encode(definitions); err != nil { diff --git a/expreduce/graphics/graphics.go b/expreduce/graphics/graphics.go index d3d50d0..1902365 100644 --- a/expreduce/graphics/graphics.go +++ b/expreduce/graphics/graphics.go @@ -179,7 +179,10 @@ func Render(expr expreduceapi.Ex) (chart.Chart, error) { Show: true, StrokeColor: drawing.ColorBlack, } - renderPrimitive(&graph, graphics.GetPart(1), &style) + err := renderPrimitive(&graph, graphics.GetPart(1), &style) + if err != nil { + return graph, errors.New("failed to render primitive") + } return graph, nil } diff --git a/expreduce/matcher/matchq.go b/expreduce/matcher/matchq.go index f1bcee9..bf4067d 100644 --- a/expreduce/matcher/matchq.go +++ b/expreduce/matcher/matchq.go @@ -17,8 +17,6 @@ var freezeStateDuringPreMatch = flag.Bool( const maxUint = ^uint(0) const maxInt = int(maxUint >> 1) -const maxUint64 = ^uint64(0) -const maxInt64 = int64(maxUint64 >> 1) type MatchIter interface { // returns ismatch, pd, isdone diff --git a/expreduce/matcher/pdmanager.go b/expreduce/matcher/pdmanager.go index 802b859..10a6853 100644 --- a/expreduce/matcher/pdmanager.go +++ b/expreduce/matcher/pdmanager.go @@ -57,6 +57,7 @@ func (pm *PDManager) len() int { return len(pm.patternDefined) } +//nolint:unused func (pm *PDManager) string(es expreduceapi.EvalStateInterface) string { var buffer bytes.Buffer buffer.WriteString("{") diff --git a/expreduce/streammanager/streammanager.go b/expreduce/streammanager/streammanager.go index 2730eba..9b9d9d9 100644 --- a/expreduce/streammanager/streammanager.go +++ b/expreduce/streammanager/streammanager.go @@ -47,8 +47,8 @@ func (sm streamManagerImpl) WriteString(streamName string, streamIndex int64, to if !hasWriter { return false } - writer.Write([]byte(toWrite)) - return true + _, err := writer.Write([]byte(toWrite)) + return err == nil } func (sm streamManagerImpl) AsExpr() expreduceapi.Ex { diff --git a/utils/factorout/factorout.go b/utils/factorout/factorout.go index 3cc6cc1..2b4171b 100644 --- a/utils/factorout/factorout.go +++ b/utils/factorout/factorout.go @@ -33,7 +33,7 @@ func main() { for _, a := range def.Attributes { b.WriteString(fmt.Sprintf("%s, ", a)) } - b.WriteString(fmt.Sprintf("Protected};\n")) + b.WriteString("Protected};\n") var tests bytes.Buffer hasTests := false tests.WriteString(fmt.Sprintf("Tests`%v = {\n\t", def.Name)) @@ -60,7 +60,7 @@ func main() { tests.WriteString(fmt.Sprintf("%v[\n", testColNames[i])) } for ti, t := range testCol { - tests.WriteString(fmt.Sprintf("\t\t")) + tests.WriteString("\t\t") if tSame, tIsSame := t.(*expreduce.SameTest); tIsSame { tests.WriteString(fmt.Sprintf("ESameTest[%v, %v]", tSame.Out, tSame.In)) } else if tComment, tIsComment := t.(*expreduce.TestComment); tIsComment { @@ -70,25 +70,25 @@ func main() { } else if tExampleOnly, tIsExampleOnly := t.(*expreduce.ExampleOnlyInstruction); tIsExampleOnly { tests.WriteString(fmt.Sprintf("EExampleOnlyInstruction[\"%v\", \"%v\"]", tExampleOnly.Out, tExampleOnly.In)) } else if _, tIsResetState := t.(*expreduce.ResetState); tIsResetState { - tests.WriteString(fmt.Sprintf("EResetState[]")) + tests.WriteString("EResetState[]") } else { tests.WriteString(fmt.Sprintf("%v", t)) log.Fatalf("%v %v %v", t, defSet.Name, def.Name) } if ti != len(testCol)-1 { - tests.WriteString(fmt.Sprintf(",")) + tests.WriteString(",") } - tests.WriteString(fmt.Sprintf("\n")) + tests.WriteString("\n") } - tests.WriteString(fmt.Sprintf("\t]")) + tests.WriteString("\t]") hasTests = true } } - tests.WriteString(fmt.Sprintf("\n};")) + tests.WriteString("\n};") if hasTests { b.WriteString(fmt.Sprintf("%v\n", tests.String())) } - b.WriteString(fmt.Sprintf("\n")) + b.WriteString("\n") } } fmt.Printf("%s\n", strings.TrimSpace(strings.Replace(b.String(), "\t", " ", -1)))