Skip to content

Commit 94ab80d

Browse files
pieternclaude
andauthored
Add forbidigo rules for terminal detection and fix violations (#4302)
## Changes Configure forbidigo to prevent direct use of term.IsTerminal and isatty functions outside libs/cmdio. Depends on #4298 and #4301. ## Why Use cmdio.IsPromptSupported() instead for consistent capability detection. --------- Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent d2dab23 commit 94ab80d

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

.golangci.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ linters:
2020
- copyloopvar
2121
- forbidigo
2222
settings:
23+
forbidigo:
24+
forbid:
25+
- pattern: 'term\.IsTerminal'
26+
msg: Use cmdio.IsPromptSupported(ctx) to check for a TTY.
27+
- pattern: 'isatty\.IsTerminal'
28+
msg: Use cmdio.IsPromptSupported(ctx) to check for a TTY.
29+
- pattern: 'isatty\.IsCygwinTerminal'
30+
msg: Use cmdio.IsPromptSupported(ctx) to check for a TTY.
31+
analyze-types: true
2332
copyloopvar:
2433
check-alias: true
2534
errcheck:
@@ -96,9 +105,6 @@ linters:
96105
- path: bundle/direct/dresources/.*_test.go
97106
linters:
98107
- exhaustruct
99-
- path-except: ^cmd
100-
linters:
101-
- forbidigo
102108
issues:
103109
max-issues-per-linter: 1000
104110
max-same-issues: 1000

acceptance/pipelines/destroy/auto-approve/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Deployment complete!
88
View your pipeline my_pipeline here: [DATABRICKS_URL]/pipelines/[UUID]?o=[NUMID]
99

1010
>>> errcode [PIPELINES] destroy
11-
Error: please specify --auto-approve to skip interactive confirmation checks for non tty consoles
11+
Error: please specify --auto-approve since terminal does not support interactive prompts
1212

1313
Exit code: 1
1414

cmd/bundle/destroy.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ package bundle
44

55
import (
66
"errors"
7-
"os"
87

98
"github.com/databricks/cli/bundle"
109
"github.com/databricks/cli/bundle/phases"
1110
"github.com/databricks/cli/cmd/bundle/utils"
1211
"github.com/databricks/cli/cmd/root"
12+
"github.com/databricks/cli/libs/cmdio"
1313
"github.com/databricks/cli/libs/logdiag"
1414
"github.com/spf13/cobra"
15-
"golang.org/x/term"
1615
)
1716

1817
func newDestroyCommand() *cobra.Command {
@@ -47,10 +46,9 @@ Typical use cases:
4746
}
4847

4948
func CommandBundleDestroy(cmd *cobra.Command, args []string, autoApprove, forceDestroy bool) error {
50-
// we require auto-approve for non tty terminals since interactive consent
51-
// is not possible
52-
if !term.IsTerminal(int(os.Stderr.Fd())) && !autoApprove {
53-
return errors.New("please specify --auto-approve to skip interactive confirmation checks for non tty consoles")
49+
// We require auto-approve for non-interactive terminals since prompts are not possible.
50+
if !cmdio.IsPromptSupported(cmd.Context()) && !autoApprove {
51+
return errors.New("please specify --auto-approve since terminal does not support interactive prompts")
5452
}
5553

5654
opts := utils.ProcessOptions{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
golang.org/x/oauth2 v0.34.0
3535
golang.org/x/sync v0.19.0
3636
golang.org/x/sys v0.40.0
37-
golang.org/x/term v0.39.0
37+
golang.org/x/term v0.39.0 // indirect
3838
golang.org/x/text v0.33.0
3939
gopkg.in/ini.v1 v1.67.0 // Apache 2.0
4040
gopkg.in/yaml.v3 v3.0.1

libs/cmdio/tty.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func isTTY(v any) bool {
2020
return false
2121
}
2222
fd := f.Fd()
23-
return isatty.IsTerminal(fd) || isatty.IsCygwinTerminal(fd)
23+
return isatty.IsTerminal(fd) || isatty.IsCygwinTerminal(fd) //nolint:forbidigo
2424
}
2525

2626
// fakeTTY wraps an io.Writer and makes IsTTY return true for it.

0 commit comments

Comments
 (0)