diff --git a/.golangci.yml b/.golangci.yml index 2a78dc7418b..9d2ba93a397 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,21 +25,34 @@ 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 + 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 diff --git a/cmd/codegen/generator/go/templates/module_objects.go b/cmd/codegen/generator/go/templates/module_objects.go index e31d6139869..71b98c3d591 100644 --- a/cmd/codegen/generator/go/templates/module_objects.go +++ b/cmd/codegen/generator/go/templates/module_objects.go @@ -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) } @@ -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 { diff --git a/cmd/dagger/flags.go b/cmd/dagger/flags.go index fd8c4bb79fe..c823445bcb5 100644 --- a/cmd/dagger/flags.go +++ b/cmd/dagger/flags.go @@ -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 diff --git a/cmd/dagger/functions.go b/cmd/dagger/functions.go index f2e422b6e57..b5ab5cef83d 100644 --- a/cmd/dagger/functions.go +++ b/cmd/dagger/functions.go @@ -377,7 +377,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) @@ -446,7 +446,7 @@ func (fc *FuncCommand) makeSubCmd(dag *dagger.Client, fn *modFunction) *cobra.Co Long: fn.Description, GroupID: funcGroup.ID, 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 } @@ -534,7 +534,7 @@ 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 { @@ -542,7 +542,7 @@ func (fc *FuncCommand) addArgsForFunction(cmd *cobra.Command, cmdArgs []string, } for _, arg := range fn.Args { - _, err := arg.AddFlag(cmd.Flags(), dag) + _, err := arg.AddFlag(cmd.Flags()) if err != nil { return err } diff --git a/cmd/engine/executor.go b/cmd/engine/executor.go index 516960304c7..3d27e9d18c1 100644 --- a/cmd/engine/executor.go +++ b/cmd/engine/executor.go @@ -517,7 +517,7 @@ func (w *runcExecutor) run( }) return err } - err = exitError(ctx, w.callWithIO(ctx, id, bundle, process, startedCallback, killer, runcCall)) + err = exitError(ctx, w.callWithIO(ctx, process, startedCallback, killer, runcCall)) if err != nil { w.runc.Delete(context.TODO(), id, &runc.DeleteOpts{}) return err @@ -589,18 +589,18 @@ func (w *runcExecutor) Exec(ctx context.Context, id string, process executor.Pro spec.Process.Env = process.Meta.Env } - err = w.exec(ctx, id, state.Bundle, spec.Process, process, nil) + err = w.exec(ctx, id, spec.Process, process, nil) return exitError(ctx, err) } -func (w *runcExecutor) exec(ctx context.Context, id, bundle string, specsProcess *specs.Process, process executor.ProcessInfo, started func()) error { +func (w *runcExecutor) exec(ctx context.Context, id string, specsProcess *specs.Process, process executor.ProcessInfo, started func()) error { killer, err := newExecProcKiller(w.runc, id) if err != nil { return fmt.Errorf("failed to initialize process killer: %w", err) } defer killer.Cleanup() - return w.callWithIO(ctx, id, bundle, process, started, killer, func(ctx context.Context, started chan<- int, io runc.IO, pidfile string) error { + return w.callWithIO(ctx, process, started, killer, func(ctx context.Context, started chan<- int, io runc.IO, pidfile string) error { return w.runc.Exec(ctx, id, *specsProcess, &runc.ExecOpts{ Started: started, IO: io, @@ -930,7 +930,7 @@ func handleSignals(ctx context.Context, runcProcess *procHandle, signals <-chan type runcCall func(ctx context.Context, started chan<- int, io runc.IO, pidfile string) error -func (w *runcExecutor) callWithIO(ctx context.Context, id, bundle string, process executor.ProcessInfo, started func(), killer procKiller, call runcCall) error { +func (w *runcExecutor) callWithIO(ctx context.Context, process executor.ProcessInfo, started func(), killer procKiller, call runcCall) error { runcProcess, ctx := runcProcessHandle(ctx, killer) defer runcProcess.Release() diff --git a/core/container.go b/core/container.go index cb008463f9b..e7770d0aa66 100644 --- a/core/container.go +++ b/core/container.go @@ -726,7 +726,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 } @@ -749,7 +749,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 } @@ -769,7 +769,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, @@ -931,7 +930,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 } diff --git a/core/git.go b/core/git.go index f0f9774f815..027cc9646cb 100644 --- a/core/git.go +++ b/core/git.go @@ -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" ) @@ -59,14 +58,13 @@ func (*GitRef) TypeDescription() string { } func (ref *GitRef) Tree(ctx context.Context) (*Directory, error) { - bk := ref.Query.Buildkit - st := ref.getState(ctx, bk) + st := ref.getState(ctx) return NewDirectorySt(ctx, ref.Query, *st, "", ref.Repo.Platform, ref.Repo.Services) } func (ref *GitRef) Commit(ctx context.Context) (string, error) { + st := ref.getState(ctx) bk := ref.Query.Buildkit - st := ref.getState(ctx, bk) p, err := resolveProvenance(ctx, bk, *st) if err != nil { return "", err @@ -77,7 +75,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 { +func (ref *GitRef) getState(ctx context.Context) *llb.State { opts := []llb.GitOption{} if ref.Repo.KeepGitDir { diff --git a/core/integration/module_test.go b/core/integration/module_test.go index 7e1a2dcf04f..cd6b2fe1f14 100644 --- a/core/integration/module_test.go +++ b/core/integration/module_test.go @@ -5705,7 +5705,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() diff --git a/core/interface.go b/core/interface.go index 9eb3d604fc9..bb910aca5ed 100644 --- a/core/interface.go +++ b/core/interface.go @@ -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) }, }) } @@ -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) { @@ -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) } diff --git a/core/modfunc.go b/core/modfunc.go index 0828739a987..20d538ddf6b 100644 --- a/core/modfunc.go +++ b/core/modfunc.go @@ -41,7 +41,6 @@ func newModFunction( ctx context.Context, root *Query, mod *Module, - modID *call.ID, objDef *ObjectTypeDef, runtime *Container, metadata *Function, diff --git a/core/module.go b/core/module.go index b4e28b07cf9..2fbb845ff1c 100644 --- a/core/module.go +++ b/core/module.go @@ -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{ diff --git a/core/object.go b/core/object.go index d2c1009cdf0..ddf8e761dcc 100644 --- a/core/object.go +++ b/core/object.go @@ -111,7 +111,6 @@ func (t *ModuleObjectType) GetCallable(ctx context.Context, name string) (Callab ctx, mod.Query, mod, - mod.InstanceID, t.typeDef, mod.Runtime, fun, @@ -231,7 +230,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) } @@ -324,7 +323,6 @@ func objFun(ctx context.Context, mod *Module, objDef *ObjectTypeDef, fun *Functi ctx, mod.Query, mod, - mod.InstanceID, objDef, mod.Runtime, fun, diff --git a/engine/sources/blob/blobsource.go b/engine/sources/blob/blobsource.go index b9fd668527b..27a2a89b79e 100644 --- a/engine/sources/blob/blobsource.go +++ b/engine/sources/blob/blobsource.go @@ -75,8 +75,11 @@ func IdentifierFromPB(op *pb.SourceOp) (*SourceIdentifier, error) { if !ok { return nil, fmt.Errorf("invalid blob source identifier %q", op.Identifier) } + if scheme != BlobScheme { + return nil, fmt.Errorf("invalid blob source identifier %q", op.Identifier) + } bs := &blobSource{} - return bs.identifier(scheme, ref, op.GetAttrs(), nil) + return bs.identifier(ref, op.GetAttrs(), nil) } func NewSource(opt Opt) (source.Source, error) { @@ -91,10 +94,10 @@ func (bs *blobSource) Schemes() []string { } func (bs *blobSource) Identifier(scheme, ref string, sourceAttrs map[string]string, p *pb.Platform) (source.Identifier, error) { - return bs.identifier(scheme, ref, sourceAttrs, p) + return bs.identifier(ref, sourceAttrs, p) } -func (bs *blobSource) identifier(scheme, ref string, sourceAttrs map[string]string, _ *pb.Platform) (*SourceIdentifier, error) { +func (bs *blobSource) identifier(ref string, sourceAttrs map[string]string, _ *pb.Platform) (*SourceIdentifier, error) { desc := ocispecs.Descriptor{ Digest: digest.Digest(ref), Annotations: map[string]string{}, diff --git a/sdk/go/telemetry/batch_processor.go b/sdk/go/telemetry/batch_processor.go index 1ed04abb8b5..f5c49a08dcb 100644 --- a/sdk/go/telemetry/batch_processor.go +++ b/sdk/go/telemetry/batch_processor.go @@ -410,7 +410,7 @@ func (bsp *batchSpanProcessor) enqueue(sd trace.ReadOnlySpan) { if bsp.o.BlockOnQueueFull { bsp.enqueueBlockOnQueueFull(ctx, sd) } else { - bsp.enqueueDrop(ctx, sd) + bsp.enqueueDrop(sd) } } @@ -427,7 +427,7 @@ func (bsp *batchSpanProcessor) enqueueBlockOnQueueFull(ctx context.Context, sd t } } -func (bsp *batchSpanProcessor) enqueueDrop(ctx context.Context, sd trace.ReadOnlySpan) bool { +func (bsp *batchSpanProcessor) enqueueDrop(sd trace.ReadOnlySpan) bool { if !sd.SpanContext().IsSampled() { return false } diff --git a/telemetry/inflight/batch_processor.go b/telemetry/inflight/batch_processor.go index 116bff64c91..867c9d60348 100644 --- a/telemetry/inflight/batch_processor.go +++ b/telemetry/inflight/batch_processor.go @@ -412,7 +412,7 @@ func (bsp *batchSpanProcessor) enqueue(sd trace.ReadOnlySpan) { if bsp.o.BlockOnQueueFull { bsp.enqueueBlockOnQueueFull(ctx, sd) } else { - bsp.enqueueDrop(ctx, sd) + bsp.enqueueDrop(sd) } } @@ -429,7 +429,7 @@ func (bsp *batchSpanProcessor) enqueueBlockOnQueueFull(ctx context.Context, sd t } } -func (bsp *batchSpanProcessor) enqueueDrop(ctx context.Context, sd trace.ReadOnlySpan) bool { +func (bsp *batchSpanProcessor) enqueueDrop(sd trace.ReadOnlySpan) bool { if !sd.SpanContext().IsSampled() { return false } diff --git a/telemetry/labels_test.go b/telemetry/labels_test.go index a84a90466ce..ef48d480d34 100644 --- a/telemetry/labels_test.go +++ b/telemetry/labels_test.go @@ -334,7 +334,7 @@ func TestLoadCircleCILabels(t *testing.T) { } } -func run(t *testing.T, exe string, args ...string) string { //nolint: unparam +func run(t *testing.T, exe string, args ...string) string { t.Helper() cmd := exec.Command(exe, args...) cmd.Stderr = os.Stderr diff --git a/telemetry/sdklog/batch_processor.go b/telemetry/sdklog/batch_processor.go index 29d5b80ed62..8184f430b7a 100644 --- a/telemetry/sdklog/batch_processor.go +++ b/telemetry/sdklog/batch_processor.go @@ -297,7 +297,7 @@ func (bsp *batchLogProcessor) enqueue(log *LogData) { if bsp.o.BlockOnQueueFull { bsp.enqueueBlockOnQueueFull(ctx, log) } else { - bsp.enqueueDrop(ctx, log) + bsp.enqueueDrop(log) } } @@ -310,7 +310,7 @@ func (bsp *batchLogProcessor) enqueueBlockOnQueueFull(ctx context.Context, log * } } -func (bsp *batchLogProcessor) enqueueDrop(ctx context.Context, log *LogData) bool { +func (bsp *batchLogProcessor) enqueueDrop(log *LogData) bool { select { case bsp.queue <- log: return true