Skip to content

Commit

Permalink
Enable perfsprint linter and apply autofix (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
denik authored Jan 7, 2025
1 parent 3629c9e commit e2cd8c2
Show file tree
Hide file tree
Showing 141 changed files with 330 additions and 353 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters:
- testifylint
- intrange
- mirror
- perfsprint
linters-settings:
govet:
enable-all: true
Expand Down
9 changes: 4 additions & 5 deletions bundle/artifacts/expand_globs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package artifacts

import (
"context"
"fmt"
"path/filepath"
"testing"

Expand Down Expand Up @@ -88,16 +87,16 @@ func TestExpandGlobs_InvalidPattern(t *testing.T) {
))

assert.Len(t, diags, 4)
assert.Equal(t, fmt.Sprintf("%s: syntax error in pattern", filepath.Clean("a[.txt")), diags[0].Summary)
assert.Equal(t, filepath.Clean("a[.txt")+": syntax error in pattern", diags[0].Summary)
assert.Equal(t, filepath.Join(tmpDir, "databricks.yml"), diags[0].Locations[0].File)
assert.Equal(t, "artifacts.test.files[0].source", diags[0].Paths[0].String())
assert.Equal(t, fmt.Sprintf("%s: syntax error in pattern", filepath.Clean("a[.txt")), diags[1].Summary)
assert.Equal(t, filepath.Clean("a[.txt")+": syntax error in pattern", diags[1].Summary)
assert.Equal(t, filepath.Join(tmpDir, "databricks.yml"), diags[1].Locations[0].File)
assert.Equal(t, "artifacts.test.files[1].source", diags[1].Paths[0].String())
assert.Equal(t, fmt.Sprintf("%s: syntax error in pattern", filepath.Clean("../a[.txt")), diags[2].Summary)
assert.Equal(t, filepath.Clean("../a[.txt")+": syntax error in pattern", diags[2].Summary)
assert.Equal(t, filepath.Join(tmpDir, "databricks.yml"), diags[2].Locations[0].File)
assert.Equal(t, "artifacts.test.files[2].source", diags[2].Paths[0].String())
assert.Equal(t, fmt.Sprintf("%s: syntax error in pattern", filepath.Clean("subdir/a[.txt")), diags[3].Summary)
assert.Equal(t, filepath.Clean("subdir/a[.txt")+": syntax error in pattern", diags[3].Summary)
assert.Equal(t, filepath.Join(tmpDir, "databricks.yml"), diags[3].Locations[0].File)
assert.Equal(t, "artifacts.test.files[3].source", diags[3].Paths[0].String())
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/artifacts/whl/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (m *infer) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
//)

py := python.GetExecutable()
artifact.BuildCommand = fmt.Sprintf(`%s setup.py bdist_wheel`, py)
artifact.BuildCommand = py + " setup.py bdist_wheel"

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package bundle

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -234,7 +235,7 @@ func (b *Bundle) GetSyncIncludePatterns(ctx context.Context) ([]string, error) {
// we call into from this bundle context.
func (b *Bundle) AuthEnv() (map[string]string, error) {
if b.client == nil {
return nil, fmt.Errorf("workspace client not initialized yet")
return nil, errors.New("workspace client not initialized yet")
}

cfg := b.client.Config
Expand Down
4 changes: 2 additions & 2 deletions bundle/config/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

import (
"context"
"fmt"
"errors"

"github.com/databricks/cli/libs/exec"
)
Expand Down Expand Up @@ -37,7 +37,7 @@ type Artifact struct {

func (a *Artifact) Build(ctx context.Context) ([]byte, error) {
if a.BuildCommand == "" {
return nil, fmt.Errorf("no build property defined")
return nil, errors.New("no build property defined")
}

var e *exec.Executor
Expand Down
3 changes: 1 addition & 2 deletions bundle/config/mutator/expand_workspace_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mutator

import (
"context"
"fmt"
"path"
"strings"

Expand Down Expand Up @@ -33,7 +32,7 @@ func (m *expandWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) diag.
}

if strings.HasPrefix(root, "~/") {
home := fmt.Sprintf("/Workspace/Users/%s", currentUser.UserName)
home := "/Workspace/Users/" + currentUser.UserName
b.Config.Workspace.RootPath = path.Join(home, root[2:])
}

Expand Down
2 changes: 1 addition & 1 deletion bundle/config/mutator/prepend_workspace_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di
}
}

return dyn.NewValue(fmt.Sprintf("/Workspace%s", path), v.Locations()), nil
return dyn.NewValue("/Workspace"+path, v.Locations()), nil
})
if err != nil {
return dyn.InvalidValue, err
Expand Down
23 changes: 12 additions & 11 deletions bundle/config/mutator/python/python_mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package python

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -319,15 +320,15 @@ func TestCreateOverrideVisitor(t *testing.T) {
updatePath: dyn.MustPathFromString("resources.jobs.job0.name"),
deletePath: dyn.MustPathFromString("resources.jobs.job0.name"),
insertPath: dyn.MustPathFromString("resources.jobs.job0.name"),
deleteError: fmt.Errorf("unexpected change at \"resources.jobs.job0.name\" (delete)"),
insertError: fmt.Errorf("unexpected change at \"resources.jobs.job0.name\" (insert)"),
updateError: fmt.Errorf("unexpected change at \"resources.jobs.job0.name\" (update)"),
deleteError: errors.New("unexpected change at \"resources.jobs.job0.name\" (delete)"),
insertError: errors.New("unexpected change at \"resources.jobs.job0.name\" (insert)"),
updateError: errors.New("unexpected change at \"resources.jobs.job0.name\" (update)"),
},
{
name: "load: can't delete an existing job",
phase: PythonMutatorPhaseLoad,
deletePath: dyn.MustPathFromString("resources.jobs.job0"),
deleteError: fmt.Errorf("unexpected change at \"resources.jobs.job0\" (delete)"),
deleteError: errors.New("unexpected change at \"resources.jobs.job0\" (delete)"),
},
{
name: "load: can insert 'resources'",
Expand All @@ -353,9 +354,9 @@ func TestCreateOverrideVisitor(t *testing.T) {
deletePath: dyn.MustPathFromString("include[0]"),
insertPath: dyn.MustPathFromString("include[0]"),
updatePath: dyn.MustPathFromString("include[0]"),
deleteError: fmt.Errorf("unexpected change at \"include[0]\" (delete)"),
insertError: fmt.Errorf("unexpected change at \"include[0]\" (insert)"),
updateError: fmt.Errorf("unexpected change at \"include[0]\" (update)"),
deleteError: errors.New("unexpected change at \"include[0]\" (delete)"),
insertError: errors.New("unexpected change at \"include[0]\" (insert)"),
updateError: errors.New("unexpected change at \"include[0]\" (update)"),
},
{
name: "init: can change an existing job",
Expand All @@ -371,7 +372,7 @@ func TestCreateOverrideVisitor(t *testing.T) {
name: "init: can't delete an existing job",
phase: PythonMutatorPhaseInit,
deletePath: dyn.MustPathFromString("resources.jobs.job0"),
deleteError: fmt.Errorf("unexpected change at \"resources.jobs.job0\" (delete)"),
deleteError: errors.New("unexpected change at \"resources.jobs.job0\" (delete)"),
},
{
name: "init: can insert 'resources'",
Expand All @@ -397,9 +398,9 @@ func TestCreateOverrideVisitor(t *testing.T) {
deletePath: dyn.MustPathFromString("include[0]"),
insertPath: dyn.MustPathFromString("include[0]"),
updatePath: dyn.MustPathFromString("include[0]"),
deleteError: fmt.Errorf("unexpected change at \"include[0]\" (delete)"),
insertError: fmt.Errorf("unexpected change at \"include[0]\" (insert)"),
updateError: fmt.Errorf("unexpected change at \"include[0]\" (update)"),
deleteError: errors.New("unexpected change at \"include[0]\" (delete)"),
insertError: errors.New("unexpected change at \"include[0]\" (insert)"),
updateError: errors.New("unexpected change at \"include[0]\" (update)"),
},
}

Expand Down
6 changes: 3 additions & 3 deletions bundle/config/mutator/resolve_variable_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package mutator

import (
"context"
"fmt"
"errors"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config/variable"
Expand Down Expand Up @@ -68,7 +68,7 @@ func lookupForComplexVariables(v dyn.Value, path dyn.Path) (dyn.Value, error) {
}

if vv.Type == variable.VariableTypeComplex {
return dyn.InvalidValue, fmt.Errorf("complex variables cannot contain references to another complex variables")
return dyn.InvalidValue, errors.New("complex variables cannot contain references to another complex variables")
}

return lookup(v, path)
Expand Down Expand Up @@ -100,7 +100,7 @@ func lookupForVariables(v dyn.Value, path dyn.Path) (dyn.Value, error) {
}

if vv.Lookup != nil && vv.Lookup.String() != "" {
return dyn.InvalidValue, fmt.Errorf("lookup variables cannot contain references to another lookup variables")
return dyn.InvalidValue, errors.New("lookup variables cannot contain references to another lookup variables")
}

return lookup(v, path)
Expand Down
3 changes: 1 addition & 2 deletions bundle/config/resources/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"

"github.com/databricks/cli/libs/log"
Expand Down Expand Up @@ -45,7 +44,7 @@ func (s *Cluster) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("compute/clusters/%s", s.ID)
baseURL.Path = "compute/clusters/" + s.ID
s.URL = baseURL.String()
}

Expand Down
3 changes: 1 addition & 2 deletions bundle/config/resources/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"
"strconv"

Expand Down Expand Up @@ -52,7 +51,7 @@ func (j *Job) InitializeURL(baseURL url.URL) {
if j.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("jobs/%s", j.ID)
baseURL.Path = "jobs/" + j.ID
j.URL = baseURL.String()
}

Expand Down
3 changes: 1 addition & 2 deletions bundle/config/resources/mlflow_experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"

"github.com/databricks/cli/libs/log"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (s *MlflowExperiment) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("ml/experiments/%s", s.ID)
baseURL.Path = "ml/experiments/" + s.ID
s.URL = baseURL.String()
}

Expand Down
3 changes: 1 addition & 2 deletions bundle/config/resources/mlflow_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"

"github.com/databricks/cli/libs/log"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (s *MlflowModel) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("ml/models/%s", s.ID)
baseURL.Path = "ml/models/" + s.ID
s.URL = baseURL.String()
}

Expand Down
3 changes: 1 addition & 2 deletions bundle/config/resources/model_serving_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"

"github.com/databricks/cli/libs/log"
Expand Down Expand Up @@ -55,7 +54,7 @@ func (s *ModelServingEndpoint) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("ml/endpoints/%s", s.ID)
baseURL.Path = "ml/endpoints/" + s.ID
s.URL = baseURL.String()
}

Expand Down
2 changes: 1 addition & 1 deletion bundle/config/resources/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func (p Permission) String() string {
return fmt.Sprintf("level: %s, group_name: %s", p.Level, p.GroupName)
}

return fmt.Sprintf("level: %s", p.Level)
return "level: " + p.Level
}
3 changes: 1 addition & 2 deletions bundle/config/resources/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"

