mirror of
https://github.com/hanzoai/numscript.git
synced 2026-10-30 18:26:57 +00:00
3dc4fdbe11
* feat: add Nix flake for Go 1.23 development environment * feat: add .envrc and Justfile for environment setup; remove obsolete scripts * feat: add antlr to Nix flake dependencies * chore: update ANTLR version in generated files to 4.13.2 * feat: add GitHub Actions for environment setup and release management; remove obsolete workflows * chore: remove SPEAKEASY_API_KEY from workflows to streamline environment variables * refactor: simplify range checks in hover functions and update variable end position * refactor: improve error handling and logging across multiple files * feat: Update flake.nix Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
|
|
"github.com/formancehq/numscript/internal/analysis"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func check(path string) {
|
|
dat, err := os.ReadFile(path)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error reading file: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
res := analysis.CheckSource(string(dat))
|
|
sort.Slice(res.Diagnostics, func(i, j int) bool {
|
|
p1 := res.Diagnostics[i].Range.Start
|
|
p2 := res.Diagnostics[j].Range.Start
|
|
|
|
return p2.GtEq(p1)
|
|
})
|
|
|
|
for i, d := range res.Diagnostics {
|
|
if i != 0 {
|
|
fmt.Print("\n\n")
|
|
}
|
|
errType := analysis.SeverityToAnsiString(d.Kind.Severity())
|
|
fmt.Printf("%s:%d:%d - %s\n%s\n", path, d.Range.Start.Line, d.Range.Start.Character, errType, d.Kind.Message())
|
|
}
|
|
|
|
if len(res.Diagnostics) != 0 {
|
|
fmt.Printf("\n\n")
|
|
}
|
|
|
|
errorsCount := res.GetErrorsCount()
|
|
if errorsCount != 0 {
|
|
|
|
var pluralizedError string
|
|
if errorsCount == 1 {
|
|
pluralizedError = "error"
|
|
} else {
|
|
pluralizedError = "errors"
|
|
|
|
}
|
|
|
|
fmt.Printf("\033[31mFound %d %s\033[0m\n", errorsCount, pluralizedError)
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Printf("No errors found ✅\n")
|
|
}
|
|
|
|
var checkCmd = &cobra.Command{
|
|
Use: "check <path>",
|
|
Short: "Check a numscript file",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
path := args[0]
|
|
check(path)
|
|
},
|
|
}
|