Skip to content

Commit a698cdc

Browse files
authored
Enable 13 more linters and fix all violations (#4997)
## Changes - Enable 13 additional golangci-lint linters and fix all violations. Intentional patterns (e.g. deliberate nil-error returns) are annotated with `//nolint`. - Fix IPv6-unsafe host:port formatting in apps run-local config (`fmt.Sprintf` → `net.JoinHostPort`). - Fix user-facing typos: "paramaters" → "parameters", "app app proxy" → "app proxy". ## Why Follow-up to #4978. These linters catch real bugs at compile time (silently discarded errors, IPv6 breakage) and prevent future regressions. ## Tests No new tests. Validated with `golangci-lint run ./...`. One existing test assertion updated to match a corrected error string.
1 parent db527d1 commit a698cdc

62 files changed

Lines changed: 97 additions & 91 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ linters:
2121
- forbidigo
2222
- depguard
2323
- usestdlibvars
24+
- nilerr
25+
- fatcontext
26+
- nosprintfhostport
27+
- recvcheck
28+
- usetesting
29+
- dupword
30+
- misspell
31+
- nilnesserr
32+
- durationcheck
33+
- exptostd
34+
- gocheckcompilerdirectives
35+
- asciicheck
36+
- reassign
2437
settings:
2538
depguard:
2639
rules:

acceptance/acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ func runTest(t *testing.T,
610610
if KeepTmp {
611611
tempDirBase := filepath.Join(os.TempDir(), "acceptance")
612612
_ = os.Mkdir(tempDirBase, 0o755)
613-
tmpDir, err = os.MkdirTemp(tempDirBase, "")
613+
tmpDir, err = os.MkdirTemp(tempDirBase, "") //nolint:usetesting // KeepTmp: dir must persist after test for debugging
614614
require.NoError(t, err)
615615
t.Logf("Created directory: %s", tmpDir)
616616
} else if WorkspaceTmpDir {

acceptance/internal/cmd_server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ func chdir(t *testing.T, cwd string) func() {
4949
require.NotEmpty(t, cwd)
5050
prevDir, err := os.Getwd()
5151
require.NoError(t, err)
52-
err = os.Chdir(cwd)
52+
err = os.Chdir(cwd) //nolint:usetesting // must restore before function ends, not at test cleanup
5353
require.NoError(t, err)
5454
return func() {
55-
_ = os.Chdir(prevDir)
55+
_ = os.Chdir(prevDir) //nolint:usetesting // see above
5656
}
5757
}
5858

@@ -62,15 +62,15 @@ func configureEnv(t *testing.T, env map[string]string) func() {
6262
// Set current process's environment to match the input.
6363
os.Clearenv()
6464
for key, val := range env {
65-
os.Setenv(key, val)
65+
os.Setenv(key, val) //nolint:usetesting // custom restore needed; t.Setenv can't clearenv+restore all
6666
}
6767

6868
// Function callback to use with defer to restore original environment.
6969
return func() {
7070
os.Clearenv()
7171
for _, kv := range oldEnv {
7272
kvs := strings.SplitN(kv, "=", 2)
73-
os.Setenv(kvs[0], kvs[1])
73+
os.Setenv(kvs[0], kvs[1]) //nolint:usetesting // see above
7474
}
7575
}
7676
}

acceptance/internal/prepare_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func StartDefaultServer(t *testing.T, logRequests bool) {
4444
// This approach ensures test reliability across platforms.
4545
//
4646
// See debugging journey in https://github.com/databricks/cli/pull/3575.
47-
homeDir, err := os.MkdirTemp("", "acceptance-home-dir")
47+
homeDir, err := os.MkdirTemp("", "acceptance-home-dir") //nolint:usetesting // t.TempDir() fails on Windows; see PR #3575
4848
require.NoError(t, err)
4949
t.Cleanup(func() {
5050
err := os.RemoveAll(homeDir)
@@ -123,7 +123,7 @@ func PrepareServerAndClient(t *testing.T, config TestConfig, logRequests bool, o
123123
}
124124

125125
// For the purposes of replacements, use testUser for local runs.
126-
// Note, users might have overriden /api/2.0/preview/scim/v2/Me but that should not affect the replacement:
126+
// Note, users might have overridden /api/2.0/preview/scim/v2/Me but that should not affect the replacement:
127127
return cfg, testUser
128128
}
129129

bundle/apps/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (v *validate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
4646
diags = append(diags, diag.Diagnostic{
4747
Severity: diag.Error,
4848
Summary: "Duplicate app source code path",
49-
Detail: fmt.Sprintf("app resource '%s' has the same source code path as app resource '%s', this will lead to the app configuration being overriden by each other", key, usedSourceCodePaths[app.SourceCodePath]),
49+
Detail: fmt.Sprintf("app resource '%s' has the same source code path as app resource '%s', this will lead to the app configuration being overridden by each other", key, usedSourceCodePaths[app.SourceCodePath]),
5050
Locations: b.Config.GetLocations(fmt.Sprintf("resources.apps.%s.source_code_path", key)),
5151
})
5252
}

bundle/artifacts/prepare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func InsertPythonArtifact(ctx context.Context, b *bundle.Bundle) error {
117117
_, err := os.Stat(setupPy)
118118
if err != nil {
119119
log.Infof(ctx, "No Python wheel project found at bundle root folder")
120-
return nil
120+
return nil //nolint:nilerr // setup.py not found means no wheel project to detect
121121
}
122122

123123
log.Infof(ctx, "Found Python wheel project at %s", b.BundleRootPath)

bundle/config/mutator/resourcemutator/apply_target_mode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (m *applyTargetMode) Name() string {
2323
}
2424

2525
// Mark all resources as being for 'development' purposes, i.e.
26-
// changing their their name, adding tags, and (in the future)
26+
// changing their name, adding tags, and (in the future)
2727
// marking them as 'hidden' in the UI.
2828
func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) {
2929
if !b.Config.Bundle.Deployment.Lock.IsExplicitlyEnabled() {

bundle/config/mutator/rewrite_workspace_prefix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
type rewriteWorkspacePrefix struct{}
1414

15-
// RewriteWorkspacePrefix finds any strings in bundle configration that have
15+
// RewriteWorkspacePrefix finds any strings in bundle configuration that have
1616
// workspace prefix plus workspace path variable used and removes workspace prefix from it.
1717
func RewriteWorkspacePrefix() bundle.Mutator {
1818
return &rewriteWorkspacePrefix{}

bundle/config/mutator/set_variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestSetVariablesMutator(t *testing.T) {
122122
Default: defaultValForA,
123123
},
124124
"b": {
125-
Description: "resolved from environment vairables",
125+
Description: "resolved from environment variables",
126126
Default: defaultValForB,
127127
},
128128
"c": {

bundle/config/resources/secret_scope.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type SecretScopePermission struct {
2828
GroupName string `json:"group_name,omitempty"`
2929
}
3030

31-
type SecretScope struct {
31+
type SecretScope struct { //nolint:recvcheck // pointer receiver needed for UnmarshalJSON, value for other methods
3232
BaseResource
3333

3434
// A unique name to identify the secret scope.
@@ -67,7 +67,7 @@ func (s SecretScope) Exists(ctx context.Context, w *databricks.WorkspaceClient,
6767
// The indirect methods are not semantically ideal for simple existence checks, so we use the list API here
6868
scopes, err := w.Secrets.ListScopesAll(ctx)
6969
if err != nil {
70-
return false, nil
70+
return false, nil //nolint:nilerr // treat API errors as "scope not found"
7171
}
7272

7373
for _, scope := range scopes {

0 commit comments

Comments
 (0)