@knip/mcp 0.0.19 → 0.0.20

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 (70) hide show
  1. package/package.json +16 -16
  2. package/src/docs/blog/knip-v3.mdx +1 -1
  3. package/src/docs/blog/knip-v4.mdx +1 -1
  4. package/src/docs/explanations/comparison-and-migration.md +2 -0
  5. package/src/docs/explanations/plugins.md +22 -4
  6. package/src/docs/features/auto-fix.mdx +2 -2
  7. package/src/docs/guides/handling-issues.mdx +1 -1
  8. package/src/docs/guides/issue-reproduction.md +7 -6
  9. package/src/docs/guides/performance.md +1 -1
  10. package/src/docs/overview/features.md +1 -1
  11. package/src/docs/reference/faq.md +101 -38
  12. package/src/docs/reference/jsdoc-tsdoc-tags.md +12 -1
  13. package/src/docs/reference/plugins.md +7 -1
  14. package/src/docs/writing-a-plugin/index.md +1 -1
  15. package/src/docs/docs/blog/brief-history.md +0 -30
  16. package/src/docs/docs/blog/for-editors-and-agents.md +0 -131
  17. package/src/docs/docs/blog/knip-v3.mdx +0 -88
  18. package/src/docs/docs/blog/knip-v4.mdx +0 -149
  19. package/src/docs/docs/blog/knip-v5.mdx +0 -190
  20. package/src/docs/docs/blog/migration-to-v1.md +0 -65
  21. package/src/docs/docs/blog/release-notes-v2.md +0 -46
  22. package/src/docs/docs/blog/slim-down-to-speed-up.md +0 -269
  23. package/src/docs/docs/blog/state-of-knip.md +0 -191
  24. package/src/docs/docs/blog/two-years.mdx +0 -107
  25. package/src/docs/docs/explanations/comparison-and-migration.md +0 -133
  26. package/src/docs/docs/explanations/entry-files.md +0 -70
  27. package/src/docs/docs/explanations/plugins.md +0 -347
  28. package/src/docs/docs/explanations/why-use-knip.md +0 -128
  29. package/src/docs/docs/features/auto-fix.mdx +0 -348
  30. package/src/docs/docs/features/compilers.md +0 -172
  31. package/src/docs/docs/features/integrated-monorepos.md +0 -61
  32. package/src/docs/docs/features/monorepos-and-workspaces.md +0 -149
  33. package/src/docs/docs/features/production-mode.md +0 -95
  34. package/src/docs/docs/features/reporters.md +0 -304
  35. package/src/docs/docs/features/rules-and-filters.md +0 -102
  36. package/src/docs/docs/features/script-parser.md +0 -156
  37. package/src/docs/docs/features/source-mapping.md +0 -100
  38. package/src/docs/docs/guides/configuring-project-files.md +0 -205
  39. package/src/docs/docs/guides/contributing.md +0 -24
  40. package/src/docs/docs/guides/handling-issues.mdx +0 -708
  41. package/src/docs/docs/guides/issue-reproduction.md +0 -103
  42. package/src/docs/docs/guides/namespace-imports.md +0 -125
  43. package/src/docs/docs/guides/performance.md +0 -108
  44. package/src/docs/docs/guides/troubleshooting.md +0 -133
  45. package/src/docs/docs/guides/using-knip-in-ci.md +0 -50
  46. package/src/docs/docs/guides/working-with-commonjs.md +0 -72
  47. package/src/docs/docs/index.mdx +0 -160
  48. package/src/docs/docs/overview/configuration.md +0 -104
  49. package/src/docs/docs/overview/features.md +0 -66
  50. package/src/docs/docs/overview/getting-started.mdx +0 -205
  51. package/src/docs/docs/overview/screenshots-videos.md +0 -42
  52. package/src/docs/docs/playground.mdx +0 -38
  53. package/src/docs/docs/reference/cli.md +0 -511
  54. package/src/docs/docs/reference/configuration-hints.md +0 -146
  55. package/src/docs/docs/reference/configuration.md +0 -430
  56. package/src/docs/docs/reference/dynamic-configuration.mdx +0 -72
  57. package/src/docs/docs/reference/faq.md +0 -430
  58. package/src/docs/docs/reference/integrations.md +0 -105
  59. package/src/docs/docs/reference/issue-types.md +0 -43
  60. package/src/docs/docs/reference/jsdoc-tsdoc-tags.md +0 -122
  61. package/src/docs/docs/reference/known-issues.md +0 -86
  62. package/src/docs/docs/reference/plugins/.gitkeep +0 -0
  63. package/src/docs/docs/reference/plugins.md +0 -140
  64. package/src/docs/docs/reference/related-tooling.md +0 -46
  65. package/src/docs/docs/sponsors.mdx +0 -64
  66. package/src/docs/docs/typescript/unused-dependencies.md +0 -86
  67. package/src/docs/docs/typescript/unused-exports.md +0 -87
  68. package/src/docs/docs/writing-a-plugin/argument-parsing.md +0 -202
  69. package/src/docs/docs/writing-a-plugin/index.md +0 -392
  70. package/src/docs/docs/writing-a-plugin/inputs.md +0 -162