"github.com/databricks/cli/libs/log"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (p *Pipeline) InitializeURL(baseURL url.URL) {
if p.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("pipelines/%s", p.ID)
baseURL.Path = "pipelines/" + p.ID
p.URL = baseURL.String()
}

Expand Down
3 changes: 1 addition & 2 deletions bundle/config/resources/quality_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"
"strings"

Expand Down Expand Up @@ -51,7 +50,7 @@ func (s *QualityMonitor) InitializeURL(baseURL url.URL) {
if s.TableName == "" {
return
}
baseURL.Path = fmt.Sprintf("explore/data/%s", strings.ReplaceAll(s.TableName, ".", "/"))
baseURL.Path = "explore/data/" + strings.ReplaceAll(s.TableName, ".", "/")
s.URL = baseURL.String()
}

Expand Down
3 changes: 1 addition & 2 deletions bundle/config/resources/registered_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"context"
"fmt"
"net/url"
"strings"

Expand Down Expand Up @@ -57,7 +56,7 @@ func (s *RegisteredModel) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("explore/data/models/%s", strings.ReplaceAll(s.ID, ".", "/"))
baseURL.Path = "explore/data/models/" + strings.ReplaceAll(s.ID, ".", "/")
s.URL = baseURL.String()
}

Expand Down
6 changes: 3 additions & 3 deletions bundle/config/resources/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package resources

