Skip to content

Commit 22d9bd2

Browse files
committed
refactor(cmd/lint): remove unused canSkip logic
1 parent a71b0d5 commit 22d9bd2

1 file changed

Lines changed: 34 additions & 49 deletions

File tree

pkg/cmd/lint.go

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var lintCommand = cli.Command{
5454
fmt.Print("\033[2J\033[H")
5555
os.Stdout.Sync()
5656
}
57-
return runLinter(ctx, cmd, false)
57+
return runLinter(ctx, cmd)
5858
},
5959
}
6060

@@ -108,7 +108,7 @@ func (m lintModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
108108

109109
case configChangedEvent:
110110
m.diagnostics = nil // Clear diagnostics while linting
111-
return m, getDiagnosticsCmd(m.ctx, m.cmd, m.client, m.wc)
111+
return m, getDiagnosticsCmd(m.ctx, m.cmd, m.client)
112112

113113
case spinner.TickMsg:
114114
var cmd tea.Cmd
@@ -154,9 +154,9 @@ type diagnosticsMsg struct {
154154
client stainless.Client
155155
}
156156

157-
func getDiagnosticsCmd(ctx context.Context, cmd *cli.Command, client stainless.Client, wc workspace.Config) tea.Cmd {
157+
func getDiagnosticsCmd(ctx context.Context, cmd *cli.Command, client stainless.Client) tea.Cmd {
158158
return func() tea.Msg {
159-
diagnostics, err := getDiagnostics(ctx, cmd, client, wc)
159+
diagnostics, err := getDiagnostics(ctx, cmd, client)
160160
return diagnosticsMsg{
161161
diagnostics: diagnostics,
162162
err: err,
@@ -176,40 +176,34 @@ type GenerateSpecParams struct {
176176
} `json:"source"`
177177
}
178178

179-
func getDiagnostics(ctx context.Context, cmd *cli.Command, client stainless.Client, wc workspace.Config) ([]stainless.BuildDiagnostic, error) {
179+
func getDiagnostics(ctx context.Context, cmd *cli.Command, client stainless.Client) ([]stainless.BuildDiagnostic, error) {
180180
var specParams GenerateSpecParams
181-
if cmd.IsSet("project") {
182-
specParams.Project = cmd.String("project")
183-
} else {
184-
specParams.Project = wc.Project
185-
}
181+
specParams.Project = cmd.String("project")
182+
186183
specParams.Source.Type = "upload"
187184

188-
configPath := wc.StainlessConfig
189-
if cmd.IsSet("stainless-config") {
190-
configPath = cmd.String("stainless-config")
191-
} else if configPath == "" {
192-
return nil, fmt.Errorf("You must provide a stainless configuration file with `--config /path/to/stainless.yml` or run this command from an initialized workspace.")
193-
}
185+
var (
186+
oas []byte
187+
config []byte
188+
err error
189+
)
194190

195-
stainlessConfig, err := os.ReadFile(configPath)
196-
if err != nil {
197-
return nil, fmt.Errorf("Could not read your stainless configuration file:\n%w", err)
191+
if _, config, err = convertFileFlag(cmd, "stainless-config"); err != nil {
192+
return nil, err
193+
}
194+
if _, oas, err = convertFileFlag(cmd, "openapi-spec"); err != nil {
195+
return nil, err
198196
}
199-
specParams.Source.StainlessConfig = string(stainlessConfig)
200197

201-
oasPath := wc.OpenAPISpec
202-
if cmd.IsSet("openapi-spec") {
203-
oasPath = cmd.String("openapi-spec")
204-
} else if oasPath == "" {
198+
if config == nil {
199+
return nil, fmt.Errorf("You must provide a stainless configuration file with `--config /path/to/stainless.yml` or run this command from an initialized workspace.")
200+
}
201+
if oas == nil {
205202
return nil, fmt.Errorf("You must provide an OpenAPI specification with `--oas /path/to/openapi.json` or run this command from an initialized workspace.")
206203
}
207204

208-
openAPISpec, err := os.ReadFile(oasPath)
209-
if err != nil {
210-
return nil, fmt.Errorf("Could not read your stainless configuration file:\n%w", err)
211-
}
212-
specParams.Source.OpenAPISpec = string(openAPISpec)
205+
specParams.Source.StainlessConfig = string(config)
206+
specParams.Source.OpenAPISpec = string(oas)
213207

214208
options := []option.RequestOption{}
215209
if cmd.Bool("debug") {
@@ -234,22 +228,6 @@ func getDiagnostics(ctx context.Context, cmd *cli.Command, client stainless.Clie
234228
return diagnostics, nil
235229
}
236230

237-
func hasBlockingDiagnostic(diagnostics []stainless.BuildDiagnostic) bool {
238-
for _, d := range diagnostics {
239-
if !d.Ignored {
240-
switch d.Level {
241-
case stainless.BuildDiagnosticLevelFatal:
242-
case stainless.BuildDiagnosticLevelError:
243-
case stainless.BuildDiagnosticLevelWarning:
244-
return true
245-
case stainless.BuildDiagnosticLevelNote:
246-
continue
247-
}
248-
}
249-
}
250-
return false
251-
}
252-
253231
func (m lintModel) ShortHelp() []key.Binding {
254232
return []key.Binding{key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("ctrl-c", "quit"))}
255233
}
@@ -258,7 +236,7 @@ func (m lintModel) FullHelp() [][]key.Binding {
258236
return [][]key.Binding{{key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("ctrl-c", "quit"))}}
259237
}
260238

261-
func runLinter(ctx context.Context, cmd *cli.Command, canSkip bool) error {
239+
func runLinter(ctx context.Context, cmd *cli.Command) error {
262240
client := stainless.NewClient(getDefaultRequestOptions(cmd)...)
263241

264242
wc := getWorkspace(ctx)
@@ -283,7 +261,7 @@ func runLinter(ctx context.Context, cmd *cli.Command, canSkip bool) error {
283261
// Start the diagnostics process
284262
go func() {
285263
time.Sleep(100 * time.Millisecond) // Small delay to let the UI initialize
286-
p.Send(getDiagnosticsCmd(ctx, cmd, client, wc)())
264+
p.Send(getDiagnosticsCmd(ctx, cmd, client)())
287265
}()
288266

289267
model, err := p.Run()
@@ -300,9 +278,16 @@ func runLinter(ctx context.Context, cmd *cli.Command, canSkip bool) error {
300278
return finalModel.error
301279
}
302280

303-
// If not in watch mode and we have blocking diagnostics, exit with error code
304281
if !cmd.Bool("watch") {
305-
os.Exit(1)
282+
for _, d := range finalModel.diagnostics {
283+
if d.Ignored {
284+
continue
285+
}
286+
switch d.Level {
287+
case stainless.BuildDiagnosticLevelFatal, stainless.BuildDiagnosticLevelError, stainless.BuildDiagnosticLevelWarning:
288+
return cli.Exit("", 1)
289+
}
290+
}
306291
}
307292

308293
return nil

0 commit comments

Comments
 (0)