SKY-E003 · Dead code
Unused TypeScript/JavaScript file
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
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
export function formatPriceOld(cents: number): string { return "$" + Math.round(cents) / 100;}import { formatPrice } from "./format"; export function renderTotal(cents: number): string { return `Total: ${formatPrice(cents)}`;}export function formatPrice(cents: number): string { return `$${(cents / 100).toFixed(2)}`;}{ "name": "shop-web", "version": "1.0.0", "main": "src/index.ts"}What Skylos leaves alone
import { db } from "./db"; await db.migrate.latest();export const db = { migrate: { latest: async () => undefined } };export { db } from "./db";{ "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
- Runs in every scan on
.ts,.tsx,.js,.jsx,.mjs,.cjs,.mtsand.ctsfiles outside excluded folders. - 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$libaliases resolve without a generated tsconfig; inside a Docusaurus site extensionless paths follow its webpack order (.jsbefore.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. - Never reports entry points and infrastructure: files named in
package.json(main,exports,binand 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 bydefineTest), entries in the repository's own literal Knip config, tests and stories,.d.tsfiles, and files understatic,publicor benchmark folders. When a tool config key that names entries cannot be read without running code, the files it could select are held back. Apackage.jsontarget in a build folder maps back to the tsdown, tsup, Rollup or Rolldown entry that emits it. - Reads the commands of
package.jsonscripts, GitHub Actionsrun:steps and git hooks (husky, lefthook, simple-git-hooks) the same way the npm dependency rules do: a runtime's script and--require/--importpreloads,-c/--configfiles, bundler positional entries, and the literalentry/inputof a webpack or Rollup build script such a command runs. Atsconfigthattsc -p,vue-tsc -p,ngc -portsc --buildcompiles names itsfilesas entries, and itsincludeset too for a package with no other entry (a type-check fixture). - Files under
scriptsandexamplesneed 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. - 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. - Before reporting, looks for the file's path in configuration files, HTML,
package.jsonscripts and other languages, and treats a file loaded that way as used. - Reports LOW on line 1, in the
unused_fileslist 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 itsfolded_findingsinstead 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.jsonexportsis 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 inpackage.json(exports,mainorbin).