Skip to content

vibator.knip namespace

This document is the reference of the knip subnamespace as @vibator/knip registers it onto the shared vibator object. Importing the package performs the registration; rules then reach it as vibator.knip.

The subnamespace drives Knip through its programmatic API (knip and knip/session). Knip decides whether code is unused from the whole workspace, so the namespace runs it once per configuration; callers intersect the issues with the files in scope.

Reference


Functions

DeclarationDescription
configFile(options?: KnipOptions): string | undefinedThe absolute path of the configuration file a run uses, or undefined when Knip discovers its own. Throws when a configured path names no file.
issues(options?: KnipOptions): Promise<KnipIssue[]>Analyzes the workspace and returns every issue Knip reports, flattened across Knip's buckets.
fix(options?: KnipOptions): Promise<void>Runs Knip with its fixes enabled: unused exports and types are stripped and unused dependencies removed from package.json. Knip writes the files itself.

KnipOptions

The options every call accepts.

DeclarationDescription
configPath?: stringReference to a Knip configuration file: a ./ path from the project root, an absolute path, or a package:path reference. When omitted, Knip discovers its own configuration (knip.json, knip.ts, the knip field in package.json, …).

KnipIssue

One Knip issue with its file and position.

DeclarationDescription
type: stringThe issue bucket, such as exports, files, or dependencies.
filePath: stringThe absolute path of the file the issue points at.
symbol: stringThe symbol the issue is about: an export, a dependency, a specifier.
parentSymbol?: stringThe enclosing symbol, for enum and class members.
line?: numberThe 1-based line, when Knip resolves a position.
col?: numberThe 1-based column, when Knip resolves a position.
fixable: booleanWhether Knip can remove the issue itself under a fix run.

The fixable buckets are exports, types, dependencies, and devDependencies.

Caching

One analysis runs per configuration path and is reused across calls for the duration of the run. A fix call invalidates the cache, so the next issues call reanalyzes.

Released under the MIT License.