@@ -1,430 +0,0 @@
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
- ## Comparison
26
-
27
- ### Why isn't Knip an ESLint plugin?
28
-
29
- Linters like ESLint analyze files separately, while Knip lints projects as a
30
- whole.
31
-
32
- Knip requires full module and dependency graphs to find clutter across the
33
- project. Creating these comprehensive graphs is not a trivial task and it seems
34
- no such tool exists today, even more so when it comes to monorepos.
35
-
36
- File-oriented linters like ESLint are complementary to Knip.
37
-
38
- ### Isn't tree-shaking enough?
39
-
40
- In short: no. They share an important goal: improve UX by removing unused code.
41
- But tree-shaking and Knip are different and complementary tools.
42
-
43
- Tree-shaking is a build or compile-time activity to reduce production bundle
44
- size. It typically operates on bundled production code, which might include
45
- external/third-party code. A build time optimization and "out of your hands".
46
-
47
- On the other hand, Knip is a project linter that should be part of the
48
- development and QA phase. It lints, reports and fixes only your own source code.
49
- Moreover, in contrast with other linters, focuses on inter-file dependencies, so
50
- dead code within a file may not be caught by Knip.
51
-
52
- Issues reported by the linter are for you to handle and review.
53
-
54
- Besides those differences, Knip has a broader scope:
55
-
56
- - Improve DX (see [less is more][1]).
57
- - Unless using [production mode][2], also lint all source code like tests,
58
- scripts and Storybook stories.
59
- - Handle more [types of issues][3] (such as unlisted dependencies).
60
-
61
- ## Synergy
62
-
63
- ### Why does Knip have plugins?
64
-
65
- Plugins are an essential part of Knip. They prevent you from a lot of
66
- configuration out of the box, by adding entry files as accurately as possible
67
- and only for the tools actually installed. Yet the real magic is in their custom
68
- parsers for configuration files and command-line argument definitions.
69
-
70
- For instance, Vitest has the `environment` configuration option. The Vitest
71
- plugin knows `"node"` is the default value for `environment` which does not
72
- require an extra package, but will translate `"edge-runtime"` to the
73
- `@edge-runtime/vm` package. This allows Knip to report it if this package is not
74
- listed in `package.json`, or when it is no longer used after changes in the
75
- Vitest configuration.
76
-
77
- Configuration files may also contain references to entry files. For instance,
78
- Jest has `setupFilesAfterEnv: "<rootDir>/jest.setup.js"` or a reference may
79
- point to a file in another workspace in the same monorepo, e.g.
80
- `setupFiles: ['@org/shared/jest-setup.ts']`. Those entry files may also contain
81
- imports of internal modules or external dependencies, and so on.
82
-
83
- ### Why is Knip so heavily engineered?
84
-
85
- Even though a modular approach has its merits, for Knip it makes sense to have
86
- all the pieces in a single tool.
87
-
88
- Building up the module and dependency graphs requires non-standard module
89
- resolution and not only static but also dynamic analysis (i.e. actually load and
90
- execute modules), such as for parsers of plugins to receive the exported value
91
- of dynamic tooling configuration files. Additionally, [exports consumed by
92
- external libraries][4] require type information, as supported by the TypeScript
93
- backend. Last but not least, shell script parsing is required to find the right
94
- entry files, configuration files and dependencies accurately.
95
-
96
- The rippling effect of plugins and recursively adding entry files and
97
- dependencies to build up the graphs is also exactly what's meant by
98
- ["comprehensive" here][5].
99
-
100
- ## Building the graphs
101
-
102
- ### Where does Knip look for entry files?
103
-
104
- - In default locations such as `index.js` and `src/index.ts`
105
- - In `main`, `bin` and `exports` fields in `package.json`
106
- - In the entry files as configured by enabled plugins
107
- - In `config` files as configured and parsed by enabled plugins
108
- - The `config` files themselves are entry files
109
- - In dynamic imports (i.e. `require()` and `import()` calls)
110
- - In `require.resolve('./entry.js')`
111
- - In `import.meta.resolve('./entry.mjs')`
112
- - Through scripts inside template strings in source files such as:
113
-
114
- ```ts
115
- await $({ stdio: 'inherit' })`c8 node hydrate.js`; // execa
116
- await $`node scripts/parse.js`; // bun/zx
117
- ```
118
-
119
- - Through scripts in `package.json` such as:
120
-
121
- ```json
122
- {
123
- "name": "my-lib",
124
- "scripts": {
125
- "start": "node --import tsx/esm run.ts",
126
- "start": "vitest -c config/vitest.config.ts"
127
- }
128
- }
129
- ```
130
-
131
- - Through plugins handling CI workflow files like `.github/workflows/ci.yml`:
132
-
133
- ```yaml
134
- jobs:
135
- test:
136
- steps:
137
- run: playwright test e2e/**/*.spec.ts --config playwright.e2e.config.ts
138
- run: node --import tsx/esm run.ts
139
- ```
140
-
141
- Scripts like the ones shown here may also contain references to configuration
142
- files (`config/vitest.config.ts` and `playwright.e2e.config.ts` in the examples
143
- above). They're recognized as configuration files and passed to their respective
144
- plugins, and may contain additional entry files.
145
-
146
- Entry files are added to the module graph. [Module resolution][6] might result
147
- in additional entry files recursively until no more entry files are found.
148
-
149
- ### What does Knip look for in source files?
150
-
151
- The TypeScript source file parser is powerful and fault-tolerant. Knip visits
152
- all nodes of the generated AST to find:
153
-
154
- - Imports and dynamic imports of internal modules and external dependencies
155
- - Exports
156
- - Accessed properties on namespace imports and re-exports to track individual
157
- export usage
158
- - Calls to `require.resolve` and `import.meta.resolve`
159
- - Scripts in template strings (passed to [script parser][7])
160
-
161
- ### What's in the graphs?
162
-
163
- Once the module and dependency graphs are created, they contain the information
164
- required to create the report including all issue types:
165
-
166
- - Unused files
167
- - Unused dependencies
168
- - Unused devDependencies
169
- - Referenced optional peerDependencies
170
- - Unlisted dependencies
171
- - Unlisted binaries
172
- - Unresolved imports
173
- - Unused exports
174
- - Unused exported types
175
- - Unused exported enum members
176
- - Duplicate exports
177
-
178
- And optionally more issue types like individual exports and exported types in
179
- namespace imports, and unused class members.
180
-
181
- The graphs allows to report more interesting details, such as:
182
-
183
- - Circular references
184
- - Usage numbers per export
185
- - Export usage across workspaces in a monorepo
186
- - List of all binaries used
187
- - List of all used (OS) binaries not installed in `node_modules`
188
-
189
- ### Why doesn't Knip just read the lockfile?
190
-
191
- Knip reads the `package.json` file of each dependency. Most of the information
192
- required is in the lockfile as well, which would be more efficient. However,
193
- there are a few issues with this approach:
194
-
195
- - It requires lockfile parsing for each lockfile format and version of each
196
- package manager.
197
- - The lockfile doesn't contain whether the package [has types included][8].
198
-
199
- ## Module Resolution
200
-
201
- ### Why doesn't Knip use an existing module resolver?
202
-
203
- Runtimes like Node.js provide `require.resolve` and `import.meta.resolve`.
204
- TypeScript comes with module resolution built-in. More module resolvers are out
205
- there and bundlers are known to use or come with module resolvers. None of them
206
- seem to meet all requirements to be usable on its own by Knip:
207
-
208
- - Support non-standard extensions like `.css`, `.svelte` and `.png`
209
- - Support path aliases
210
- - Support `exports` map in `package.json`
211
- - Support self-referencing imports
212
- - Rewire `package.json#main` build artifacts like `dist/module.js` to its source
213
- at `src/module.ts`
214
- - Don't resolve to type definition paths like `module.d.ts` but source code at
215
- `module.js`
216
-
217
- A few strategies have been tried and tweaked, and Knip currently uses a
218
- combination of [oxc-resolver][9], the TypeScript module resolver and a few
219
- customizations. This single custom module resolver function is hooked into the
220
- TypeScript compiler and language service hosts.
221
-
222
- Everything else is handled by `oxc-resolver` for things like [script parsing][7]
223
- and resolving references to files in other workspaces.
224
-
225
- ### How does Knip handle non-standard import syntax?
226
-
227
- Knip tries to be resilient against import syntax like what's used by e.g.
228
- webpack loaders or Vite asset imports. Knip strips off the prefixes and suffixes
229
- in import specifiers like this:
230
-
231
- ```ts title="component.ts"
232
- import Icon from './icon.svg?raw';
233
- import Styles from '-!style-loader!css-loader?modules!./styles.css';
234
- ```
235
-
236
- In this example, the `style-loader` and `css-loader` dependencies should be
237
- dependencies found in webpack configuration, handled by Knip's webpack plugin.
238
-
239
- ## TypeScript
240
-
241
- ### What's the difference between workspaces, projects and programs?
242
-
243
- A workspace is a directory with a `package.json` file. They're configured in
244
- `package.json#workspaces` (or `pnpm-workspaces.yml`). In case a directory has a
245
- `package.json` file, but is not a workspace (from a package manager
246
- perspective), it can be added as a workspace to the Knip configuration.
247
-
248
- Projects - in the context of TypeScript - are directories with a `tsconfig.json`
249
- file. They're not a concept in Knip.
250
-
251
- A TypeScript program has a 1-to-1 relationship with workspaces if they're
252
- analyzed in isolation. However, by default Knip optimizes for performance and
253
- utilizes [workspace sharing][10]. That's why debug output contains messages like
254
- "Installed 2 programs for 29 workspaces".
255
-
256
- ### Why doesn't Knip match my TypeScript project structure?
257
-
258
- Repositories and workspaces in a monorepo aren't necessarily structured like
259
- TypeScript projects. Put simply, the location of `package.json` files isn't
260
- always adjacent to `tsconfig.json` files. Knip follows the structure of
261
- workspaces in a monorepo.
262
-
263
- An additional layering of TypeScript projects would complicate things. The
264
- downside is that a `tsconfig.json` file not used by Knip may have conflicting
265
- module resolution settings, potentially resulting in missed files.
266
-
267
- In practice, this is rarely an issue. Knip sticks to the workspaces structure
268
- and installs a single "kitchen sink" module resolver function per workspace.
269
- Different strategies might add more complexity and performance penalties, while
270
- the current strategy is simple, fast and good enough.
271
-
272
- Note that any directory with a `package.json` not listed in the root
273
- `package.json#workspaces` can be added to the Knip configuration manually to
274
- have it handled as a separate workspace.
275
-
276
- ### Why doesn't Knip analyze workspaces in isolation by default?
277
-
278
- Knip creates TypeScript programs to create a module graph and traverse file
279
- ASTs. In a monorepo, it would make a lot of sense to create one program per
280
- workspace. However, this slows down the whole process considerably. That's why
281
- Knip shares the files of multiple workspaces in a single program if their
282
- configuration allows it. This optimization is enabled by default, while it also
283
- allows the module resolver (one per program) to do some more caching.
284
-
285
- Also see [workspace sharing][10].
286
-
287
- ### Why doesn't Knip just use `ts.findReferences`?
288
-
289
- TypeScript has a very good "Find references" feature, that you might be using in
290
- your IDE as well. Yet at scale this becomes too slow. That's why Knip builds up
291
- its own module graph to look up export usages. Additional benefits for this
292
- comprehensive graph include:
293
-
294
- - serializable and cacheable
295
- - enables more features
296
- - usable for other tools to build upon as well
297
-
298
- Without sacrificing these benefits, Knip does use `ts.findReferences` to find
299
- references to class members (i.e. when the issue type `classMembers` is
300
- included). In case analysis of exports requires type information of external
301
- dependencies, the [`--include-libs ` flag][4] will trigger the same.
302
-
303
- ### Why can't I use path aliases to reference other workspaces?
304
-
305
- Projects can use `compilerOptions.paths` to alias paths in other workspaces in
306
- the same monorepo. Knip doesn't understand those paths might represent internal
307
- workspaces and might report false positives.
308
-
309
- The recommendation and best practice is to list such workspaces/dependencies in
310
- `package.json`, and import them as such. Other tooling should not have any
311
- issues with this standard approach either.
312
-
313
- Also see the example in [TypeScript path aliases in monorepos][11].
314
-
315
- ### What's up with that configurable `tsconfig.json` location?
316
-
317
- There's a difference between `--tsConfig [file]` as a CLI argument and the
318
- `typescript.config` option in Knip configuration.
319
-
320
- The [`--tsConfig [file]` option][12] is used to provide an alternative location
321
- for the default root `tsconfig.json` file. Relevant `compilerOptions` include
322
- `paths` and `moduleResolution`. This setting is only available at the root
323
- level.
324
-
325
- On the other hand, the [`config` option of the plugin][13] can be set per
326
- workspace. The TypeScript plugin extracts referenced external dependencies such
327
- as those in `extends`, `compilerOptions.types` and JSX settings:
328
-
329
- ```json title="tsconfig.json"
330
- {
331
- "extends": "@tsconfig/node20/tsconfig.json",
332
- "compilerOptions": {
333
- "jsxImportSource": "hastscript/svg"
334
- }
335
- }
336
- ```
337
-
338
- From this example, Knip can determine whether the `@tsconfig/node20` and
339
- `hastscript` dependencies are properly listed in `package.json`.
340
-
341
- #### Notes
342
-
343
- - The TypeScript plugin doesn't add support for TypeScript to Knip (that's
344
- already built-in). Like other plugins, it extracts dependencies from
345
- `tsconfig.json`. With the `typescript.config` option an alternative location
346
- for `tsconfig.json` can be set per workspace.
347
- - In case path aliases from `compilerOptions.paths` aren't picked up by Knip,
348
- either use `--tsConfig [file]` to target a different `tsconfig.json`, or
349
- manually add [paths][14] to the Knip configuration. The latter can be done per
350
- workspace.
351
-
352
- ## Compilers
353
-
354
- ### How does Knip handle Svelte or Astro files?
355
-
356
- To further increase the coverage of the module graph, non-standard files other
357
- than JavaScript and TypeScript modules should be included as well. For instance,
358
- `.mdx` and `.astro` files can import each other, internal modules and external
359
- dependencies.
360
-
361
- Knip includes basic "compilers" for a few common file types (Astro, MDX, Svelte,
362
- Vue). Knip does not include actual compilers for reasons of potential
363
- incompatibility with the existing compiler, and dependency size. Knip allows to
364
- override them with the compilers in your project, and add additional ones for
365
- other file types.
366
-
367
- ### Why are the exports of my `.vue` files not used?
368
-
369
- Knip comes with basic "compilers" for a few common non-standard file types.
370
- They're not actual compilers, they're regular expressions only to extract import
371
- statements. Override the built-in Vue "compiler" with the real one in your
372
- project. Also see the answer to the previous question and [Compilers][15].
373
-
374
- ## Miscellaneous
375
-
376
- ### Why isn't production mode the default?
377
-
378
- The default mode of Knip includes all source files, tests, dependencies, dev
379
- dependencies and tooling configuration.
380
-
381
- On the other hand, production mode considers only source files and production
382
- dependencies. Plugins add only production entry files.
383
-
384
- Which mode should've been the default? They both have their merits:
385
-
386
- - Production mode catches dead production code and dependencies. This mode has
387
- the most impact on UX, since less code tends to be faster and safer.
388
- - Default mode potentially catches more issues, e.g. lots of unused plugins of
389
- tooling, including most issues found in production mode. This mode has the
390
- most impact on DX, for the same reason.
391
-
392
- Also see [production mode][2].
393
-
394
- ### Why doesn't Knip have...?
395
-
396
- Examples of features that have been requested include:
397
-
398
- - Expose programmatic API
399
- - Add local/custom plugins
400
- - Expose the module and dependency graphs
401
- - Custom AST visitors, e.g. to find and return:
402
- - Unused interface/type members
403
- - Unused object members (and e.g. React component props)
404
- - Unused object props in function return values
405
- - Analyze workspaces in parallel
406
- - Support Deno
407
- - Improve internal code structures and accessibility to support contributions
408
- - Replace dependencies for better performance and correctness, such as for shell
409
- script parsing and globbing with "unignores".
410
-
411
- These are all interesting ideas, but most increase the API surface area, and all
412
- require more development efforts and maintenance. Time is limited and
413
- [sponsorships][16] currently don't cover - this can change though!
414
-
415
- [1]: ../explanations/why-use-knip.md#less-is-more
416
- [2]: ../features/production-mode.md
417
- [3]: ./issue-types.md
418
- [4]: ../guides/handling-issues.mdx#external-libraries
419
- [5]: ../explanations/why-use-knip.md#comprehensive
420
- [6]: #module-resolution
421
- [7]: ../features/script-parser.md
422
- [8]: ../guides/handling-issues.mdx#type-definition-packages
423
- [9]: https://oxc.rs/docs/guide/usage/resolver.html
424
- [10]: ../guides/performance.md#workspace-sharing
425
- [11]: ../guides/handling-issues.mdx#typescript-path-aliases-in-monorepos
426
- [12]: ../reference/cli.md#--tsconfig-file
427
- [13]: ../explanations/plugins.md#configuration-files
428
- [14]: ../reference/configuration.md#paths
429
- [15]: ../features/compilers.md
430
- [16]: /sponsors
@@ -1,105 +0,0 @@
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
@@ -1,43 +0,0 @@
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 | 🔧 | `dependencies` |
13
- | Referenced optional peerDependencies | Optional peer dependency is referenced | | `dependencies` |
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 referenced, but not export itself | 🔧 🟠 | `nsExports` |
21
- | Exported types in used namespace | Namespace with type is referenced, 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
- - The `devDependencies` and `optionalPeerDependencies` are covered in a single
37
- key for all `dependencies`. In [strict production mode][3], `devDependencies`
38
- are not included.
39
- - The `types` issue type includes `enum`, `interface` and `type` exports.
40
-
41
- [1]: ../features/auto-fix.mdx
42
- [2]: ../features/rules-and-filters.md#filters
43
- [3]: ../features/production-mode.md#strict-mode
@@ -1,122 +0,0 @@
1
- ---
2
- title: JSDoc & TSDoc Tags
3
- ---
4
-
5
- JSDoc or TSDoc tags can be used to make exceptions for unused or duplicate
6
- exports.
7
-
8
- Knip tries to minimize configuration and introduces no new syntax. That's why it
9
- hooks into JSDoc and TSDoc tags.
10
-
11
- :::caution
12
-
13
- Adding tags or excluding a certain type of issues from the report is usually not
14
- recommended. It hides issues, which is often a sign of code smell or ambiguity
15
- and ends up harder to maintain. It's usually better to refactor the code (or
16
- report an issue with Knip for false positives).
17
-
18
- :::
19
-
20
- JSDoc comments always start with `/**` (not `//`) and can be single or
21
- multi-line.
22
-
23
- ## Tags
24
-
25
- Use arbitrary [tags][1] to exclude or include tagged exports from the report.
26
- Example:
27
-
28
- ```ts
29
- /** @lintignore */
30
- export const myUnusedExport = 1;
31
-
32
- /** @lintignore */
33
- import Unresolved from './generated/lib.js';
34
- ```
35
-
36
- And then include (`+`) or exclude (`-`) these tagged exports from the report
37
- like so:
38
-
39
- ```shell
40
- knip --tags=-lintignore,-internal
41
- ```
42
-
43
- Tags can also be [configured in `knip.json`][2].
44
-
45
- ## `@public`
46
-
47
- By default, Knip reports unused exports in non-entry files.
48
-
49
- Tag the export as `@public` and Knip will not report it.
50
-
51
- Example:
52
-
53
- ```ts
54
- /**
55
- * @public
56
- */
57
- export const unusedFunction = () => {};
58
- ```
59
-
60
- This tag can also be used to make exceptions in entry files when using
61
- [--include-entry-exports][3].
62
-
63
- [JSDoc: @public][4] and [TSDoc: @public][5]
64
-
65
- ## `@internal`
66
-
67
- Internal exports are not meant for public consumption, but only for internal
68
- usage such as tests. This means they would be reported in [production mode][6].
69
-
70
- Mark the export with `@internal` and Knip will not report the export in
71
- production mode.
72
-
73
- Example:
74
-
75
- ```ts
76
- /** @internal */
77
- export const internalTestedFunction = () => {};
78
- ```
79
-
80
- In general it's not recommended to expose and test implementation details, but
81
- exceptions are possible. Those should not be reported as false positives, so
82
- when using production mode you'll need to help Knip out by tagging them as
83
- `@internal`.
84
-
85
- [TSDoc: @internal][7]
86
-
87
- ## `@alias`
88
-
89
- Knip reports duplicate exports. To prevent this, tag one of the exports as
90
- `@alias`.
91
-
92
- Example:
93
-
94
- ```ts
95
- export const Component = () => {};
96
-
97
- /** @alias */
98
- export default Component;
99
- ```
100
-
101
- An alternative solution is to use `--exclude duplicates` and exclude all
102
- duplicates from being reported.
103
-
104
- [JSDoc: @alias][8]
105
-
106
- ## `@beta`
107
-
108
- Works identical to [`@public`][9]. Knip ignores other tags like `@alpha` and
109
- `@experimental`.
110
-
111
- [TSDoc: @beta][10]
112
-
113
- [1]: ../reference/cli.md#--tags
114
- [2]: ./configuration.md#tags
115
- [3]: ./cli.md#--include-entry-exports
116
- [4]: https://jsdoc.app/tags-public.html
117
- [5]: https://tsdoc.org/pages/tags/public/
118
- [6]: ../features/production-mode.md
119
- [7]: https://tsdoc.org/pages/tags/internal/
120
- [8]: https://jsdoc.app/tags-alias.html
121
- [9]: #public
122
- [10]: https://tsdoc.org/pages/tags/beta/