HookTask class abstract

An abstract class representing a task to be executed as part of a Git hook.

Subclasses must implement the run method to define the task's behavior.

Tasks can include or exclude specific files based on patterns, and can have sub-tasks that are executed conditionally based on the files being processed.

Usage

To create a custom hook task, extend this class and implement the run method:

class MyCustomTask extends HookTask {
  MyCustomTask() : super(include: [Glob('**.dart')]);

  @override
  FutureOr<int> run(
    List<String> filePaths, {
    required void Function(String? string) print,
    required void Function(HookTask, int) completeTask,
    required void Function(HookTask) startTask,
  }) async {
    // Task implementation here
    return 0; // Return 0 on success, non-zero on failure
  }
}

To use the custom task in a hook:

Hook main() {
  return PreCommitHook(
    tasks: [MyCustomTask()],
  );
}
Implementers

Constructors

HookTask({required List<Pattern> include, List<Pattern> exclude = const [], String? workingDirectory})
HookTask.always({List<Pattern> exclude = const [], String? workingDirectory})
Creates a task that always runs, even if no files are being processed or if the files do not match the task's patterns.

Properties

exclude → List<Pattern>
The list of patterns to exclude files.
final
hashCode → int
The hash code for this object.
no setterinherited
id → String
The unique identifier for the task.
final
include → List<Pattern>
The list of patterns to include files.
final
name → String?
The name of the task.
no setter
patternName → String
Gets the pattern name for the task.
no setter
resolvedName → String
Gets the resolved name for the task.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
shouldAlwaysRun → bool
no setter
workingDirectory → String?
final

Methods

filterFiles(Iterable<String> filePaths) → List<String>
Filters the given file paths based on the include and exclude patterns.
label(Iterable<String> filePaths) → TaskLabel
Creates a label for the task with the given file paths.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolve(List<String> filePaths, int index) → ResolvedHookTask
Resolves the task with the given file paths and index.
resolveSubTasks(Iterable<String> filePaths) → List<HookTask>
Resolves the list of sub-tasks for the given file paths.
run(List<String> filePaths, {required void print(String? string), required void completeTask(HookTask, int), required void startTask(HookTask), required String? workingDirectory}) → FutureOr<int>
Runs the task with the given file paths.
subTasks(Iterable<String> filePaths) → List<HookTask>
Gets the list of sub-tasks for the given file paths.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited