@knip/mcp 0.0.20 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/package.json +2 -2
  2. package/src/docs/docs/blog/brief-history.md +30 -0
  3. package/src/docs/docs/blog/for-editors-and-agents.md +131 -0
  4. package/src/docs/docs/blog/knip-v3.mdx +88 -0
  5. package/src/docs/docs/blog/knip-v4.mdx +149 -0
  6. package/src/docs/docs/blog/knip-v5.mdx +190 -0
  7. package/src/docs/docs/blog/migration-to-v1.md +65 -0
  8. package/src/docs/docs/blog/release-notes-v2.md +46 -0
  9. package/src/docs/docs/blog/slim-down-to-speed-up.md +269 -0
  10. package/src/docs/docs/blog/state-of-knip.md +191 -0
  11. package/src/docs/docs/blog/two-years.mdx +107 -0
  12. package/src/docs/docs/explanations/comparison-and-migration.md +133 -0
  13. package/src/docs/docs/explanations/entry-files.md +70 -0
  14. package/src/docs/docs/explanations/plugins.md +347 -0
  15. package/src/docs/docs/explanations/why-use-knip.md +128 -0
  16. package/src/docs/docs/features/auto-fix.mdx +348 -0
  17. package/src/docs/docs/features/compilers.md +172 -0
  18. package/src/docs/docs/features/integrated-monorepos.md +61 -0
  19. package/src/docs/docs/features/monorepos-and-workspaces.md +149 -0
  20. package/src/docs/docs/features/production-mode.md +95 -0
  21. package/src/docs/docs/features/reporters.md +304 -0
  22. package/src/docs/docs/features/rules-and-filters.md +102 -0
  23. package/src/docs/docs/features/script-parser.md +156 -0
  24. package/src/docs/docs/features/source-mapping.md +100 -0
  25. package/src/docs/docs/guides/configuring-project-files.md +205 -0
  26. package/src/docs/docs/guides/contributing.md +24 -0
  27. package/src/docs/docs/guides/handling-issues.mdx +708 -0
  28. package/src/docs/docs/guides/issue-reproduction.md +103 -0
  29. package/src/docs/docs/guides/namespace-imports.md +125 -0
  30. package/src/docs/docs/guides/performance.md +108 -0
  31. package/src/docs/docs/guides/troubleshooting.md +133 -0
  32. package/src/docs/docs/guides/using-knip-in-ci.md +50 -0
  33. package/src/docs/docs/guides/working-with-commonjs.md +72 -0
  34. package/src/docs/docs/index.mdx +160 -0
  35. package/src/docs/docs/overview/configuration.md +104 -0
  36. package/src/docs/docs/overview/features.md +66 -0
  37. package/src/docs/docs/overview/getting-started.mdx +205 -0
  38. package/src/docs/docs/overview/screenshots-videos.md +42 -0
  39. package/src/docs/docs/playground.mdx +38 -0
  40. package/src/docs/docs/reference/cli.md +511 -0
  41. package/src/docs/docs/reference/configuration-hints.md +146 -0
  42. package/src/docs/docs/reference/configuration.md +430 -0
  43. package/src/docs/docs/reference/dynamic-configuration.mdx +72 -0
  44. package/src/docs/docs/reference/faq.md +493 -0
  45. package/src/docs/docs/reference/integrations.md +105 -0
  46. package/src/docs/docs/reference/issue-types.md +45 -0
  47. package/src/docs/docs/reference/jsdoc-tsdoc-tags.md +133 -0
  48. package/src/docs/docs/reference/known-issues.md +86 -0
  49. package/src/docs/docs/reference/plugins/.gitkeep +0 -0
  50. package/src/docs/docs/reference/plugins.md +146 -0
  51. package/src/docs/docs/reference/related-tooling.md +46 -0
  52. package/src/docs/docs/sponsors.mdx +64 -0
  53. package/src/docs/docs/typescript/unused-dependencies.md +86 -0
  54. package/src/docs/docs/typescript/unused-exports.md +87 -0
  55. package/src/docs/docs/writing-a-plugin/argument-parsing.md +202 -0
  56. package/src/docs/docs/writing-a-plugin/index.md +392 -0
  57. package/src/docs/docs/writing-a-plugin/inputs.md +162 -0