import (
"context"
"fmt"
"errors"
"net/url"
"strings"

Expand All @@ -26,7 +26,7 @@ type Schema struct {
}

func (s *Schema) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
return false, fmt.Errorf("schema.Exists() is not supported")
return false, errors.New("schema.Exists() is not supported")
}

func (s *Schema) TerraformResourceName() string {
Expand All @@ -37,7 +37,7 @@ func (s *Schema) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("explore/data/%s", strings.ReplaceAll(s.ID, ".", "/"))
baseURL.Path = "explore/data/" + strings.ReplaceAll(s.ID, ".", "/")
s.URL = baseURL.String()
}

Expand Down
6 changes: 3 additions & 3 deletions bundle/config/resources/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package resources

import (
"context"
"fmt"
"errors"
"net/url"
"strings"

Expand Down Expand Up @@ -34,7 +34,7 @@ func (v Volume) MarshalJSON() ([]byte, error) {
}

func (v *Volume) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
return false, fmt.Errorf("volume.Exists() is not supported")
return false, errors.New("volume.Exists() is not supported")
}

func (v *Volume) TerraformResourceName() string {
Expand All @@ -45,7 +45,7 @@ func (v *Volume) InitializeURL(baseURL url.URL) {
if v.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("explore/data/volumes/%s", strings.ReplaceAll(v.ID, ".", "/"))
baseURL.Path = "explore/data/volumes/" + strings.ReplaceAll(v.ID, ".", "/")
v.URL = baseURL.String()
}

Expand Down
Loading

0 comments on commit e2cd8c2

Please sign in to comment.