Skip to content

Commit e493f63

Browse files
committed
minor
1 parent f34927f commit e493f63

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

cmd/check.go

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,57 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
var checkCmd = &cobra.Command{
13-
Use: "check",
14-
Short: "check a numscript file",
15-
Args: cobra.ExactArgs(1),
16-
Run: func(cmd *cobra.Command, args []string) {
17-
path := args[0]
18-
19-
dat, err := os.ReadFile(path)
20-
if err != nil {
21-
os.Stderr.Write([]byte(err.Error()))
22-
return
23-
}
12+
func check(path string) {
13+
dat, err := os.ReadFile(path)
14+
if err != nil {
15+
os.Stderr.Write([]byte(err.Error()))
16+
return
17+
}
2418

25-
res := analysis.CheckSource(string(dat))
26-
sort.Slice(res.Diagnostics, func(i, j int) bool {
27-
p1 := res.Diagnostics[i].Range.Start
28-
p2 := res.Diagnostics[j].Range.Start
19+
res := analysis.CheckSource(string(dat))
20+
sort.Slice(res.Diagnostics, func(i, j int) bool {
21+
p1 := res.Diagnostics[i].Range.Start
22+
p2 := res.Diagnostics[j].Range.Start
2923

30-
return p2.GtEq(p1)
31-
})
32-
33-
for i, d := range res.Diagnostics {
34-
if i != 0 {
35-
fmt.Print("\n\n")
36-
}
37-
errType := analysis.SeverityToAnsiString(d.Kind.Severity())
38-
fmt.Printf("%s:%d:%d - %s\n%s\n", path, d.Range.Start.Line, d.Range.Start.Character, errType, d.Kind.Message())
39-
}
24+
return p2.GtEq(p1)
25+
})
4026

41-
if len(res.Diagnostics) != 0 {
42-
fmt.Printf("\n\n")
27+
for i, d := range res.Diagnostics {
28+
if i != 0 {
29+
fmt.Print("\n\n")
4330
}
31+
errType := analysis.SeverityToAnsiString(d.Kind.Severity())
32+
fmt.Printf("%s:%d:%d - %s\n%s\n", path, d.Range.Start.Line, d.Range.Start.Character, errType, d.Kind.Message())
33+
}
4434

45-
errorsCount := res.GetErrorsCount()
46-
if errorsCount != 0 {
35+
if len(res.Diagnostics) != 0 {
36+
fmt.Printf("\n\n")
37+
}
4738

48-
var pluralizedError string
49-
if errorsCount == 1 {
50-
pluralizedError = "error"
51-
} else {
52-
pluralizedError = "errors"
39+
errorsCount := res.GetErrorsCount()
40+
if errorsCount != 0 {
5341

54-
}
42+
var pluralizedError string
43+
if errorsCount == 1 {
44+
pluralizedError = "error"
45+
} else {
46+
pluralizedError = "errors"
5547

56-
fmt.Printf("\033[31mFound %d %s\033[0m\n", errorsCount, pluralizedError)
57-
os.Exit(1)
5848
}
5949

60-
fmt.Printf("No errors found ✅\n")
50+
fmt.Printf("\033[31mFound %d %s\033[0m\n", errorsCount, pluralizedError)
51+
os.Exit(1)
52+
}
53+
54+
fmt.Printf("No errors found ✅\n")
55+
}
56+
57+
var checkCmd = &cobra.Command{
58+
Use: "check",
59+
Short: "check a numscript file",
60+
Args: cobra.ExactArgs(1),
61+
Run: func(cmd *cobra.Command, args []string) {
62+
path := args[0]
63+
check(path)
6164
},
6265
}

0 commit comments

Comments
 (0)