Skip to content

Allow validate() to infer description from function name #6

@masonmark

Description

@masonmark

Per verbal request from @protiev — when using .validate() with a well-named function, having to also provide a string description is redundant:

// Redundant — the function name already says what it does
script.add('git push').validate(gitIsAvailable, 'git is available');

// Desired — just pass the function, let the name speak for itself
script.add('git push').validate(gitIsAvailable);

Currently, when no description is provided, the output falls back to the generic text "Step validation". Instead, it should use the function's .name property, formatted for display (e.g. gitIsAvailable"gitIsAvailable").

Current signature

validate(
  check: () => boolean | string | Promise<boolean | string>,
  description?: string,
): this

The signature already supports omitting the description — the improvement is purely in how the fallback is displayed.

Proposed behavior

When description is omitted (or undefined):

  1. Use check.name if available (named function or named function expression)
  2. Fall back to "Step validation" only for anonymous/arrow functions where .name is empty

In Script.ts line 707, change:

const desc = step.options.validateDescription || 'Step validation';

to something like:

const desc = step.options.validateDescription
  || step.options.validateFn?.name
  || 'Step validation';

This makes the common case of passing a named validation function a one-argument call with useful output.

(Filed from Claude Code VSCode extension, model: Claude Opus 4.6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions