Files
supabase/knip.jsonc
T
Alaister YoungandAlaister Young 2c76bb371b chore(studio): gate dead code with knip in CI (#49721)
Makes knip a CI gate for Studio so dead files and unused dependencies
fail the PR instead of piling up. Third PR in the stack, on top of
#49719 (dead code) and #49720 (unused deps), which get Studio to a clean
run.

**Changed:**
- knip `pnpx knip@~5.50.0` → root devDependency `knip@6.32.3`, `pnpm
knip` now runs it. The old `pnpx` form was actually broken: it resolved
knip's `typescript` peer to TS 7 and crashed with
`ts.getDefaultLibFilePath is not a function`. (6.33.0 is newer but
blocked by `minimumReleaseAge`.)
- `knip.jsonc` rewritten for v6 with a `workspaces["apps/studio"]`
block. Framework-convention files (`router.tsx`, `start.ts`,
`routes/**`, `compat/**`, `api/server.js`) are `entry` rather than
`ignore` — an ignored file's imports aren't traced, which is how
`ShellFallback.tsx` (only imported from `routes/__root.tsx`) was being
reported as dead. knip 6's Next.js plugin already covers
`instrumentation*.ts`, `proxy.ts`, `pages/**`; its tanstack-router
plugin only looks under `src/`, hence the manual entries. Narrow
`ignoreIssues` for graphql-codegen output and the `CONSTRAINT_TYPE`
enum; `ignoreDependencies` for the five implicit deps from #49720, each
with a comment; `ignoreBinaries: ["vercel"]`.
- `apps/studio/CLAUDE.md`: one bullet on the gate and where framework
files go.

**Added:**
- `.github/workflows/studio-knip.yml` — path-filtered to
`apps/studio/**` + knip/pnpm config, mirrors `studio-lint-ratchet.yml`'s
setup (no sparse checkout: knip needs every workspace's `package.json`
to resolve the graph). Runs `pnpm knip --workspace apps/studio
--reporter symbols --reporter github-actions` so findings show up as
inline PR annotations. ~5s locally.

Scope notes: the gate is Studio-only — the full-monorepo run still has
~400 dead files in `www`/`docs`/`blocks`, which is a separate effort.
`exclude: ["types", "exports"]` is kept, so unused exports aren't gated
yet, but `enumMembers`/`duplicates` are (they caught real things in
#49719).

## To test

- `pnpm knip --workspace apps/studio` exits 0 on this branch
- The `Studio Dead Code (knip)` workflow runs on this PR and is green
- Sanity-check the gate bites: add a throwaway
`apps/studio/lib/unused.ts`, run `pnpm knip --workspace apps/studio` →
reports it and exits 1


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **CI**
* Added automated dead-code and unused-dependency checks for the Studio
workspace on relevant pushes and pull requests.
* Results appear in workflow summaries and as inline pull request
annotations.

* **Maintenance**
  * Improved analysis of framework-convention files and Studio code.
* Standardized the local code-quality check and updated its
configuration support.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-08-31 11:28:55 +08:00

99 lines
4.7 KiB
JSON

{
"$schema": "https://unpkg.com/knip@6/schema-jsonc.json",
// Only files + dependencies are gated in CI for now; the export/type surface
// has too much noise to enforce yet.
"exclude": ["types", "exports"],
"ignore": [
"examples/**",
"**/*.mdx",
// skip supabase functions
"supabase/functions/**",
"**/*.test.ts",
// ignore registry blocks in ui-library
"apps/ui-library/registry/default/**",
"apps/ui-library/contentlayer.config.js",
],
"workspaces": {
"apps/studio": {
// Framework-convention files: nothing in source imports these, the
// framework/host discovers them by path. They are `entry` rather than
// `ignore` so knip still traces what they import — an ignored file's
// imports are invisible, which makes everything only it pulls in look
// dead.
"entry": [
// TanStack Start. knip's tanstack-router plugin only looks under
// `src/`, but vite.config.ts sets `srcDirectory: './'`, so the
// conventional files sit at the workspace root and have to be listed.
// routeTree.gen.ts is deliberately absent: router.tsx imports it, so
// it is traced already.
"router.tsx",
"start.ts",
// Route modules are real entry points. Keeping them as entries (not
// ignores) means components reachable only from the TanStack tree stay
// traced as the Next `pages/**` tree is dismantled.
"routes/**/*.{ts,tsx}",
// Next.js compat shims. Reached only through the `nextShims` aliases in
// vite.config.ts (`next/link` -> compat/next/link.tsx), which knip
// cannot resolve, so they need to be entries in their own right.
"compat/**/*.{ts,tsx}",
// Vercel serverless function. Vercel deploys every file under `api/`
// as a Function by convention; knip's vercel plugin only contributes
// `vercel.ts`, so this one is manual. Listing it also traces its
// runtime `import('../instrument.server.mjs')`, which is why
// instrument.server.mjs needs no entry of its own even though
// scripts/serve.js (its other importer) is ignored below.
"api/server.js",
],
"ignore": [
"public/**",
// one-off build/codegen scripts, run by hand or from package.json
"scripts/**",
// dynamically imported
"components/interfaces/ConnectSheet/content/**",
"components/interfaces/ConnectSheet/DirectConnectionExamples.tsx",
// data layer templates, copied when adding a new query/mutation
"data/__templates/**",
// evals are run from a GitHub action, not from the app
"evals/**",
],
// Narrowly scoped suppressions: one issue type, one path. Preferred over
// `ignore` (which drops the file from the project entirely, hiding the
// imports and dependencies it legitimately uses) and over
// `ignoreMembers` (which matches member names across the whole
// workspace).
"ignoreIssues": {
// graphql-codegen `client` preset output (scripts/codegen.ts,
// regenerated by `pnpm build:graphql-types`). The preset always emits
// the full set, so some of it is unreferenced by design. execute.ts in
// the same directory is hand-written and is NOT listed here.
"data/graphql/{fragment-masking,gql,graphql}.ts": ["files"],
// CONSTRAINT_TYPE mirrors the complete closed set of Postgres
// `pg_constraint.contype` values (c/f/p/u/t/x). The members we don't
// read are documentation of the valid values, not dead code. Scoped to
// this file so `enumMembers` keeps working everywhere else.
"data/database/constraints-query.ts": ["enumMembers"],
},
// `vercel` is a globally installed CLI used by the `deploy:staging` script
"ignoreBinaries": ["vercel"],
// Dependencies that are required implicitly — nothing imports them by a
// specifier knip can follow, but removing them breaks the build or the
// runtime.
"ignoreDependencies": [
// vite.config.ts resolves 'lodash-es/package.json' by string via
// createRequire to build the SSR lodash -> lodash-es alias
"lodash-es",
// named as a webpack/turbopack loader string in next.config.ts
// (`loaders: ['raw-loader']`)
"raw-loader",
// runtime hooks for @sentry/nextjs / OpenTelemetry Node
// instrumentation. Must be direct deps under pnpm's strict isolation
// (#35030).
"import-in-the-middle",
"require-in-the-middle",
// deliberate dependency-resolution pin (#45876), never imported
"@babel/core",
],
},
},
}