monorepo-template / quality
louisbrulenaudet/monorepo-template/.cursor/rules/quality/knip.mdc
Knip dead-code policy: why each override in root knip.jsonc exists, and how to keep both the default and production passes green.
Cursor rule19 starsChanged 6 days ago
- Reads credentials
What's in it
- Knip Configuration & Policy
- Root options
- Workspace overrides
- apps/front-
- apps/!(front-)
- Root (".")
- packages/vitest-config
- Policy
---
description: "Knip dead-code policy: why each override in root knip.jsonc exists, and how to keep both the default and production passes green."
alwaysApply: false
globs: knip.jsonc
---
# Knip Configuration & Policy
Root `knip.jsonc` is intentionally comment-free; every override's rationale lives here. Official docs: [configuration](https://knip.dev/reference/configuration), [production mode](https://knip.dev/features/production-mode), [configuring project files](https://knip.dev/guides/configuring-project-files).
## Root options
| Option | Why |
|--------|-----|
| `includeEntryExports: true` | Every workspace is `"private": true`, so entry/barrel files (`packages/*/src/index.ts`) get full unused-export auditing |
| `treatConfigHintsAsErrors: true` | Stale or redundant overrides (e.g. an `entry` a plugin now provides) fail the gate instead of rotting silently |
## Workspace overrides
### apps/front-*
- `ignoreDependencies` entries are suffixed `!` = **production mode only**:
- `@tanstack/*-devtools` - imported by `AppDevtools.tsx`, which is lazy-loaded behind `import.meta.env.DEV`; production builds never statically include them, but Knip's static graph cannot evaluate that conditional.
- `tailwindcss` - build-time dependency consumed through `@tailwindcss/vite` + the `@import "tailwindcss"` in `src/index.css`.
- `project` replicates the default glob plus production-only negations (`"!tests/helpers/**!"`, `"!vitest.setup.ts!"`) so test infrastructure - helpers like `tests/helpers/session-storage-mock.ts` and the `setupFiles` entry `vitest.setup.ts` - is never flagged as unused shipped code. Do not use `ignore` or `ignoreFiles` for this - `ignoreFiles` rejects the production-only `!` suffix here.
### apps/!(front-*)
- Every app that is not the SPA - `worker-*` today, `queue-*` / `webhook-*` / `mcp-*` when they land. A negation rather than a list of prefixes because `treatConfigHintsAsErrors: true` makes a workspace key matching nothing a hard error, so unused prefixes cannot be declared ahead of time.
- `ignoreDependencies: ["cloudflare"]` - `import ... from "cloudflare:workers"` in Workers-pool tests is a runtime protocol specifier resolving to no npm package.
### Root (`"."`)
- `project` excludes `.agents/**`, which holds vendored agent skills installed from `skills-lock.json` - their bundled scripts are not project code, and the Vitest plugin's default test glob would otherwise make their `*.test.cjs` files entries. The negation is needed in both forms: `"!.agents/**"` for the default pass and `"!.agents/**!"` for production mode, which reads only `!`-suffixed patterns. Restating the default glob must keep `css`, which the Tailwind plugin compiles, or `treatConfigHintsAsErrors` fails on a compiled-extension hint. Do not use `ignore` or `ignoreFiles` instead - both still analyze the files. Same boundary as `ignorePatterns` in `.oxlintrc.json`.
- `ignoreDependencies: ["@vitest/ui"]` (both passes) - launched as a CLI by the Vite DevTools Vitest dock, never imported, and the root has no Vitest config for Knip's vitest plugin to bind to. It lives at the workspace root rather than in `apps/front-app` because `@vitejs/devtools-vitest` probes for it with `isPackageExists("@vitest/ui", { paths: [workspaceRoot] })` while `@vitejs/devtools` core probes integrations against the app `cwd`; under pnpm's isolated layout an app-local install is invisible to that probe and the dock fails with `VTDT0001`. Do not move it back.
### packages/vitest-config
- `ignoreFiles: ["src/package-root.d.ts"]` - sidecar type declarations for `package-root.js`; unlike `ignore`, the file stays analyzed for exports/types/unresolved issues.
- Root `ignoreWorkspaces: ["packages/vitest-config!"]` (production mode only) - build/test-time config helper, never part of a shipped bundle.
## Policy
- Both passes must stay green: `pnpm knip` (default) and `pnpm knip:production` (`--production --strict`: shipped-code-only + workspace isolation). Both run inside `pnpm run ci`.
- Never blanket-`ignore`. Prefer scoped patterns (`ignoreIssues`, `ignoreFiles`, production-only suffixes like `"dep!"` / `"!pattern!"`).
- Exports kept solely for unit tests carry an explicit JSDoc `@internal` tag - production mode ignores tagged exports, so tests never mask dead shipped API - the tag alone is the reason, don't add prose above it restating "extracted/exported for tests". Such an export is the last resort, not the default: the authoring gate in [testing.mdc](testing.mdc) requires testing through the real entry first.
- Auto-fix unused dependencies and pnpm catalog entries with `knip --fix --fix-type dependencies,catalog`; agent-readable output via `pnpm knip:agent` (`--reporter symbols`).
- Generated files (`routeTree.gen.ts`, `worker-configuration.d.ts`) resolve cleanly today; if they ever false-positive, use `ignoreIssues` scoped patterns, not blanket `ignore`.
More agent context in louisbrulenaudet/monorepo-template
68 other files this repository gives its agents, the first 60 shown.
CLAUDE.md
Cursor rule
- .cursor/rules/backend/hono-gateway.mdc
- .cursor/rules/backend/ports.mdc
- .cursor/rules/backend/workers-cache.mdc
- .cursor/rules/backend/workers-config.mdc
- .cursor/rules/contracts/contracts.mdc
- .cursor/rules/contracts/type-inference.mdc
- .cursor/rules/core/boundaries.mdc
- .cursor/rules/core/guardrails.mdc
- .cursor/rules/core/turborepo.mdc
- .cursor/rules/core/worktrees.mdc
- .cursor/rules/frontend/frontend-architecture.mdc
- .cursor/rules/frontend/react-doctor.mdc
- .cursor/rules/frontend/react.mdc
- .cursor/rules/frontend/tailwind.mdc
- .cursor/rules/frontend/tanstack-query.mdc
- .cursor/rules/frontend/tanstack-router.mdc
- .cursor/rules/frontend/vite-config.mdc
- .cursor/rules/ops/cd.mdc
- .cursor/rules/ops/ci.mdc
- .cursor/rules/ops/previews.mdc
- .cursor/rules/ops/release.mdc
- .cursor/rules/quality/code-style.mdc
- .cursor/rules/quality/comments.mdc
- .cursor/rules/quality/markdown-style.mdc
- .cursor/rules/quality/naming.mdc
- .cursor/rules/quality/testing.mdc
- .cursor/rules/quality/typescript-config.mdc
- .cursor/rules/quality/vitest-config.mdc
- .cursor/rules/tests/front-react.mdc
- .cursor/rules/tests/hono-workers.mdc
- .cursor/rules/tests/vitest.mdc
Skill
- front-vitest.agents/skills/front-vitest/SKILL.md
- git-commit.agents/skills/git-commit/SKILL.md
- hono.agents/skills/hono/SKILL.md
- monorepo-agent-setup.agents/skills/monorepo-agent-setup/SKILL.md
- playwright-cli.agents/skills/playwright-cli/SKILL.md
- pnpm.agents/skills/pnpm/SKILL.md
- privileged-legal-data.agents/skills/privileged-legal-data/SKILL.md
- react-doctor.agents/skills/react-doctor/SKILL.md
- review-architecture.agents/skills/review-architecture/SKILL.md
- review-ci.agents/skills/review-ci/SKILL.md
- review-code-quality.agents/skills/review-code-quality/SKILL.md
- review-configuration.agents/skills/review-configuration/SKILL.md
- review-performance.agents/skills/review-performance/SKILL.md
- review-security.agents/skills/review-security/SKILL.md
- review-seo.agents/skills/review-seo/SKILL.md
- review.agents/skills/review/SKILL.md
- review-stack.agents/skills/review-stack/SKILL.md
- review-tests.agents/skills/review-tests/SKILL.md
- review-ui.agents/skills/review-ui/SKILL.md
- run-app.agents/skills/run-app/SKILL.md
- security-audit.agents/skills/security-audit/SKILL.md
- skills-update.agents/skills/skills-update/SKILL.md
- tanstack-config.agents/skills/tanstack-config/SKILL.md
- tanstack-devtools.agents/skills/tanstack-devtools/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

