@knip/mcp 0.0.2 → 0.0.3
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.
- package/docs/blog/for-editors-and-agents.md +50 -35
- package/docs/docs/blog/brief-history.md +30 -0
- package/docs/docs/blog/for-editors-and-agents.md +124 -0
- package/docs/docs/blog/knip-v3.mdx +88 -0
- package/docs/docs/blog/knip-v4.mdx +149 -0
- package/docs/docs/blog/knip-v5.mdx +190 -0
- package/docs/docs/blog/migration-to-v1.md +65 -0
- package/docs/docs/blog/release-notes-v2.md +46 -0
- package/docs/docs/blog/slim-down-to-speed-up.md +269 -0
- package/docs/docs/blog/state-of-knip.md +191 -0
- package/docs/docs/blog/two-years.mdx +107 -0
- package/docs/docs/explanations/comparison-and-migration.md +129 -0
- package/docs/docs/explanations/entry-files.md +70 -0
- package/docs/docs/explanations/plugins.md +318 -0
- package/docs/docs/explanations/why-use-knip.md +128 -0
- package/docs/docs/features/auto-fix.mdx +333 -0
- package/docs/docs/features/compilers.md +172 -0
- package/docs/docs/features/integrated-monorepos.md +52 -0
- package/docs/docs/features/monorepos-and-workspaces.md +134 -0
- package/docs/docs/features/production-mode.md +95 -0
- package/docs/docs/features/reporters.md +302 -0
- package/docs/docs/features/rules-and-filters.md +102 -0
- package/docs/docs/features/script-parser.md +156 -0
- package/docs/docs/features/source-mapping.md +100 -0
- package/docs/docs/guides/configuring-project-files.md +205 -0
- package/docs/docs/guides/contributing.md +24 -0
- package/docs/docs/guides/handling-issues.mdx +646 -0
- package/docs/docs/guides/issue-reproduction.md +94 -0
- package/docs/docs/guides/namespace-imports.md +125 -0
- package/docs/docs/guides/performance.md +97 -0
- package/docs/docs/guides/troubleshooting.md +127 -0
- package/docs/docs/guides/using-knip-in-ci.md +54 -0
- package/docs/docs/guides/working-with-commonjs.md +72 -0
- package/docs/docs/index.mdx +160 -0
- package/docs/docs/overview/configuration.md +104 -0
- package/docs/docs/overview/features.md +66 -0
- package/docs/docs/overview/getting-started.mdx +195 -0
- package/docs/docs/overview/screenshots-videos.md +42 -0
- package/docs/docs/playground.mdx +38 -0
- package/docs/docs/reference/cli.md +481 -0
- package/docs/docs/reference/configuration.md +413 -0
- package/docs/docs/reference/dynamic-configuration.mdx +72 -0
- package/docs/docs/reference/faq.md +441 -0
- package/docs/docs/reference/issue-types.md +43 -0
- package/docs/docs/reference/jsdoc-tsdoc-tags.md +122 -0
- package/docs/docs/reference/known-issues.md +64 -0
- package/docs/docs/reference/plugins/.gitkeep +0 -0
- package/docs/docs/reference/plugins.md +238 -0
- package/docs/docs/reference/related-tooling.md +46 -0
- package/docs/docs/sponsors.mdx +65 -0
- package/docs/docs/typescript/unused-dependencies.md +86 -0
- package/docs/docs/typescript/unused-exports.md +87 -0
- package/docs/docs/writing-a-plugin/argument-parsing.md +202 -0
- package/docs/docs/writing-a-plugin/index.md +376 -0
- package/docs/docs/writing-a-plugin/inputs.md +162 -0
- package/package.json +8 -6
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Plugins
|
|
3
|
+
sidebar:
|
|
4
|
+
order: 2
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
This page describes why Knip uses plugins and the difference between `config`
|
|
8
|
+
and `entry` files.
|
|
9
|
+
|
|
10
|
+
Knip has an extensive and growing [list of built-in plugins][1]. Feel free to
|
|
11
|
+
[write a plugin][2] so others can benefit too!
|
|
12
|
+
|
|
13
|
+
## What does a plugin do?
|
|
14
|
+
|
|
15
|
+
Plugins are enabled if the related package is listed in the list of dependencies
|
|
16
|
+
in `package.json`. For instance, if `astro` is listed in `dependencies` or
|
|
17
|
+
`devDependencies`, then the Astro plugin is enabled. And this means that this
|
|
18
|
+
plugin will:
|
|
19
|
+
|
|
20
|
+
- Handle [configuration files][3] like `astro.config.mjs`
|
|
21
|
+
- Add [entry files][4] such as `src/pages/**/*.astro`
|
|
22
|
+
- Define [command-line arguments][5]
|
|
23
|
+
|
|
24
|
+
## Configuration files
|
|
25
|
+
|
|
26
|
+
Knip uses [entry files][6] as starting points to scan your source code and
|
|
27
|
+
resolve other internal files and external dependencies. The module graph can be
|
|
28
|
+
statically resolved through the `require` and `import` statements in those
|
|
29
|
+
source files. However, configuration files reference external dependencies in
|
|
30
|
+
various ways. Knip uses a plugin for each tool to parse configuration files and
|
|
31
|
+
find those dependencies.
|
|
32
|
+
|
|
33
|
+
### Example: ESLint
|
|
34
|
+
|
|
35
|
+
In the first example we look at [the ESLint plugin][7]. The default `config`
|
|
36
|
+
file patterns include `.eslintrc.json`. Here's a minimal example:
|
|
37
|
+
|
|
38
|
+
```json title=".eslintrc.json"
|
|
39
|
+
{
|
|
40
|
+
"extends": ["airbnb", "prettier"],
|
|
41
|
+
"plugins": ["@typescript-eslint"]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Configuration files like this don't `import` or `require` anything, but they do
|
|
46
|
+
require the referenced dependencies to be installed.
|
|
47
|
+
|
|
48
|
+
In this case, the plugin will return three dependencies:
|
|
49
|
+
|
|
50
|
+
- `eslint-config-airbnb`
|
|
51
|
+
- `eslint-config-prettier`
|
|
52
|
+
- `@typescript-eslint/eslint-plugin`
|
|
53
|
+
|
|
54
|
+
Knip will then look for missing dependencies in `package.json` and report those
|
|
55
|
+
as unlisted. And vice versa, if there are any ESLint plugins listed in
|
|
56
|
+
`package.json`, but unused, those will be reported as well.
|
|
57
|
+
|
|
58
|
+
### Example: Vitest
|
|
59
|
+
|
|
60
|
+
The second example uses [the Vitest plugin][7]. Here's a minimal example of a
|
|
61
|
+
Vitest configuration file:
|
|
62
|
+
|
|
63
|
+
```ts title="vitest.config.ts"
|
|
64
|
+
import { defineConfig } from 'vitest/config';
|
|
65
|
+
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
test: {
|
|
68
|
+
coverage: {
|
|
69
|
+
provider: 'istanbul',
|
|
70
|
+
},
|
|
71
|
+
environment: 'happy-dom',
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The Vitest plugin reads this configuration and return two dependencies:
|
|
77
|
+
|
|
78
|
+
- `@vitest/coverage-istanbul`
|
|
79
|
+
- `vitest-environment-happy-dom`
|
|
80
|
+
|
|
81
|
+
Knip will look for missing and unused dependencies in `package.json` and report
|
|
82
|
+
accordingly.
|
|
83
|
+
|
|
84
|
+
Some tools allow configuration to be stored in `package.json`, that's why some
|
|
85
|
+
plugins contain `package.json` in the list of `config` files.
|
|
86
|
+
|
|
87
|
+
:::tip[Summary]
|
|
88
|
+
|
|
89
|
+
Plugins parse `config` files to find external dependencies. Knip uses this to
|
|
90
|
+
determine unused and unlisted dependencies.
|
|
91
|
+
|
|
92
|
+
:::
|
|
93
|
+
|
|
94
|
+
## Entry files
|
|
95
|
+
|
|
96
|
+
Many plugins have default `entry` files configured. When the plugin is enabled,
|
|
97
|
+
Knip will add entry files as configured by the plugin to resolve used files and
|
|
98
|
+
dependencies.
|
|
99
|
+
|
|
100
|
+
For example, if `next` is listed as a dependency in `package.json`, the Next.js
|
|
101
|
+
plugin will automatically add multiple patterns as entry files, such as
|
|
102
|
+
`pages/**/*.{js,jsx,ts,tsx}`. If `vitest` is listed, the Vitest plugin adds
|
|
103
|
+
`**/*.{test,test-d,spec}.ts` as entry file patterns. Most plugins have entry
|
|
104
|
+
files configured, so you don't have to.
|
|
105
|
+
|
|
106
|
+
It's mostly plugins for meta frameworks and test runners that have `entry` files
|
|
107
|
+
configured.
|
|
108
|
+
|
|
109
|
+
:::tip[Plugins result in less configuration]
|
|
110
|
+
|
|
111
|
+
Plugins uses entry file patterns as defined in the configuration files of these
|
|
112
|
+
tools. So you don't need to repeat this in your Knip configuration.
|
|
113
|
+
|
|
114
|
+
:::
|
|
115
|
+
|
|
116
|
+
For example, let's say your Playwright configuration contains the following:
|
|
117
|
+
|
|
118
|
+
```ts title="playwright.config.ts"
|
|
119
|
+
import type { PlaywrightTestConfig } from '@playwright/test';
|
|
120
|
+
|
|
121
|
+
const config: PlaywrightTestConfig = {
|
|
122
|
+
testDir: 'integration',
|
|
123
|
+
testMatch: ['**/*-test.ts'],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export default config;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The Playwright plugin will read this configuration file and return those entry
|
|
130
|
+
patterns (`integration/**/*-test.ts`). Knip will then not use the default entry
|
|
131
|
+
patterns.
|
|
132
|
+
|
|
133
|
+
You can still override this behavior in your Knip configuration:
|
|
134
|
+
|
|
135
|
+
```json title="knip.json"
|
|
136
|
+
{
|
|
137
|
+
"playwright": {
|
|
138
|
+
"entry": "src/**/*.integration.ts"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This should not be necessary though. Please consider opening a pull request or a
|
|
144
|
+
bug report if any plugin is not behaving as expected.
|
|
145
|
+
|
|
146
|
+
:::tip[Summary]
|
|
147
|
+
|
|
148
|
+
Plugins try hard to automatically add the correct entry files.
|
|
149
|
+
|
|
150
|
+
:::
|
|
151
|
+
|
|
152
|
+
## Entry files from config files
|
|
153
|
+
|
|
154
|
+
Entry files are part of plugin configuration (as described in the previous
|
|
155
|
+
section). Yet plugins can also return additional entry files after parsing
|
|
156
|
+
configuration files. Below are some examples of configuration files parsed by
|
|
157
|
+
plugins to return additional entry files. The goal of these examples is to give
|
|
158
|
+
you an idea about the various ways Knip and its plugins try to find entry files
|
|
159
|
+
so you don't need to configure them yourself.
|
|
160
|
+
|
|
161
|
+
### Angular
|
|
162
|
+
|
|
163
|
+
The Angular plugin parses the Angular configuration file. Here's a fragment:
|
|
164
|
+
|
|
165
|
+
```json title="angular.json"
|
|
166
|
+
{
|
|
167
|
+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
|
168
|
+
"projects": {
|
|
169
|
+
"knip-angular-example": {
|
|
170
|
+
"architect": {
|
|
171
|
+
"build": {
|
|
172
|
+
"builder": "@angular-devkit/build-angular:browser",
|
|
173
|
+
"options": {
|
|
174
|
+
"outputPath": "dist/knip-angular-example",
|
|
175
|
+
"main": "src/main.ts",
|
|
176
|
+
"tsConfig": "tsconfig.app.json"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
This will result in `src/main.ts` being added as an entry file (and
|
|
186
|
+
`@angular-devkit/build-angular` as a referenced dependency).
|
|
187
|
+
|
|
188
|
+
Additionally, the Angular plugin returns `tsconfig.app.json` as a configuration
|
|
189
|
+
file for the TypeScript plugin.
|
|
190
|
+
|
|
191
|
+
### GitHub Actions
|
|
192
|
+
|
|
193
|
+
This plugin parses workflow YAML files. This fragment contains three `run`
|
|
194
|
+
scripts:
|
|
195
|
+
|
|
196
|
+
```yml title=".github/workflows/deploy.yml"
|
|
197
|
+
jobs:
|
|
198
|
+
integration:
|
|
199
|
+
runs-on: ubuntu-latest
|
|
200
|
+
steps:
|
|
201
|
+
- run: npm install
|
|
202
|
+
- run: node scripts/build.js
|
|
203
|
+
- run: node --loader tsx scripts/deploy.ts
|
|
204
|
+
- run: playwright test -c playwright.web.config.ts
|
|
205
|
+
working-dir: e2e
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
From these scripts, the `scripts/build.js` and `scripts/deploy.ts` files will be
|
|
209
|
+
added as entry files by the GitHub Actions plugin.
|
|
210
|
+
|
|
211
|
+
Additionally, the file `e2e/playwright.web.config.ts` is detected and will be
|
|
212
|
+
handed over as a Playwright configuration file.
|
|
213
|
+
|
|
214
|
+
Read more about this in [command-line arguments][5].
|
|
215
|
+
|
|
216
|
+
### webpack
|
|
217
|
+
|
|
218
|
+
Let's take a look at this example webpack configuration file:
|
|
219
|
+
|
|
220
|
+
```js title="webpack.config.js"
|
|
221
|
+
module.exports = env => {
|
|
222
|
+
return {
|
|
223
|
+
entry: {
|
|
224
|
+
main: './src/app.ts',
|
|
225
|
+
vendor: './src/vendor.ts',
|
|
226
|
+
},
|
|
227
|
+
module: {
|
|
228
|
+
rules: [
|
|
229
|
+
{
|
|
230
|
+
test: /\.(woff|ttf|ico|woff2|jpg|jpeg|png|webp)$/i,
|
|
231
|
+
use: 'base64-inline-loader',
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The webpack plugin will parse this and add `./src/app.ts` and `./src/vendor.ts`
|
|
240
|
+
as entry files. It will also add `base64-inline-loader` as a referenced
|
|
241
|
+
dependency.
|
|
242
|
+
|
|
243
|
+
:::tip[Summary]
|
|
244
|
+
|
|
245
|
+
Plugins can find additional entry files when parsing config files.
|
|
246
|
+
|
|
247
|
+
:::
|
|
248
|
+
|
|
249
|
+
## Bringing it all together
|
|
250
|
+
|
|
251
|
+
Sometimes a configuration file is a JavaScript or TypeScript file that imports
|
|
252
|
+
dependencies, but also contains configuration that needs to be parsed by a
|
|
253
|
+
plugin to find additional dependencies.
|
|
254
|
+
|
|
255
|
+
Let's take a look at this example Vite configuration file:
|
|
256
|
+
|
|
257
|
+
```ts title="vite.config.ts"
|
|
258
|
+
import { defineConfig } from 'vite';
|
|
259
|
+
import react from '@vitejs/plugin-react';
|
|
260
|
+
|
|
261
|
+
export default defineConfig(async ({ mode, command }) => {
|
|
262
|
+
return {
|
|
263
|
+
plugins: [react()],
|
|
264
|
+
test: {
|
|
265
|
+
setupFiles: ['./setup-tests.ts'],
|
|
266
|
+
environment: 'happy-dom',
|
|
267
|
+
coverage: {
|
|
268
|
+
provider: 'c8',
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
This file imports `vite` and `@vitejs/plugin-react` directly, but also
|
|
276
|
+
indirectly references the `happy-dom` and `@vitest/coverage-c8` packages.
|
|
277
|
+
|
|
278
|
+
The Vite plugin of Knip will **dynamically** load this configuration file and
|
|
279
|
+
parse the exported configuration. But it's not aware of the `vite` and
|
|
280
|
+
`@vitejs/plugin-react` imports. This is why such `config` files are also
|
|
281
|
+
automatically added as `entry` files for Knip to **statically** resolve the
|
|
282
|
+
`import` and `require` statements.
|
|
283
|
+
|
|
284
|
+
Additionally, `./setup-tests.ts` will be added as an `entry` file.
|
|
285
|
+
|
|
286
|
+
## Command-Line Arguments
|
|
287
|
+
|
|
288
|
+
Plugins may define the arguments where Knip should look for entry files,
|
|
289
|
+
configuration files and dependencies. We've already seen some examples above:
|
|
290
|
+
|
|
291
|
+
```sh
|
|
292
|
+
node --loader tsx scripts/deploy.ts
|
|
293
|
+
playwright test -c playwright.web.config.ts
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Please see [script parser][8] for more details.
|
|
297
|
+
|
|
298
|
+
## Summary
|
|
299
|
+
|
|
300
|
+
:::tip[Summary]
|
|
301
|
+
|
|
302
|
+
Plugins are configured with two distinct types of files:
|
|
303
|
+
|
|
304
|
+
- `config` files are dynamically loaded and parsed by the plugin
|
|
305
|
+
- `entry` files are added to the module graph
|
|
306
|
+
- Both can recursively lead to additional entry files, config files and
|
|
307
|
+
dependencies
|
|
308
|
+
|
|
309
|
+
:::
|
|
310
|
+
|
|
311
|
+
[1]: ../reference/plugins.md
|
|
312
|
+
[2]: ../guides/writing-a-plugin.md
|
|
313
|
+
[3]: #configuration-files
|
|
314
|
+
[4]: #entry-files
|
|
315
|
+
[5]: #command-line-arguments
|
|
316
|
+
[6]: ./entry-files.md
|
|
317
|
+
[7]: ../reference/plugins/eslint.md
|
|
318
|
+
[8]: ../features/script-parser.md
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Why use Knip?
|
|
3
|
+
sidebar:
|
|
4
|
+
order: 3
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The value of removing clutter is clear, but finding it manually is tedious. This
|
|
8
|
+
is where Knip comes in: comprehensive and accurate results at any scale.
|
|
9
|
+
|
|
10
|
+
:::tip[TL;DR]
|
|
11
|
+
|
|
12
|
+
Knip finds and fixes unused dependencies, exports and files.
|
|
13
|
+
|
|
14
|
+
Deep analysis from [fine-grained entry points][1] based on the actual frameworks
|
|
15
|
+
and tooling in [(mono)repos][2] for accurate and actionable results. Advanced
|
|
16
|
+
features for maximum coverage:
|
|
17
|
+
|
|
18
|
+
- [Custom module resolution][3]
|
|
19
|
+
- [Configuration file parsers][4]
|
|
20
|
+
- [Advanced shell script parser][5]
|
|
21
|
+
- [Built-in and custom compilers][6]
|
|
22
|
+
- [Auto-fix most issues][7]
|
|
23
|
+
|
|
24
|
+
:::
|
|
25
|
+
|
|
26
|
+
## Less is more
|
|
27
|
+
|
|
28
|
+
There are plenty of reasons to delete unused files, dependencies and "dead
|
|
29
|
+
code":
|
|
30
|
+
|
|
31
|
+
- Easier maintenance: things are easier to manage when there's less of it.
|
|
32
|
+
- Improved performance: startup time, build time and/or bundle size can be
|
|
33
|
+
negatively impacted when unused code, files and/or dependencies are included.
|
|
34
|
+
Relying on tree-shaking when bundling code helps, but it's not a silver
|
|
35
|
+
bullet.
|
|
36
|
+
- Easier onboarding: there should be no doubts about whether files, dependencies
|
|
37
|
+
and exports are actually in use or not. Especially for people new to the
|
|
38
|
+
project and/or taking over responsibilities this is harder to grasp.
|
|
39
|
+
- Prevent regressions: tools like TypeScript, ESLint and Prettier do all sorts
|
|
40
|
+
of checks and linting to report violations and prevent regressions. Knip does
|
|
41
|
+
the same for dependencies, exports and files that are obsolete.
|
|
42
|
+
- Keeping dead code around has a negative value on readability, as it can be
|
|
43
|
+
misleading and distracting. Even if it serves no purpose it will need to be
|
|
44
|
+
maintained (source: [Safe dead code removal → YAGNI][8]).
|
|
45
|
+
- Also see [Why are unused dependencies a problem?][9] and [Why are unused
|
|
46
|
+
exports a problem?][10].
|
|
47
|
+
|
|
48
|
+
## Automation
|
|
49
|
+
|
|
50
|
+
Code and dependency management is usually not the most exciting task for most of
|
|
51
|
+
us. Knip's mission is to automate finding clutter. This is such a tedious job if
|
|
52
|
+
you were to do it manually, and where would you even start? Knip applies many
|
|
53
|
+
techniques and heuristics to report what you need and save a lot of time.
|
|
54
|
+
|
|
55
|
+
:::tip
|
|
56
|
+
|
|
57
|
+
Knip not only finds clutter, it can also [remove clutter][7]!
|
|
58
|
+
|
|
59
|
+
Use Knip next to a linter like ESLint or Biome: after removing unused variables
|
|
60
|
+
inside files, Knip might find even more unused code. Rinse and repeat!
|
|
61
|
+
|
|
62
|
+
:::
|
|
63
|
+
|
|
64
|
+
## Comprehensive
|
|
65
|
+
|
|
66
|
+
You can use alternative tools that do the same. However, the advantage of a
|
|
67
|
+
strategy that addresses all of dependencies, exports and files is in their
|
|
68
|
+
synergy:
|
|
69
|
+
|
|
70
|
+
- Utilizing plugins to find their dependencies includes the capacity to find
|
|
71
|
+
additional entry and configuration files. This results in more resolved and
|
|
72
|
+
used files. Better coverage gives better insights into unused files and
|
|
73
|
+
exports.
|
|
74
|
+
- Analyzing more files reveals more unused exports and dependency usage,
|
|
75
|
+
refining the list of both unused and unlisted dependencies.
|
|
76
|
+
- This approach is amplified in a monorepo setting. In fact, files and internal
|
|
77
|
+
dependencies can recursively reference each other (across workspaces).
|
|
78
|
+
|
|
79
|
+
## Greenfield or Legacy
|
|
80
|
+
|
|
81
|
+
Installing Knip in greenfield projects ensures the project stays neat and tidy
|
|
82
|
+
from the start. Add it to your CI workflow and prevent any regressions from
|
|
83
|
+
entering the codebase.
|
|
84
|
+
|
|
85
|
+
:::tip
|
|
86
|
+
|
|
87
|
+
Use Knip in a CI environment to prevent future regressions.
|
|
88
|
+
|
|
89
|
+
:::
|
|
90
|
+
|
|
91
|
+
In large and/or legacy projects, Knip may report false positives and require
|
|
92
|
+
some configuration. It aims to be a great assistant when cleaning up parts of
|
|
93
|
+
the project or doing large refactors. Even a list of results with a few false
|
|
94
|
+
positives is many times better and faster than if you were to do it manually.
|
|
95
|
+
|
|
96
|
+
## Unobtrusive
|
|
97
|
+
|
|
98
|
+
Knip does not introduce new syntax for you to learn. This may sound obvious, but
|
|
99
|
+
consider comments like the following:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
// eslint-disable-next-line
|
|
103
|
+
// prettier-ignore
|
|
104
|
+
// @ts-expect-error
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Maybe you wonder why Knip does not have similar comments like `// knip-ignore`
|
|
108
|
+
so you can get rid of false positives? A variety of reasons:
|
|
109
|
+
|
|
110
|
+
1. A false positive may be a bug in Knip, and should be reported, not dismissed.
|
|
111
|
+
2. Instead of proprietary comments, use [standardized annotations][11] that also
|
|
112
|
+
serve as documentation.
|
|
113
|
+
3. In the event you want to remove Knip, just uninstall `knip` without having to
|
|
114
|
+
remove useless comments scattered throughout the codebase.
|
|
115
|
+
|
|
116
|
+
Tip: use `@lintignore` in JSDoc comments, so other linters can use the same.
|
|
117
|
+
|
|
118
|
+
[1]: ./entry-files.md
|
|
119
|
+
[2]: ../features/monorepos-and-workspaces.md
|
|
120
|
+
[3]: ../reference/faq.md#why-doesnt-knip-use-an-existing-module-resolver
|
|
121
|
+
[4]: ./plugins.md#configuration-files
|
|
122
|
+
[5]: ../features/script-parser.md
|
|
123
|
+
[6]: ../features/compilers.md
|
|
124
|
+
[7]: ../features/auto-fix.mdx
|
|
125
|
+
[8]: https://jfmengels.net/safe-dead-code-removal/#yagni-you-arent-gonna-need-it
|
|
126
|
+
[9]: ../typescript/unused-dependencies.md#why-are-unused-dependencies-a-problem
|
|
127
|
+
[10]: ../typescript/unused-exports.md#why-are-unused-exports-a-problem
|
|
128
|
+
[11]: ../reference/jsdoc-tsdoc-tags.md
|