Configuration
This page lists all configuration file options.
File Types
JSON Schema
A $schema
field is a URL that you put at the top of your JSON file. This
allows you to get red squiggly lines inside of your IDE when you make a typo or
provide an otherwise invalid configuration option.
In JSON, use the provided JSON schema:
JSONC
In JSONC, use the provided JSONC schema:
Use JSONC if you want to use comments and/or trailing commas.
TypeScript
See dynamic configuration about dynamic and typed configuration files.
Project
entry
Array of glob patterns to find entry files. Prefix with !
for negation.
Example:
Also see configuration and entry files.
project
Array of glob patterns to find project files. Example:
Also see configuration and entry files.
workspaces
Individual workspace configurations may contain all other options listed on this page, except for the following root-only options:
exclude
/include
ignoreExportsUsedInFile
ignoreWorkspaces
workspaces
Workspaces can’t be nested in a Knip configuration, but they can be nested in a monorepo folder structure.
Also see Monorepos and workspaces.
paths
Tools like TypeScript, webpack and Babel support import aliases in various ways.
Knip automatically includes compilerOptions.paths
from the TypeScript
configuration, but does not automatically use other types of import aliases.
They can be configured manually:
Each workspace can have its own paths
configured. Knip paths
follow the
TypeScript semantics:
- Path values are an array of relative paths.
- Paths without an
*
are exact matches.
Plugins
There are a few options to modify the behavior of a plugin:
- Override a plugin’s
config
orentry
location - Force-enable a plugin by setting its value to
true
- Disable a plugin by setting its value to
false
It should be rarely necessary to override the entry
patterns, since plugins
also read custom entry file patterns from the tooling configuration (see
Plugins → entry files).
Plugin configuration can be set on root and on a per-workspace level. If enabled
on root level, it can be disabled on workspace level by setting it to false
there, and vice versa.
Also see Plugins.
Rules & Filters
rules
See Rules & Filters.
include
See Rules & Filters.
exclude
See Rules & Filters.
Ignore Issues
ignore
Array of glob patterns to ignore issues from matching files. Example:
ignoreBinaries
Exclude binaries that are used but not provided by any dependency from the report. Value is an array of binary names or regular expressions. Example:
Actual regular expressions can be used in dynamic configurations:
ignoreDependencies
Array of package names to exclude from the report. Regular expressions allowed. Example:
Actual regular expressions can be used in dynamic configurations:
ignoreMembers
Array of class and enum members to exclude from the report. Regular expressions allowed. Example:
Actual regular expressions can be used in dynamic configurations.
ignoreWorkspaces
Array of workspaces to ignore, globs allowed. Example:
Exports
ignoreExportsUsedInFile
In files with multiple exports, some of them might be used only internally. If
these exports should not be reported, there is a ignoreExportsUsedInFile
option available. With this option enabled, when something is also no longer
used internally, it will be reported as unused.
In a more fine-grained manner, to ignore only specific issue types:
includeEntryExports
By default, Knip does not report unused exports in entry files. When a repository (or workspace) is self-contained or private, you may want to include entry files when reporting unused exports:
If enabled, Knip will report unused exports in entry source files and scripts
such as those referenced in package.json
. But not in entry and configuration
files as configured by plugins, such as next.config.js
or
src/routes/+page.svelte
.
This will also enable reporting unused members of exported classes and enums.
Set this option at root level to enable this globally, or within workspace configurations individually.
ISC License © 2024 Lars Kappert