@@ -0,0 +1,493 @@
1
+ ---
2
+ title: FAQ
3
+ date: 2024-08-20
4
+ ---
5
+
6
+ ## Introduction
7
+
8
+ Knip finds and fixes unused dependencies, exports and files. As a "kitchen sink"
9
+ in the npm ecosystem, it creates comprehensive module and dependency graphs of
10
+ your project.
11
+
12
+ :::note[Rationale]
13
+
14
+ The JavaScript/TypeScript ecosystem has a vast amount of frameworks and tools.
15
+ Additionally, file locations, configuration semantics, command-line arguments
16
+ and so on vary wildly. Files and dependencies are referenced in many ways. Knip
17
+ tries harder than you think to cover it all.
18
+
19
+ :::
20
+
21
+ This FAQ is an attempt to provide some perspective on a few design decisions and
22
+ why certain things work the way they do. Here and there it's intentionally a bit
23
+ more in-depth than the rest of the docs.
24
+
25
+ ## Why should I even bother to do all this?
26
+
27
+ Because the payoff is huge. While it might take a bit of effort to configure
28
+ Knip correctly initially, a clean module graph gives you absolute confidence in
29
+ your codebase. You can delete dead code, remove unused dependencies, and
30
+ refactor with certainty. It prevents the slow accumulation of technical debt and
31
+ keeps your project lean and fast. Once configured, Knip runs quickly in CI and
32
+ keeps your codebase pristine automatically.
33
+
34
+ :::tip
35
+
36
+ Try the [Knip MCP Server][1] or the [Knip Editor Extension][2]. Let your coding
37
+ agent use the built-in MCP Server and create a custom `knip.json` for you, so
38
+ you don't have to.
39
+
40
+ :::
41
+
42
+ ## Common Pitfalls
43
+
44
+ ### Why shouldn't I ignore or disable configuration hints?
45
+
46
+ Configuration hints are critical for building a healthy and accurate module
47
+ graph. They usually indicate that Knip cannot resolve a dependency, plugin, or
48
+ entry file. If you ignore or disable these hints, Knip's understanding of your
49
+ project will be incomplete, which inevitably leads to false positives (reporting
50
+ used code as unused). Always address configuration hints first before looking at
51
+ other reported issues.
52
+
53
+ ### Why is it a bad idea to use `ignore` patterns like I do in ESLint?
54
+
55
+ Knip is not a regular file-based linter like ESLint. It works by analyzing the
56
+ entire interconnected module graph of your project. Using `ignore` patterns does
57
+ not exclude files from the analysis, it only suppresses the reporting of issues
58
+ in those files. This hides real issues and creates blind spots. Instead of
59
+ ignoring files, ensure your entry points and plugins are configured correctly,
60
+ and use `project` patterns to define the boundaries of your codebase. Read more:
61
+ [Configuring Project Files][3].
62
+
63
+ If you have specific exports (such as types) that are only used within the file
64
+ they are defined, use the [ignoreExportsUsedInFile][4] configuration option
65
+ rather than ignoring the file entirely.
66
+
67
+ ### How should I exclude tests and development tools from the analysis?
68
+
69
+ A common mistake is trying to exclude test files, storybooks, or development
70
+ tools using `project` or `ignore` patterns. The correct approach is to use
71
+ [production mode][5]. This mode is specifically designed to strictly analyze
72
+ only your production source code and `dependencies`, automatically excluding
73
+ tests and `devDependencies` without requiring complex ignore rules.
74
+
75
+ ### Why shouldn't I run `knip --fix` immediately?
76
+
77
+ Running `knip --fix` before your configuration is fully settled is dangerous. If
78
+ your configuration is missing entry points or has unresolved hints, Knip might
79
+ think perfectly valid, actively used code is unused. Auto-fixing in this state
80
+ can lead to deleting code that your application relies on. Always verify the
81
+ reported issues manually and ensure your configuration is solid before using the
82
+ `--fix` flag.
83
+
84
+ ## Comparison
85
+
86
+ ### Why isn't Knip an ESLint plugin?
87
+
88
+ Linters like ESLint analyze files separately, while Knip lints projects as a
89
+ whole.
90
+
91
+ Knip requires full module and dependency graphs to find clutter across the
92
+ project. Creating these comprehensive graphs is not a trivial task and it seems
93
+ no such tool exists today, even more so when it comes to monorepos.
94
+
95
+ File-oriented linters like ESLint are complementary to Knip.
96
+
97
+ ### Isn't tree-shaking enough?
98
+
99
+ In short: no. They share an important goal: improve UX by removing unused code.
100
+ But tree-shaking and Knip are different and complementary tools.
101
+
102
+ Tree-shaking is a build or compile-time activity to reduce production bundle
103
+ size. It typically operates on bundled production code, which might include
104
+ external/third-party code. A build time optimization and "out of your hands".
105
+
106
+ On the other hand, Knip is a project linter that should be part of the
107
+ development and QA phase. It lints, reports and fixes only your own source code.
108
+ Moreover, in contrast with other linters, focuses on inter-file dependencies, so
109
+ dead code within a file may not be caught by Knip.
110
+
111
+ Issues reported by the linter are for you to handle and review.
112
+
113
+ Besides those differences, Knip has a broader scope:
114
+
115
+ - Improve DX (see [less is more][6]).
116
+ - Unless using [production mode][5], also lint all source code like tests,
117
+ scripts and Storybook stories.
118
+ - Handle more [types of issues][7] (such as unlisted dependencies).
119
+
120
+ ## Synergy
121
+
122
+ ### Why does Knip have plugins?
123
+
124
+ Plugins are an essential part of Knip. They prevent you from a lot of
125
+ configuration out of the box, by adding entry files as accurately as possible
126
+ and only for the tools actually installed. Yet the real magic is in their custom
127
+ parsers for configuration files and command-line argument definitions.
128
+
129
+ For instance, Vitest has the `environment` configuration option. The Vitest
130
+ plugin knows `"node"` is the default value for `environment` which does not
131
+ require an extra package, but will translate `"edge-runtime"` to the
132
+ `@edge-runtime/vm` package. This allows Knip to report it if this package is not
133
+ listed in `package.json`, or when it is no longer used after changes in the
134
+ Vitest configuration.
135
+
136
+ Configuration files may also contain references to entry files. For instance,
137
+ Jest has `setupFilesAfterEnv: "<rootDir>/jest.setup.js"` or a reference may
138
+ point to a file in another workspace in the same monorepo, e.g.
139
+ `setupFiles: ['@org/shared/jest-setup.ts']`. Those entry files may also contain
140
+ imports of internal modules or external dependencies, and so on.
141
+
142
+ ### Why is Knip so heavily engineered?
143
+
144
+ Even though a modular approach has its merits, for Knip it makes sense to have
145
+ all the pieces in a single tool.
146
+
147
+ Building up the module and dependency graphs requires non-standard module
148
+ resolution and not only static but also dynamic analysis (i.e. actually load and
149
+ execute modules), such as for parsers of plugins to receive the exported value
150
+ of dynamic tooling configuration files. Additionally, [exports consumed by
151
+ external libraries][8] require type information, as supported by the TypeScript
152
+ backend. Last but not least, shell script parsing is required to find the right
153
+ entry files, configuration files and dependencies accurately.
154
+
155
+ The rippling effect of plugins and recursively adding entry files and
156
+ dependencies to build up the graphs is also exactly what's meant by
157
+ ["comprehensive" here][9].
158
+
159
+ ## Building the graphs
160
+
161
+ ### Where does Knip look for entry files?
162
+
163
+ - In default locations such as `index.js` and `src/index.ts`
164
+ - In `main`, `bin` and `exports` fields in `package.json`
165
+ - In the entry files as configured by enabled plugins
166
+ - In `config` files as configured and parsed by enabled plugins
167
+ - The `config` files themselves are entry files
168
+ - In dynamic imports (i.e. `require()` and `import()` calls)
169
+ - In `require.resolve('./entry.js')`
170
+ - In `import.meta.resolve('./entry.mjs')`
171
+ - Through scripts inside template strings in source files such as:
172
+
173
+ ```ts
174
+ await $({ stdio: 'inherit' })`c8 node hydrate.js`; // execa
175
+ await $`node scripts/parse.js`; // bun/zx
176
+ ```
177
+
178
+ - Through scripts in `package.json` such as:
179
+
180
+ ```json
181
+ {
182
+ "name": "my-lib",
183
+ "scripts": {
184
+ "start": "node --import tsx/esm run.ts",
185
+ "start": "vitest -c config/vitest.config.ts"
186
+ }
187
+ }
188
+ ```
189
+
190
+ - Through plugins handling CI workflow files like `.github/workflows/ci.yml`:
191
+
192
+ ```yaml
193
+ jobs:
194
+ test:
195
+ steps:
196
+ run: playwright test e2e/**/*.spec.ts --config playwright.e2e.config.ts
197
+ run: node --import tsx/esm run.ts
198
+ ```
199
+
200
+ Scripts like the ones shown here may also contain references to configuration
201
+ files (`config/vitest.config.ts` and `playwright.e2e.config.ts` in the examples
202
+ above). They're recognized as configuration files and passed to their respective
203
+ plugins, and may contain additional entry files.
204
+
205
+ Entry files are added to the module graph. [Module resolution][10] might result
206
+ in additional entry files recursively until no more entry files are found.
207
+
208
+ ### What does Knip look for in source files?
209
+
210
+ The TypeScript source file parser is powerful and fault-tolerant. Knip visits
211
+ all nodes of the generated AST to find:
212
+
213
+ - Imports and dynamic imports of internal modules and external dependencies
214
+ - Exports
215
+ - Accessed properties on namespace imports and re-exports to track individual
216
+ export usage
217
+ - Calls to `require.resolve` and `import.meta.resolve`
218
+ - Scripts in template strings (passed to [script parser][11])
219
+
220
+ ### What's in the graphs?
221
+
222
+ Once the module and dependency graphs are created, they contain the information
223
+ required to create the report including all issue types:
224
+
225
+ - Unused files
226
+ - Unused dependencies
227
+ - Unused devDependencies
228
+ - Referenced optional peerDependencies
229
+ - Unlisted dependencies
230
+ - Unlisted binaries
231
+ - Unresolved imports
232
+ - Unused exports
233
+ - Unused exported types
234
+ - Unused exported enum members
235
+ - Duplicate exports
236
+
237
+ And optionally more issue types like individual exports and exported types in
238
+ namespace imports, and unused class members.
239
+
240
+ The graphs allows to report more interesting details, such as:
241
+
242
+ - Circular references
243
+ - Usage numbers per export
244
+ - Export usage across workspaces in a monorepo
245
+ - List of all binaries used
246
+ - List of all used (OS) binaries not installed in `node_modules`
247
+
248
+ ### Why doesn't Knip just read the lockfile?
249
+
250
+ Knip reads the `package.json` file of each dependency. Most of the information
251
+ required is in the lockfile as well, which would be more efficient. However,
252
+ there are a few issues with this approach:
253
+
254
+ - It requires lockfile parsing for each lockfile format and version of each
255
+ package manager.
256
+ - The lockfile doesn't contain whether the package [has types included][12].
257
+
258
+ ## Module Resolution
259
+
260
+ ### Why doesn't Knip use an existing module resolver?
261
+
262
+ Runtimes like Node.js provide `require.resolve` and `import.meta.resolve`.
263
+ TypeScript comes with module resolution built-in. More module resolvers are out
264
+ there and bundlers are known to use or come with module resolvers. None of them
265
+ seem to meet all requirements to be usable on its own by Knip:
266
+
267
+ - Support non-standard extensions like `.css`, `.svelte` and `.png`
268
+ - Support path aliases
269
+ - Support `exports` map in `package.json`
270
+ - Support self-referencing imports
271
+ - Rewire `package.json#main` build artifacts like `dist/module.js` to its source
272
+ at `src/module.ts`
273
+ - Don't resolve to type definition paths like `module.d.ts` but source code at
274
+ `module.js`
275
+
276
+ A few strategies have been tried and tweaked, and Knip currently uses a
277
+ combination of [oxc-resolver][13], the TypeScript module resolver and a few
278
+ customizations. This single custom module resolver function is hooked into the
279
+ TypeScript compiler and language service hosts.
280
+
281
+ Everything else is handled by `oxc-resolver` for things like [script
282
+ parsing][11] and resolving references to files in other workspaces.
283
+
284
+ ### How does Knip handle non-standard import syntax?
285
+
286
+ Knip tries to be resilient against import syntax like what's used by e.g.
287
+ webpack loaders or Vite asset imports. Knip strips off the prefixes and suffixes
288
+ in import specifiers like this:
289
+
290
+ ```ts title="component.ts"
291
+ import Icon from './icon.svg?raw';
292
+ import Styles from '-!style-loader!css-loader?modules!./styles.css';
293
+ ```
294
+
295
+ In this example, the `style-loader` and `css-loader` dependencies should be
296
+ dependencies found in webpack configuration, handled by Knip's webpack plugin.
297
+
298
+ ## TypeScript
299
+
300
+ ### What's the difference between workspaces, projects and programs?
301
+
302
+ A workspace is a directory with a `package.json` file. They're configured in
303
+ `package.json#workspaces` (or `pnpm-workspaces.yml`). In case a directory has a
304
+ `package.json` file, but is not a workspace (from a package manager
305
+ perspective), it can be added as a workspace to the Knip configuration.
306
+
307
+ Projects - in the context of TypeScript - are directories with a `tsconfig.json`
308
+ file. They're not a concept in Knip.
309
+
310
+ A TypeScript program has a 1-to-1 relationship with workspaces if they're
311
+ analyzed in isolation. However, by default Knip optimizes for performance and
312
+ utilizes [workspace sharing][14]. That's why debug output contains messages like
313
+ "Installed 2 programs for 29 workspaces".
314
+
315
+ ### Why doesn't Knip match my TypeScript project structure?
316
+
317
+ Repositories and workspaces in a monorepo aren't necessarily structured like
318
+ TypeScript projects. Put simply, the location of `package.json` files isn't
319
+ always adjacent to `tsconfig.json` files. Knip follows the structure of
320
+ workspaces in a monorepo.
321
+
322
+ An additional layering of TypeScript projects would complicate things. The
323
+ downside is that a `tsconfig.json` file not used by Knip may have conflicting
324
+ module resolution settings, potentially resulting in missed files.
325
+
326
+ In practice, this is rarely an issue. Knip sticks to the workspaces structure
327
+ and installs a single "kitchen sink" module resolver function per workspace.
328
+ Different strategies might add more complexity and performance penalties, while
329
+ the current strategy is simple, fast and good enough.
330
+
331
+ Note that any directory with a `package.json` not listed in the root
332
+ `package.json#workspaces` can be added to the Knip configuration manually to
333
+ have it handled as a separate workspace.
334
+
335
+ ### Why doesn't Knip analyze workspaces in isolation by default?
336
+
337
+ Knip creates TypeScript programs to create a module graph and traverse file
338
+ ASTs. In a monorepo, it would make a lot of sense to create one program per
339
+ workspace. However, this slows down the whole process considerably. That's why
340
+ Knip shares the files of multiple workspaces in a single program if their
341
+ configuration allows it. This optimization is enabled by default, while it also
342
+ allows the module resolver (one per program) to do some more caching.
343
+
344
+ Also see [workspace sharing][14].
345
+
346
+ ### Why doesn't Knip just use `ts.findReferences`?
347
+
348
+ TypeScript has a very good "Find references" feature, that you might be using in
349
+ your IDE as well. Yet at scale this becomes too slow. That's why Knip builds up
350
+ its own module graph to look up export usages. Additional benefits for this
351
+ comprehensive graph include:
352
+
353
+ - serializable and cacheable
354
+ - enables more features
355
+ - usable for other tools to build upon as well
356
+
357
+ Without sacrificing these benefits, Knip does use `ts.findReferences` to find
358
+ references to class members (i.e. when the issue type `classMembers` is
359
+ included). In case analysis of exports requires type information of external
360
+ dependencies, the [`--include-libs ` flag][8] will trigger the same.
361
+
362
+ ### Why can't I use path aliases to reference other workspaces?
363
+
364
+ Projects can use `compilerOptions.paths` to alias paths in other workspaces in
365
+ the same monorepo. Knip doesn't understand those paths might represent internal
366
+ workspaces and might report false positives.
367
+
368
+ The recommendation and best practice is to list such workspaces/dependencies in
369
+ `package.json`, and import them as such. Other tooling should not have any
370
+ issues with this standard approach either.
371
+
372
+ Also see the example in [TypeScript path aliases in monorepos][15].
373
+
374
+ ### What's up with that configurable `tsconfig.json` location?
375
+
376
+ There's a difference between `--tsConfig [file]` as a CLI argument and the
377
+ `typescript.config` option in Knip configuration.
378
+
379
+ The [`--tsConfig [file]` option][16] is used to provide an alternative location
380
+ for the default root `tsconfig.json` file. Relevant `compilerOptions` include
381
+ `paths` and `moduleResolution`. This setting is only available at the root
382
+ level.
383
+
384
+ On the other hand, the [`config` option of the plugin][17] can be set per
385
+ workspace. The TypeScript plugin extracts referenced external dependencies such
386
+ as those in `extends`, `compilerOptions.types` and JSX settings:
387
+
388
+ ```json title="tsconfig.json"
389
+ {
390
+ "extends": "@tsconfig/node20/tsconfig.json",
391
+ "compilerOptions": {
392
+ "jsxImportSource": "hastscript/svg"
393
+ }
394
+ }
395
+ ```
396
+
397
+ From this example, Knip can determine whether the `@tsconfig/node20` and
398
+ `hastscript` dependencies are properly listed in `package.json`.
399
+
400
+ #### Notes
401
+
402
+ - The TypeScript plugin doesn't add support for TypeScript to Knip (that's
403
+ already built-in). Like other plugins, it extracts dependencies from
404
+ `tsconfig.json`. With the `typescript.config` option an alternative location
405
+ for `tsconfig.json` can be set per workspace.
406
+ - In case path aliases from `compilerOptions.paths` aren't picked up by Knip,
407
+ either use `--tsConfig [file]` to target a different `tsconfig.json`, or
408
+ manually add [paths][18] to the Knip configuration. The latter can be done per
409
+ workspace.
410
+
411
+ ## Compilers
412
+
413
+ ### How does Knip handle Svelte or Astro files?
414
+
415
+ To further increase the coverage of the module graph, non-standard files other
416
+ than JavaScript and TypeScript modules should be included as well. For instance,
417
+ `.mdx` and `.astro` files can import each other, internal modules and external
418
+ dependencies.
419
+
420
+ Knip includes basic "compilers" for a few common file types (Astro, MDX, Svelte,
421
+ Vue). Knip does not include actual compilers for reasons of potential
422
+ incompatibility with the existing compiler, and dependency size. Knip allows to
423
+ override them with the compilers in your project, and add additional ones for
424
+ other file types.
425
+
426
+ ### Why are the exports of my `.vue` files not used?
427
+
428
+ Knip comes with basic "compilers" for a few common non-standard file types.
429
+ They're not actual compilers, they're regular expressions only to extract import
430
+ statements. Override the built-in Vue "compiler" with the real one in your
431
+ project. Also see the answer to the previous question and [Compilers][19].
432
+
433
+ ## Miscellaneous
434
+
435
+ ### Why isn't production mode the default?
436
+
437
+ The default mode of Knip includes all source files, tests, dependencies, dev
438
+ dependencies and tooling configuration.
439
+
440
+ On the other hand, production mode considers only source files and production
441
+ dependencies. Plugins add only production entry files.
442
+
443
+ Which mode should've been the default? They both have their merits:
444
+
445
+ - Production mode catches dead production code and dependencies. This mode has
446
+ the most impact on UX, since less code tends to be faster and safer.
447
+ - Default mode potentially catches more issues, e.g. lots of unused plugins of
448
+ tooling, including most issues found in production mode. This mode has the
449
+ most impact on DX, for the same reason.
450
+
451
+ Also see [production mode][5].
452
+
453
+ ### Why doesn't Knip have...?
454
+
455
+ Examples of features that have been requested include:
456
+
457
+ - Expose programmatic API
458
+ - Add local/custom plugins
459
+ - Expose the module and dependency graphs
460
+ - Custom AST visitors, e.g. to find and return:
461
+ - Unused interface/type members
462
+ - Unused object members (and e.g. React component props)
463
+ - Unused object props in function return values
464
+ - Analyze workspaces in parallel
465
+ - Support Deno
466
+ - Improve internal code structures and accessibility to support contributions
467
+ - Replace dependencies for better performance and correctness, such as for shell
468
+ script parsing and globbing with "unignores".
469
+
470
+ These are all interesting ideas, but most increase the API surface area, and all
471
+ require more development efforts and maintenance. Time is limited and
472
+ [sponsorships][20] currently don't cover - this can change though!
473
+
474
+ [1]: ../reference/integrations.md#mcp-server
475
+ [2]: ../reference/integrations.md#vs-code-extension
476
+ [3]: ../guides/configuring-project-files.md
477
+ [4]: ../reference/configuration.md#ignoreexportsusedinfile
478
+ [5]: ../features/production-mode.md
479
+ [6]: ../explanations/why-use-knip.md#less-is-more
480
+ [7]: ./issue-types.md
481
+ [8]: ../guides/handling-issues.mdx#external-libraries
482
+ [9]: ../explanations/why-use-knip.md#comprehensive
483
+ [10]: #module-resolution
484
+ [11]: ../features/script-parser.md
485
+ [12]: ../guides/handling-issues.mdx#type-definition-packages
486
+ [13]: https://oxc.rs/docs/guide/usage/resolver.html
487
+ [14]: ../guides/performance.md#workspace-sharing
488
+ [15]: ../guides/handling-issues.mdx#typescript-path-aliases-in-monorepos
489
+ [16]: ../reference/cli.md#--tsconfig-file
490
+ [17]: ../explanations/plugins.md#configuration-files
491
+ [18]: ../reference/configuration.md#paths
492
+ [19]: ../features/compilers.md
493
+ [20]: /sponsors
@@ -0,0 +1,105 @@
1
+ ---
2
+ title: Integrations
3
+ ---
4
+
5
+ - [VS Code/VSX Extension][1]
6
+ - [JetBrains Plugin][2]
7
+ - [MCP Server][3]
8
+ - [Language Server][4]
9
+
10
+ ## VS Code Extension
11
+
12
+ The official VS Code extension provides a rich integration with the [Knip
13
+ Language Server][4]:
14
+
15
+ - **Diagnostics**: Inline warnings for unused dependencies, exports and files
16
+ - **Hover Information**: Hover over exports to see import and usage locations
17
+ - **Imports Tree View**: Direct links to implementations
18
+ - **Exports Tree View**: Direct links to import and usage locations
19
+ - **Contention Detection**: Warnings for circular dependencies, conflicts and
20
+ branched import chains
21
+ - **Built-in MCP Server**: Automated configuration support for coding agents
22
+
23
+ Find [Knip on the VS Code Marketplace][5] and find [Knip in the Open VSX
24
+ Registry][6].
25
+
26
+ See below for [screenshots][7].
27
+
28
+ ## JetBrains Plugin
29
+
30
+ A community plugin is available for JetBrains IDEs including WebStorm, IntelliJ
31
+ IDEA, and others. The plugin is powered by the [Knip Language Server][4] and
32
+ provides diagnostics. Find [Knip on the JetBrains Marketplace][8].
33
+
34
+ ## MCP Server
35
+
36
+ The standalone MCP Server enables coding agents to configure Knip automatically.
37
+ Tell your agent to "configure knip" and it will use the available tools to
38
+ create, analyze and optimize your `knip.json` configuration.
39
+
40
+ The [Knip MCP Server][9] is available separately and built into the [Knip VS
41
+ Code Extension][1].
42
+
43
+ Start:
44
+
45
+ ```sh
46
+ npx @knip/mcp
47
+ ```
48
+
49
+ Note: The VS Code extension has this MCP Server built-in.
50
+
51
+ ## Language Server
52
+
53
+ The IDE integrations are powered by the Knip Language Server. It builds the full
54
+ module graph of your project and provides a session with a graph explorer. See
55
+ the [Knip Language Server documentation][10] for more details and information on
56
+ integrating Knip.
57
+
58
+ ## VS Code Extension Screenshots
59
+
60
+ ### Lint Findings
61
+
62
+ ![Lint Findings][11]
63
+
64
+ ### Imports & Exports
65
+
66
+ ![Hover over imports and exports][12]
67
+
68
+ ### Contention
69
+
70
+ The IDE extension shows extra issues in the tree views like circular
71
+ dependencies.
72
+
73
+ #### Circular Dependencies
74
+
75
+ ![Circular Dependencies][13]
76
+
77
+ #### Conflicts
78
+
79
+ ![Conflicts][14]
80
+
81
+ #### Branching
82
+
83
+ ![Branching][15]
84
+
85
+ ### Settings
86
+
87
+ ![VS Code Extension Settings][16]
88
+
89
+ [1]: #vs-code-extension
90
+ [2]: #jetbrains-plugin
91
+ [3]: #mcp-server
92
+ [4]: #language-server
93
+ [5]: https://marketplace.visualstudio.com/items?itemName=webpro.vscode-knip
94
+ [6]: https://open-vsx.org/extension/webpro/vscode-knip
95
+ [7]: #vs-code-extension-screenshots
96
+ [8]: https://plugins.jetbrains.com/plugin/29765-knip
97
+ [9]: https://www.npmjs.com/package/@knip/mcp
98
+ [10]:
99
+ https://github.com/webpro-nl/knip/blob/main/packages/language-server/README.md
100
+ [11]: /screenshots/editors-and-agents/diagnostics.webp
101
+ [12]: /screenshots/editors-and-agents/imports-exports.webp
102
+ [13]: /screenshots/editors-and-agents/circular-dependency.webp
103
+ [14]: /screenshots/editors-and-agents/conflict.webp
104
+ [15]: /screenshots/editors-and-agents/branch.webp
105
+ [16]: /screenshots/editors-and-agents/vscode-extension-settings.webp
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Issue Types
3
+ tableOfContents: false
4
+ ---
5
+
6
+ Knip reports the following types of issues:
7
+
8
+ | Title | Description | | Key |
9
+ | :----------------------------------- | :---------------------------------------------------- | ----- | :------------------------- |
10
+ | Unused files | Unable to find a reference to this file | 🔧 | `files` |
11
+ | Unused dependencies | Unable to find a reference to this dependency | 🔧 | `dependencies` |
12
+ | Unused devDependencies | Unable to find a reference to this devDependency | 🔧 | `devDependencies` |
13
+ | Referenced optional peerDependencies | Optional peer dependency is used | | `optionalPeerDependencies` |
14
+ | Unlisted dependencies | Used dependencies not listed in package.json | | `unlisted` |
15
+ | Unlisted binaries | Binaries from dependencies not listed in package.json | | `binaries` |
16
+ | Unused catalog entries | Unable to find a reference to this catalog entry | 🔧 | `catalog` |
17
+ | Unresolved imports | Unable to resolve this (import) specifier | | `unresolved` |
18
+ | Unused exports | Unable to find a reference to this export | 🔧 | `exports` |
19
+ | Unused exported types | Unable to find a reference to this exported type | 🔧 | `types` |
20
+ | Exports in used namespace | Namespace with export is used, but not export itself | 🔧 🟠 | `nsExports` |
21
+ | Exported types in used namespace | Namespace with type is used, but not type itself | 🔧 🟠 | `nsTypes` |
22
+ | Unused exported enum members | Unable to find a reference to this enum member | 🔧 | `enumMembers` |
23
+ | Unused exported class members | Unable to find a reference to this class member | 🔧 🟠 | `classMembers` |
24
+ | Duplicate exports | This is exported more than once | | `duplicates` |
25
+
26
+ ## Legend
27
+
28
+ | | Description |
29
+ | --- | :-------------------------------------------------- |
30
+ | 🔧 | [Auto-fixable][1] issue types |
31
+ | 🟠 | Not included by default (include with [filters][2]) |
32
+
33
+ ## Notes
34
+
35
+ - When an issue type has zero issues, it is not shown.
36
+ - Including or excluding `dependencies` (via CLI or configuration) automatically
37
+ includes or excludes `devDependencies` and `optionalPeerDependencies`. In
38
+ [rules][3], each key can be set individually.
39
+ - In [strict production mode][4], `devDependencies` are not included.
40
+ - The `types` issue type includes `enum`, `interface` and `type` exports.
41
+
42
+ [1]: ../features/auto-fix.mdx
43
+ [2]: ../features/rules-and-filters.md#filters
44
+ [3]: ../features/rules-and-filters.md#rules
45
+ [4]: ../features/production-mode.md#strict-mode