Skip to content

Add built-in deno-check hook for type checking #4

@drernie

Description

@drernie

Summary

Add deno-check as a built-in hook to run type checking before commits, filling an obvious gap alongside deno-fmt and deno-lint.

Motivation

Current built-in hooks:

  • deno-fmt - formatting
  • deno-lint - linting
  • deno-check - missing!

Type checking is a fundamental part of TypeScript development and should be built-in.

Proposed Solution

Add deno-check built-in hook:

hooks:
  pre-commit:
    - id: type-check
      run: deno-check
      glob: "**/*.ts"
      config:
        remote: false  # Don't check remote imports (faster)
        strict: true   # Enable strict mode

Implementation

Add new built-in hook in src/executor.ts:

async function denoCheck(ctx: HookContext): Promise<HookResult> {
  const { files, rootDir, config } = ctx;
  
  if (files.length === 0) {
    return { success: true, message: "no files to check" };
  }
  
  const args = ["check"];
  
  // Add config options
  if (config.config?.remote === false) {
    args.push("--no-remote");
  }
  
  args.push(...files);
  
  const command = new Deno.Command("deno", {
    args,
    cwd: rootDir,
    stdout: "piped",
    stderr: "piped",
  });
  
  const { success, stdout, stderr } = await command.output();
  
  if (\!success) {
    const error = new TextDecoder().decode(stderr);
    const output = new TextDecoder().decode(stdout);
    return {
      success: false,
      message: error || output,
    };
  }
  
  return { success: true, message: `${files.length} file(s) type-checked` };
}

Configuration Options

  • remote: Check remote imports (default: true)
  • strict: Enable strict type checking (default: false)
  • config: Path to custom tsconfig.json

Benefits

  • ✅ Catch type errors before commit
  • ✅ Consistent with existing built-in hooks
  • ✅ Easy to implement (similar to deno-fmt/deno-lint)
  • ✅ Fast win with high value

Priority

MEDIUM - Quick win that fills an obvious gap

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions