Skip to content

Commit 965a0c9

Browse files
author
Bruce Hill
committed
Show linter errors on stl lint using the nice format
1 parent 7f6d000 commit 965a0c9

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

cmd/stl-docs/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func generateManpage(filename string) error {
6666

6767
app := cmd.Command
6868

69-
manpage, err := docs.ToMan(&app)
69+
manpage, err := docs.ToMan(app)
7070
if err != nil {
7171
return err
7272
}
@@ -87,7 +87,7 @@ func generateMarkdown(filename string) error {
8787

8888
app := cmd.Command
8989

90-
md, err := docs.ToMarkdown(&app)
90+
md, err := docs.ToMarkdown(app)
9191
if err != nil {
9292
return err
9393
}

pkg/cmd/dev.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@ var devCommand = cli.Command{
271271
Value: false,
272272
Usage: "Only check for diagnostic errors without running a full build.",
273273
},
274-
&cli.StringFlag{
275-
Name: "lint-format",
276-
Value: "pretty",
277-
Usage: "The format for the linter output.",
278-
},
279274
&cli.BoolFlag{
280275
Name: "lint-first",
281276
Value: false,
@@ -380,7 +375,9 @@ func runPreview(ctx context.Context, cmd *cli.Command) error {
380375
}
381376
return err
382377
}
383-
ShowJSON("Linting Results", diagnostics.Raw, cmd.String("lint-format"))
378+
jsonObj := gjson.Parse(diagnostics.Raw)
379+
transform := cmd.String("transform")
380+
ShowJSON("Linting Results", jsonObj, cmd.String("format"), transform)
384381
}
385382

386383
// Start the build process
@@ -422,17 +419,16 @@ func runLintLoop(ctx context.Context, cmd *cli.Command) error {
422419
}
423420
return err
424421
}
425-
ShowJSON("Diagnostics", diagnostics.Raw, cmd.String("lint-format"))
422+
jsonObj := gjson.Parse(diagnostics.Raw)
423+
ShowJSON("Diagnostics", jsonObj, cmd.String("format"), cmd.String("transform"))
426424

427425
if !cmd.Bool("watch") {
428426
break
429427
}
430428

431-
// Watch for file changes instead of sleeping
432429
for {
433-
time.Sleep(500 * time.Millisecond) // Check every 500ms
430+
time.Sleep(500 * time.Millisecond)
434431

435-
// Check OpenAPI spec file
436432
if openapiSpecStat, err := os.Stat(openapiSpecPath); err == nil {
437433
if openapiSpecStat.ModTime().After(openapiSpecLastModified) {
438434
openapiSpecLastModified = openapiSpecStat.ModTime()

pkg/cmd/dev_view.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
"time"
77

8-
"github.com/charmbracelet/bubbletea"
8+
tea "github.com/charmbracelet/bubbletea"
99
"github.com/charmbracelet/glamour"
1010
"github.com/charmbracelet/lipgloss"
1111
"github.com/stainless-api/stainless-api-go"
@@ -397,10 +397,9 @@ func ViewDiagnosticsPrint(diagnostics []stainless.BuildDiagnostic) string {
397397
s.WriteString(lipgloss.NewStyle().
398398
Padding(1).
399399
Border(lipgloss.RoundedBorder()).
400-
BorderForeground(lipgloss.Color("7")).
400+
BorderForeground(lipgloss.Color("208")).
401401
Render(strings.TrimRight(sub.String(), "\n")),
402402
)
403-
s.WriteString("\n\n")
404403
} else {
405404
s.WriteString(SProperty(0, "diagnostics", "(no errors or warnings)"))
406405
}

pkg/cmd/lint.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package cmd
22

33
import (
44
"context"
5+
"encoding/json"
6+
"fmt"
57
"os"
68

9+
"github.com/stainless-api/stainless-api-go"
710
"github.com/stainless-api/stainless-api-go/option"
11+
"github.com/tidwall/gjson"
812
"github.com/urfave/cli/v3"
913
)
1014

@@ -63,5 +67,23 @@ func runLinter(ctx context.Context, cmd *cli.Command) error {
6367
if err != nil {
6468
return err
6569
}
66-
return ShowJSON("Diagnostics", string(result), "json")
70+
71+
transform := "spec.diagnostics.@values.@flatten.#(ignored==false)#"
72+
jsonObj := gjson.Parse(string(result)).Get(transform)
73+
var diagnostics []stainless.BuildDiagnostic
74+
json.Unmarshal([]byte(jsonObj.Raw), &diagnostics)
75+
fmt.Println(ViewDiagnosticsPrint(diagnostics))
76+
for _, d := range diagnostics {
77+
if !d.Ignored {
78+
switch d.Level {
79+
case stainless.BuildDiagnosticLevelFatal:
80+
case stainless.BuildDiagnosticLevelError:
81+
case stainless.BuildDiagnosticLevelWarning:
82+
os.Exit(1)
83+
case stainless.BuildDiagnosticLevelNote:
84+
continue
85+
}
86+
}
87+
}
88+
return nil
6789
}

0 commit comments

Comments
 (0)