Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable unparam linter #7174

Merged
merged 3 commits into from May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Expand Up @@ -129,9 +129,3 @@ updates:
applies-to: version-updates
patterns:
- "*"

# ignore all npm dependencies in sdk/rust
- package-ecosystem: "npm"
directory: "/sdk/rust"
ignore:
- dependency-name: "*"
23 changes: 20 additions & 3 deletions .golangci.yml
Expand Up @@ -26,21 +26,38 @@ linters:
- typecheck
- unconvert
- unused
- unparam
- whitespace

issues:
exclude-rules:
- path: _test\.go
linters:
# tests are very repetitive
- dupl
# tests are allowed to do silly things
- gosec
- path: docs/
linters:
# example dagger module code might use extra ctx/err in signatures for clarity
- unparam
- text: ".* always receives .*"
linters:
# this is sometimes done for clarity
- unparam

exclude-dirs:
# these files are already linted in sdk/go
- internal/telemetry
- internal/querybuilder

linters-settings:
revive:
rules:
# This rule is annoying. Often you want to name the
# parameters for clarity because it conforms to an
# interface.
# This rule is annoying. Often you want to name the parameters for
# clarity because it conforms to an interface. Additionally, unparam
# finds a good number of cases for this anyways (with fewer false
# positives).
- name: unused-parameter
severity: warning
disabled: true
Expand Down
19 changes: 9 additions & 10 deletions ci/docs.go
Expand Up @@ -63,18 +63,17 @@ func (d Docs) Lint(ctx context.Context) error {
// Regenerate the API schema and CLI reference docs
func (d Docs) Generate(ctx context.Context) (*dagger.Directory, error) {
eg, ctx := errgroup.WithContext(ctx)
_ = ctx

var sdl *dagger.Directory
eg.Go(func() error {
var err error
sdl, err = d.GenerateSdl(ctx)
return err
sdl = d.GenerateSdl()
return nil
})
var cli *dagger.Directory
eg.Go(func() error {
var err error
cli, err = d.GenerateCli(ctx)
return err
cli = d.GenerateCli()
return nil
})

if err := eg.Wait(); err != nil {
Expand All @@ -85,7 +84,7 @@ func (d Docs) Generate(ctx context.Context) (*dagger.Directory, error) {
}

// Regenerate the API schema
func (d Docs) GenerateSdl(ctx context.Context) (*Directory, error) {
func (d Docs) GenerateSdl() *Directory {
introspectionJSON :=
util.GoBase(d.Dagger.Source).
WithExec([]string{"go", "run", "./cmd/introspect"}, dagger.ContainerWithExecOpts{
Expand All @@ -100,14 +99,14 @@ func (d Docs) GenerateSdl(ctx context.Context) (*Directory, error) {
WithExec([]string{"graphql-json-to-sdl", "/src/schema.json", "/src/schema.graphql"}).
File("/src/schema.graphql")

return dag.Directory().WithFile(generatedSchemaPath, generated), nil
return dag.Directory().WithFile(generatedSchemaPath, generated)
}

// Regenerate the CLI reference docs
func (d Docs) GenerateCli(ctx context.Context) (*Directory, error) {
func (d Docs) GenerateCli() *Directory {
// Should we keep `--include-experimental`?
generated := util.GoBase(d.Dagger.Source).
WithExec([]string{"go", "run", "./cmd/dagger", "gen", "--frontmatter=" + cliZenFrontmatter, "--output=cli.mdx", "--include-experimental"}).
File("cli.mdx")
return dag.Directory().WithFile(generatedCliZenPath, generated), nil
return dag.Directory().WithFile(generatedCliZenPath, generated)
}
2 changes: 1 addition & 1 deletion ci/sdk_go.go
Expand Up @@ -106,7 +106,7 @@ func (t GoSDK) Publish(
}

// Bump the Go SDK's Engine dependency
func (t GoSDK) Bump(ctx context.Context, version string) (*Directory, error) {
func (t GoSDK) Bump(version string) (*Directory, error) {
// trim leading v from version
version = strings.TrimPrefix(version, "v")

Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_php.go
Expand Up @@ -83,7 +83,7 @@ func (t PHPSDK) Publish(
}

// Bump the PHP SDK's Engine dependency
func (t PHPSDK) Bump(ctx context.Context, version string) (*Directory, error) {
func (t PHPSDK) Bump(version string) (*Directory, error) {
version = strings.TrimPrefix(version, "v")
content := fmt.Sprintf(`<?php /* Code generated by dagger. DO NOT EDIT. */ return '%s';
`, version)
Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_python.go
Expand Up @@ -155,7 +155,7 @@ func (t PythonSDK) Publish(
}

// Bump the Python SDK's Engine dependency
func (t PythonSDK) Bump(ctx context.Context, version string) (*dagger.Directory, error) {
func (t PythonSDK) Bump(version string) (*dagger.Directory, error) {
// trim leading v from version
version = strings.TrimPrefix(version, "v")
engineReference := fmt.Sprintf("# Code generated by dagger. DO NOT EDIT.\n\nCLI_VERSION = %q\n", version)
Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_typescript.go
Expand Up @@ -156,7 +156,7 @@ always-auth=true`, plaintext)
}

// Bump the Typescript SDK's Engine dependency
func (t TypescriptSDK) Bump(ctx context.Context, version string) (*Directory, error) {
func (t TypescriptSDK) Bump(version string) (*Directory, error) {
// trim leading v from version
version = strings.TrimPrefix(version, "v")

Expand Down
9 changes: 3 additions & 6 deletions cmd/codegen/generator/go/templates/module_objects.go
Expand Up @@ -367,10 +367,7 @@ func (spec *parsedObjectType) marshalJSONMethodCode() (*Statement, error) {
}
concreteFields = append(concreteFields, fieldCode)

getFieldCode, err := spec.setFieldsToMarshalStructCode(field)
if err != nil {
return nil, fmt.Errorf("failed to generate get field code: %w", err)
}
getFieldCode := spec.setFieldsToMarshalStructCode(field)
getFieldCodes = append(getFieldCodes, getFieldCode)
}

Expand Down Expand Up @@ -475,8 +472,8 @@ func (spec *parsedObjectType) setFieldsFromUnmarshalStructCode(field *fieldSpec)
return s, nil
}

func (spec *parsedObjectType) setFieldsToMarshalStructCode(field *fieldSpec) (*Statement, error) {
return Empty().Id("concrete").Dot(field.goName).Op("=").Id("r").Dot(field.goName), nil
func (spec *parsedObjectType) setFieldsToMarshalStructCode(field *fieldSpec) *Statement {
return Empty().Id("concrete").Dot(field.goName).Op("=").Id("r").Dot(field.goName)
}

type fieldSpec struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dagger/flags.go
Expand Up @@ -594,7 +594,7 @@ func (v *moduleSourceValue) Get(ctx context.Context, dag *dagger.Client, _ *dagg

// AddFlag adds a flag appropriate for the argument type. Should return a
// pointer to the value.
func (r *modFunctionArg) AddFlag(flags *pflag.FlagSet, dag *dagger.Client) (any, error) {
func (r *modFunctionArg) AddFlag(flags *pflag.FlagSet) (any, error) {
name := r.FlagName()
usage := r.Description

Expand Down
8 changes: 4 additions & 4 deletions cmd/dagger/functions.go
Expand Up @@ -384,7 +384,7 @@ func (fc *FuncCommand) load(c *cobra.Command, a []string) (cmd *cobra.Command, _

if obj.Constructor != nil {
// add constructor args as top-level flags
if err := fc.addArgsForFunction(c, a, obj.Constructor, dag); err != nil {
if err := fc.addArgsForFunction(c, a, obj.Constructor); err != nil {
return nil, nil, err
}
fc.selectFunc(obj.Name, obj.Constructor, c, dag)
Expand Down Expand Up @@ -454,7 +454,7 @@ func (fc *FuncCommand) makeSubCmd(dag *dagger.Client, fn *modFunction) *cobra.Co
GroupID: funcGroup.ID,
DisableFlagsInUseLine: true,
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
if err := fc.addArgsForFunction(cmd, args, fn, dag); err != nil {
if err := fc.addArgsForFunction(cmd, args, fn); err != nil {
return err
}

Expand Down Expand Up @@ -542,15 +542,15 @@ func (fc *FuncCommand) makeSubCmd(dag *dagger.Client, fn *modFunction) *cobra.Co
return newCmd
}

func (fc *FuncCommand) addArgsForFunction(cmd *cobra.Command, cmdArgs []string, fn *modFunction, dag *dagger.Client) error {
func (fc *FuncCommand) addArgsForFunction(cmd *cobra.Command, cmdArgs []string, fn *modFunction) error {
fc.mod.LoadTypeDef(fn.ReturnType)

for _, arg := range fn.Args {
fc.mod.LoadTypeDef(arg.TypeDef)
}

for _, arg := range fn.Args {
_, err := arg.AddFlag(cmd.Flags(), dag)
_, err := arg.AddFlag(cmd.Flags())
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions core/container.go
Expand Up @@ -724,7 +724,7 @@ func (container *Container) WithSecretVariable(ctx context.Context, name string,
}

func (container *Container) Directory(ctx context.Context, dirPath string) (*Directory, error) {
dir, _, err := locatePath(ctx, container, dirPath, NewDirectory)
dir, _, err := locatePath(container, dirPath, NewDirectory)
if err != nil {
return nil, err
}
Expand All @@ -747,7 +747,7 @@ func (container *Container) Directory(ctx context.Context, dirPath string) (*Dir
}

func (container *Container) File(ctx context.Context, filePath string) (*File, error) {
file, _, err := locatePath(ctx, container, filePath, NewFile)
file, _, err := locatePath(container, filePath, NewFile)
if err != nil {
return nil, err
}
Expand All @@ -767,7 +767,6 @@ func (container *Container) File(ctx context.Context, filePath string) (*File, e
}

func locatePath[T *File | *Directory](
ctx context.Context,
container *Container,
containerPath string,
init func(*Query, *pb.Definition, string, Platform, ServiceBindings) T,
Expand Down Expand Up @@ -929,7 +928,7 @@ func (container *Container) chown(
}

func (container *Container) writeToPath(ctx context.Context, subdir string, fn func(dir *Directory) (*Directory, error)) (*Container, error) {
dir, mount, err := locatePath(ctx, container, subdir, NewDirectory)
dir, mount, err := locatePath(container, subdir, NewDirectory)
if err != nil {
return nil, err
}
Expand Down
8 changes: 3 additions & 5 deletions core/git.go
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/vektah/gqlparser/v2/ast"

"github.com/dagger/dagger/engine"
"github.com/dagger/dagger/engine/buildkit"
"github.com/dagger/dagger/engine/sources/gitdns"
)

Expand Down Expand Up @@ -59,8 +58,7 @@ func (*GitRef) TypeDescription() string {
}

func (ref *GitRef) Tree(ctx context.Context) (*Directory, error) {
bk := ref.Query.Buildkit
st, err := ref.getState(ctx, bk)
st, err := ref.getState(ctx)
if err != nil {
return nil, err
}
Expand All @@ -69,7 +67,7 @@ func (ref *GitRef) Tree(ctx context.Context) (*Directory, error) {

func (ref *GitRef) Commit(ctx context.Context) (string, error) {
bk := ref.Query.Buildkit
st, err := ref.getState(ctx, bk)
st, err := ref.getState(ctx)
if err != nil {
return "", err
}
Expand All @@ -83,7 +81,7 @@ func (ref *GitRef) Commit(ctx context.Context) (string, error) {
return p.Sources.Git[0].Commit, nil
}

func (ref *GitRef) getState(ctx context.Context, bk *buildkit.Client) (llb.State, error) {
func (ref *GitRef) getState(ctx context.Context) (llb.State, error) {
opts := []llb.GitOption{}

if ref.Repo.KeepGitDir {
Expand Down
2 changes: 1 addition & 1 deletion core/integration/module_test.go
Expand Up @@ -5817,7 +5817,7 @@ func hostDaggerCommand(ctx context.Context, t testing.TB, workdir string, args .
}

// runs a dagger cli command directly on the host, rather than in an exec
func hostDaggerExec(ctx context.Context, t testing.TB, workdir string, args ...string) ([]byte, error) {
func hostDaggerExec(ctx context.Context, t testing.TB, workdir string, args ...string) ([]byte, error) { //nolint: unparam
t.Helper()
cmd := hostDaggerCommand(ctx, t, workdir, args...)
output, err := cmd.CombinedOutput()
Expand Down
6 changes: 3 additions & 3 deletions core/interface.go
Expand Up @@ -252,7 +252,7 @@ func (iface *InterfaceType) Install(ctx context.Context, dag *dagql.Server) erro
if err != nil {
return nil, fmt.Errorf("failed to get object return type for %s.%s: %w", ifaceName, fieldDef.Name, err)
}
return wrapIface(ctx, dag, ifaceReturnType, objReturnType, res)
return wrapIface(ifaceReturnType, objReturnType, res)
},
})
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func (iface *InterfaceType) Install(ctx context.Context, dag *dagql.Server) erro
return nil
}

func wrapIface(ctx context.Context, dag *dagql.Server, ifaceType *InterfaceType, underlyingType ModType, res dagql.Typed) (dagql.Typed, error) {
func wrapIface(ifaceType *InterfaceType, underlyingType ModType, res dagql.Typed) (dagql.Typed, error) {
switch underlyingType := underlyingType.(type) {
case *InterfaceType, *ModuleObjectType:
switch res := res.(type) {
Expand Down Expand Up @@ -323,7 +323,7 @@ func wrapIface(ctx context.Context, dag *dagql.Server, ifaceType *InterfaceType,
if ret.Elem == nil { // set the return type
ret.Elem = item
}
val, err := wrapIface(ctx, dag, ifaceType, underlyingType.Underlying, item)
val, err := wrapIface(ifaceType, underlyingType.Underlying, item)
if err != nil {
return nil, fmt.Errorf("failed to wrap item %d: %w", i, err)
}
Expand Down
2 changes: 0 additions & 2 deletions core/modfunc.go
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/dagger/dagger/analytics"
"github.com/dagger/dagger/core/pipeline"
"github.com/dagger/dagger/dagql"
"github.com/dagger/dagger/dagql/call"
"github.com/dagger/dagger/engine/buildkit"
)

Expand All @@ -40,7 +39,6 @@ func newModFunction(
ctx context.Context,
root *Query,
mod *Module,
modID *call.ID,
objDef *ObjectTypeDef,
runtime *Container,
metadata *Function,
Expand Down
1 change: 0 additions & 1 deletion core/module.go
Expand Up @@ -127,7 +127,6 @@ func (mod *Module) Initialize(ctx context.Context, oldSelf dagql.Instance[*Modul
ctx,
mod.Query,
oldSelf.Self,
oldSelf.ID(),
nil,
mod.Runtime,
NewFunction("", &TypeDef{
Expand Down
4 changes: 1 addition & 3 deletions core/object.go
Expand Up @@ -110,7 +110,6 @@ func (t *ModuleObjectType) GetCallable(ctx context.Context, name string) (Callab
ctx,
mod.Query,
mod,
mod.InstanceID,
t.typeDef,
mod.Runtime,
fun,
Expand Down Expand Up @@ -230,7 +229,7 @@ func (obj *ModuleObject) installConstructor(ctx context.Context, dag *dagql.Serv
return fmt.Errorf("constructor function for object %s must return that object", objDef.OriginalName)
}

fn, err := newModFunction(ctx, mod.Query, mod, mod.InstanceID, objDef, mod.Runtime, fnTypeDef)
fn, err := newModFunction(ctx, mod.Query, mod, objDef, mod.Runtime, fnTypeDef)
if err != nil {
return fmt.Errorf("failed to create function: %w", err)
}
Expand Down Expand Up @@ -323,7 +322,6 @@ func objFun(ctx context.Context, mod *Module, objDef *ObjectTypeDef, fun *Functi
ctx,
mod.Query,
mod,
mod.InstanceID,
objDef,
mod.Runtime,
fun,
Expand Down
2 changes: 1 addition & 1 deletion dagger.json
Expand Up @@ -15,4 +15,4 @@
]
}
]
}
}