Skip to main content

SKY-E003 · Dead code

Unused TypeScript/JavaScript file

Low

A TypeScript or JavaScript file that no other file imports and that is not an entry point, so nothing loads it. Files imported only by such unused files are reported too.

Languages
TypeScript, JavaScript
Turned on by
skylos . (every scan)
Quality gate
counted toward the gate limits (full and diff scans). Counts toward max_dead_code, which has no limit by default, so it only fails a gate where you set one.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The file still compiles and lints, so it costs review time and keeps its dependencies installed. Coding agents often create a second version of a module (legacyFormat.ts next to format.ts) and leave the old one behind.

What Skylos flags

src/legacyFormat.ts · TypeScriptReported on line 1
export function formatPriceOld(cents: number): string {  return "$" + Math.round(cents) / 100;}
src/index.ts · TypeScript
import { formatPrice } from "./format"; export function renderTotal(cents: number): string {  return `Total: ${formatPrice(cents)}`;}
src/format.ts · TypeScript
export function formatPrice(cents: number): string {  return `$${(cents / 100).toFixed(2)}`;}
package.json · JSON
{  "name": "shop-web",  "version": "1.0.0",  "main": "src/index.ts"}

What Skylos leaves alone

src/migrate.ts · TypeScript
import { db } from "./db"; await db.migrate.latest();
src/db.ts · TypeScript
export const db = { migrate: { latest: async () => undefined } };
src/index.ts · TypeScript
export { db } from "./db";
package.json · JSON
{  "name": "shop-web",  "version": "1.0.0",  "main": "src/index.ts",  "scripts": {    "migrate": "tsx src/migrate.ts"  }}

Why Skylos leaves it alone

No file imports src/migrate.ts, but the migrate script in package.json runs it by path. Skylos reads such references in configuration, templates and scripts and treats the file as used.

How Skylos decides

  1. Runs in every scan on .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts and .cts files outside excluded folders.
  2. Builds the import graph, counting re-exports and import()/require() calls, also when a comment precedes the specifier (import(/* webpackChunkName: "x" */ "./x")). A file is unused when no other file imports it, or when every file that imports it is itself unused. Files that import each other in a cycle no entry reaches are unused too, unless that region spans more than 8 files. Docusaurus @site/ and @theme/ and SvelteKit $lib aliases resolve without a generated tsconfig; inside a Docusaurus site extensionless paths follow its webpack order (.js before .tsx). An import through a symlink reaches the file the link names. Astro pages, SvelteKit + route files, Nuxt pages, layouts and components, and Vue page and layout folders of the plugins that route them are graph roots, so what they import is used.
  3. Never reports entry points and infrastructure: files named in package.json (main, exports, bin and similar) or by a bundler or framework convention (Next.js pages and routes, and the entry, route and config patterns of the JS/TS plugin table: SolidStart, Nuxt, Astro, Docusaurus, SvelteKit, Remix, React Router, Vike, Storybook, Cypress, Mocha and about 200 other tools, each switched on by its package; static site generators; jscodeshift transforms named by defineTest), entries in the repository's own literal Knip config, tests and stories, .d.ts files, and files under static, public or benchmark folders. When a tool config key that names entries cannot be read without running code, the files it could select are held back. A package.json target in a build folder maps back to the tsdown, tsup, Rollup or Rolldown entry that emits it.
  4. Reads the commands of package.json scripts, GitHub Actions run: steps and git hooks (husky, lefthook, simple-git-hooks) the same way the npm dependency rules do: a runtime's script and --require/--import preloads, -c/--config files, bundler positional entries, and the literal entry/input of a webpack or Rollup build script such a command runs. A tsconfig that tsc -p, vue-tsc -p, ngc -p or tsc --build compiles names its files as entries, and its include set too for a package with no other entry (a type-check fixture).
  5. Files under scripts and examples need evidence to be used: an import from a used file, a command that runs them, a path reference, a shebang, or their file name written in another repository file.
  6. Files in __testfixtures__/__fixtures__ folders are test data read as text and never reported. A module published only through a types-only wildcard export ("./*": {"types": ...}) is kept when it declares exported types.
  7. Before reporting, looks for the file's path in configuration files, HTML, package.json scripts and other languages, and treats a file loaded that way as used.
  8. Reports LOW on line 1, in the unused_files list of the JSON output. An unused file is one finding: unused-symbol, export, unlisted-dependency (SKY-Q408) and unresolved-import (SKY-Q414) findings inside it are listed under its folded_findings instead of on their own.

How to fix it

Delete the file once you have checked that nothing loads it in a way Skylos cannot see, such as a dynamic import() with a computed path.

When it can be wrong

  • A file loaded only through a dynamic import() with a computed path, a plugin system or another repository is reported.
  • A library file meant for consumers but not listed in package.json exports is reported; list it there.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put the marker at the end of the file's first line.

    TypeScript
    export function formatPriceOld(cents: number): string { // skylos: ignore[SKY-E003]
  • [tool.skylos] ignore = ["SKY-E003"] turns the rule off for the project. A file that other packages load can instead be listed as an entry in package.json (exports, main or bin).

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.