CLI Arguments
General
Section titled “General”--help
Section titled “--help”Shortcut: -h
Prints a summary of this page.
--version
Section titled “--version”Shortcut: -V
Print the version number.
--no-progress
Section titled “--no-progress”Shortcut: -n
Don’t show dynamic progress updates. Progress is automatically disabled in CI environments.
--config [file]
Section titled “--config [file]”Use an alternative path for the configuration file. Default locations:
knip.jsonknip.jsonc.knip.json.knip.jsoncknip.jsknip.tspackage.json#knip
Shortcut: -c
--use-tsconfig-files
Section titled “--use-tsconfig-files”Use tsconfig.json to define project files (override project patterns).
--tsConfig [file]
Section titled “--tsConfig [file]”Shortcut: -t
Use an alternative path for the TypeScript configuration file.
Using -t jsconfig.json is also supported.
Default location: tsconfig.json
knip-bun
Section titled “knip-bun”Run Knip using the Bun runtime (instead of Node.js + jiti).
knip-bunThis is equal to bunx --bun knip
Requires Bun to be installed. Also see known issues for the type of issues this might help with.
NO_COLOR
Section titled “NO_COLOR”The built-in reporters use the NO_COLOR friendly picocolors:
NO_COLOR=1 knip--cache
Section titled “--cache”Enable caching.
Consecutive runs are 10-40% faster as the results of file analysis (AST traversal) are cached. Conservative. Cache strategy based on file meta data (modification time + file size).
--cache-location
Section titled “--cache-location”Provide alternative cache location.
Default location: ./node_modules/.cache/knip
--include-entry-exports
Section titled “--include-entry-exports”When a repository is self-contained or private, you may want to include entry files when reporting unused exports:
knip --include-entry-exportsAlso see includeEntryExports.
--no-gitignore
Section titled “--no-gitignore”Ignore .gitignore files.
--production
Section titled “--production”Lint only production source files. This excludes:
- entry files defined by plugins:
- test files
- configuration files
- Storybook stories
devDependenciesfrompackage.json
Read more at Production Mode.
--strict
Section titled “--strict”Isolate workspaces and consider only direct dependencies. Implies production mode.
Read more at Production Mode.
--watch
Section titled “--watch”Watch current directory, and update reported issues when a file is modified, added or deleted.
Watch mode focuses on imports and exports in source files. During watch mode,
changes in package.json or node_modules may not cause an updated report.
--workspace [filter]
Section titled “--workspace [filter]”Select one or multiple workspaces (including its ancestor and dependent workspaces). The default behavior is to lint all configured workspaces.
Shortcut: -W
See filter workspaces for more details and examples.
--directory [dir]
Section titled “--directory [dir]”Default: cwd (current directory)
Run the process from a different directory.
--exclude
Section titled “--exclude”Exclude provided issue types from report. Can be comma-separated or repeated.
Example:
knip --exclude enumMembers--include
Section titled “--include”Report only provided issue types. Can be comma-separated or repeated.
Example:
knip --include files,dependenciesknip --include files --include dependenciesAvailable issue types when filtering output using --include or
--exclude:
filesdependenciesunlistedunresolvedexportsnsExportstypesnsTypesenumMembersnamespaceMembersduplicatescatalog
--dependencies
Section titled “--dependencies”Shortcut to include all types of dependency issues:
--include dependencies,unlisted,binaries,unresolved,catalog--exports
Section titled “--exports”Shortcut to include all types of export issues:
--include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates--files
Section titled “--files”Shortcut to include file issues:
--include files--tags
Section titled “--tags”Exports can be tagged with known or arbitrary JSDoc/TSDoc tags:
/** * Description of my exported value * * @type number * @internal Important matters * @lintignore */export const myExport = 1;And then include (+) or exclude (-) these tagged exports from the report
like so:
knip --tags=-lintignore,-internalknip --tags=+customThis way, you can either focus on or ignore specific tagged exports with tags you define yourself. This also works for individual enum and namespace members.
The default directive is + (include) and the @ prefix is ignored, so the
notation below is valid and will report only exports tagged @lintignore or
@internal:
knip --tags @lintignore --tags @internalRead more at auto-fix.
--fix-type
Section titled “--fix-type”Fix only issues of type, can be comma-separated or repeated.
More info about fixable types at issue types
--allow-remove-files
Section titled “--allow-remove-files”Allow Knip to remove files (with --fix).
--format
Section titled “--format”Format modified files after --fix using the local formatter.
Output
Section titled “Output”--preprocessor [preprocessor]
Section titled “--preprocessor [preprocessor]”Preprocess the results before providing it to the reporter(s).
Can be repeated. Examples:
knip --preprocessor ./my-preprocessor.tsknip --preprocessor preprocessor-packageAlso see Reporters & Preprocessors.
--preprocessor-options [json]
Section titled “--preprocessor-options [json]”Pass extra options to the preprocessor as JSON string.
knip --preprocessor ./preproc.ts --preprocessor-options '{"key":"value"}'--reporter [reporter]
Section titled “--reporter [reporter]”Available reporters:
symbols(default)compactcodeownersjsoncodeclimatemarkdowndisclosuregithub-actions
Can be repeated. Example:
knip --reporter compactAlso see Reporters & Preprocessors.
--reporter-options [json]
Section titled “--reporter-options [json]”Pass extra options to the reporter (as JSON string):
Example:
knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'--no-config-hints
Section titled “--no-config-hints”Suppress configuration hints.
--treat-config-hints-as-errors
Section titled “--treat-config-hints-as-errors”Exit with non-zero exit code (1) if there are any configuration hints.
--max-issues
Section titled “--max-issues”Maximum number of issues before non-zero exit code. Default: 0
--max-show-issues
Section titled “--max-show-issues”Maximum number of issues per type to display (does not affect exit code).
--no-exit-code
Section titled “--no-exit-code”Always exit with code zero (0), even when there are lint issues.
The default exit codes:
| Code | Description |
|---|---|
0 | Knip ran successfully, no lint issues |
1 | Knip ran successfully, but there is at least one lint issue |
2 | Knip did not run successfully due to bad input or internal error |
Troubleshooting
Section titled “Troubleshooting”--debug
Section titled “--debug”Shortcut: -d
Show debug output.
--memory
Section titled “--memory”knip --memory
(results)
# heapUsed heapTotal freemem-- -------- --------- ------- 0 42.09 70.91 2251.00 1 927.04 1042.58 1166.47 2 973.29 1047.33 1160.92 3 971.54 1079.83 1121.66 4 997.80 1080.33 1120.34 5 1001.88 1098.08 1100.72 6 1038.69 1116.58 1100.72 7 1082.12 1166.33 1100.72 8 1145.46 1224.50 1100.72 9 1115.82 1240.25 1100.7210 1182.35 1249.75 973.0511 637.32 1029.17 943.6312 674.30 1029.33 943.3913 682.24 1029.33 941.6314 707.70 1029.33 937.48
Total running time: 4.3s--memory-realtime
Section titled “--memory-realtime”Use this if Knip crashes to still see memory usage info over time:
knip --memory-realtime
# heapUsed heapTotal freemem- -------- --------- -------0 42.09 70.91 2251.001 927.04 1042.58 1166.47...mem info keeps being logged...
(results)--performance
Section titled “--performance”Use this flag to get the count and execution time of potentially expensive functions in a table. Example:
$ knip --performance
(results)
Name size min max median sum----------------------------- ---- -------- -------- -------- --------findReferences 648 84.98 7698.61 96.41 70941.70createProgram 2 6295.84 7064.68 6680.26 13360.52glob 6 0.05 995.78 513.82 3150.87findESLintDependencies 2 0.01 74.41 37.21 74.41findGithubActionsDependencies 6 0.16 12.71 0.65 23.45findBabelDependencies 2 0.00 38.75 19.37 38.75...
Total running time: 5sname: the internal Knip function namesize: number of function invocationsmin: the fastest invocationmax: the slowest invocationmedian: the median invocationsumthe accumulated time of all invocations
This is not yet available in Bun, since it does not support
performance.timerify (GitHub issue).
--performance-fn
Section titled “--performance-fn”Limit the output of --performance to a single function to minimize the
overhead of the timerify Node.js built-in and focus on that function alone:
$ knip --performance-fn resolveSync
(results)
Name size min max median sum----------- ----- ---- ---- ------ ------resolveSync 66176 0.00 5.69 0.00 204.85
Total running time: 12.9s--trace
Section titled “--trace”Trace exports to see where they are imported.
Also see Trace.
--trace-dependency [name]
Section titled “--trace-dependency [name]”Trace package or binary name to see where it’s referenced. Implies —trace.
--trace-export [name]
Section titled “--trace-export [name]”Trace export name to see where it’s imported. Implies —trace.
--trace-file [path]
Section titled “--trace-file [path]”Trace file to see where its exports are imported. Implies —trace.
ISC License © 2024 Lars Kappert