Configuration File
This page lists all configuration options (in alphabetical order).
Also see dynamic configurations in case you need more flexibility to configure Knip.
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, you can use the provided JSON schema:
In JSONC, you can use the provided JSONC schema:
Use JSONC if you want to use comments and/or trailing commas.
Types
In TypeScript, you can use the KnipConfig
type:
entry
See configuration and entry files.
exclude
See Rules & Filters.
ignore
Array of glob patterns to ignore files. Used as ignore patterns when looking up
entry
and project
files. Example:
This does not 100% guarantee that the targeted files are not included in the
analysis, so even issues in the ignored files may still be reported. Use
--debug
for details.
ignoreBinaries
Array of binaries to exclude from the report. Regular expressions allowed. 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:
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, you don’t need to mark everything
@public
separately and when something is no longer used internally, it will
still be reported.
In a more fine-grained manner, you can also ignore only specific issue types:
ignoreWorkspaces
Array of workspaces to ignore, globs allowed. Example:
include
See Rules & Filters.
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.
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.
project
See configuration and entry files.
rules
See Rules & Filters.
workspaces
Workspaces may contain the options listed on this page, except for the following root-only options:
exclude
/include
ignoreExportsUsedInFile
ignoreWorkspaces
workspaces
Workspaces can’t be nested in configuration, but they can be nested in folder structure.
ISC License © 2024 Lars Kappert