Files
initiative/specs/007-add-knip/research.md

2.4 KiB

Research: Add Knip Unused Code Detection

Date: 2026-03-05

Decision 1: Knip Configuration Approach

Decision: Use workspace-aware knip.json at the repo root with minimal explicit configuration, relying on Knip's auto-detection for plugins and entry points.

Rationale: Knip v5 auto-detects pnpm workspaces from pnpm-workspace.yaml and enables plugins (Vite, Vitest, TypeScript, Biome) based on package.json dependencies. The project follows standard conventions, so auto-detection covers most cases. Explicit workspace entries in knip.json provide a safety net and clear documentation of scope.

Alternatives considered:

  • Zero config (no knip.json): Works but less explicit; harder for contributors to understand what's scanned.
  • Per-package configs: Unnecessary complexity; root-level workspace config covers the monorepo.

Decision 2: Quality Gate Integration

Decision: Add knip as a separate script in root package.json and chain it into the existing check script.

Rationale: The current check script is biome check . && tsc --build && vitest run. Adding knip to this chain (e.g., knip && biome check . && ...) makes it part of the pre-commit gate via Lefthook without any Lefthook config changes. Running Knip first is efficient since it's fast and catches structural issues before heavier checks.

Alternatives considered:

  • Separate Lefthook job: Adds config complexity; the existing single pnpm check job is cleaner.
  • Only standalone command (not in gate): Doesn't enforce the quality bar on every commit.

Decision 3: Handling the scripts/ Directory

Decision: Configure Knip to recognize scripts/check-layer-boundaries.mjs as an entry point so it isn't flagged as unused.

Rationale: This script is imported by Vitest tests but lives outside the standard workspace packages. Knip needs to know it's intentionally referenced. The root workspace can include it as an entry pattern.

Alternatives considered:

  • Ignoring the scripts directory entirely: Would miss actual unused scripts in the future.

Decision 4: Knip Version

Decision: Install latest Knip v5 (knip@5).

Rationale: v5 is the current stable major version with full pnpm workspace support and 138+ built-in plugins.

Alternatives considered:

  • Pinning exact version: Less flexible for patch updates; caret range (^5) is standard practice.