Skip to content

Commit ef999c4

Browse files
committedDec 15, 2023
Edit docs
1 parent b1c28e6 commit ef999c4

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed
 

‎packages/docs/src/content/docs/blog/slim-down-to-speed-up.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ NS.referencedExport();
236236
Previously, Knip used `findReferences()` to "trace back" the usage of the
237237
exported `referencedExport`.
238238

239-
Yet in v4, during AST traversal of `index.ts` , Knip sees that
240-
`referencedExport` is attached to the imported `NS` namespace, and stores that
241-
as an imported identifier of `namespace.ts`. When matching exports against
242-
imports, this lookup comes at no extra cost.
239+
The gist of the optimization is to pre-determine all imports and exports. During
240+
AST traversal of `index.ts` , Knip sees that `referencedExport` is attached to
241+
the imported `NS` namespace, and stores that as an imported identifier of
242+
`namespace.ts`. When matching exports against imports, this lookup comes at no
243+
extra cost. Additionally, this can be stored as strings, so it can be serialized
244+
too. And that means it can be cached.
243245

244246
Knip already did this for trivial cases as shown in the first example of this
245247
article. This has now been extended to cover more patterns. This is also what
@@ -260,5 +262,7 @@ false positive that wasn't there in v3, please [report this][2].
260262
npm install -D knip@canary
261263
```
262264

265+
Remember, Knip it before you ship it! Have a great day ☀️
266+
263267
[1]: https://github.com/remix-run/remix
264268
[2]: https://github.com/webpro/knip/issues

‎packages/docs/src/content/docs/features/auto-fix.mdx

+37
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,43 @@ Use `--fix-type` to fix only specific issue types (`exports`, `types` and/or
3030
knip --fix-type exports,types
3131
```
3232

33+
## Example Result
34+
35+
The `export` keyword for unused exports is removed:
36+
37+
```diff title="file.js"
38+
-export default class MyClass {}
39+
+class MyClass {}
40+
```
41+
42+
Note that also the `default` keyword was removed here.
43+
44+
Sometimes a line can be completely removed safely:
45+
46+
```diff title="file.js"
47+
-module.exports.UNUSED = 1;
48+
-module.exports['ACCESS'] = 1;
49+
+
50+
+
51+
```
52+
53+
Unused dependencies are removed from `package.json`:
54+
55+
```diff title="package.json"
56+
{
57+
"name": "my-package",
58+
"dependencies": {
59+
- "rimraf": "*",
60+
- "unused-dependency": "*"
61+
+ "rimraf": "*"
62+
},
63+
- "devDependencies": {
64+
- "unreferenced-package": "5.3.3"
65+
- }
66+
+ "devDependencies": {}
67+
}
68+
```
69+
3370
## Post-fix
3471

3572
- You may want to run tools like `eslint --fix` or `prettier --write` to fix the

‎packages/docs/src/content/docs/features/compilers.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ this is not a real compiler, but in many cases it's enough to extract and return
107107
the contents of the `<script>` elements as a TypeScript module.
108108

109109
Knip does not have a Vue plugin, mainly because the entry file `src/main.ts` is
110-
already covered by the default entry patterns.
110+
already covered by the default entry patterns. You may need to add e.g.
111+
`src/App.vue` as an entry file.
111112

112113
### Svelte
113114

‎packages/docs/src/content/docs/reference/configuration.md

+10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Example:
7777
}
7878
```
7979

80+
Actual regular expressions can be used in dynamic configurations.
81+
8082
## `ignoreDependencies`
8183

8284
Array of package names to exclude from the report. Regular expressions allowed.
@@ -88,6 +90,14 @@ Example:
8890
}
8991
```
9092

93+
Actual regular expressions can be used in dynamic configurations:
94+
95+
```ts title="knip.ts"
96+
export default {
97+
ignoreDependencies: [/@org\/.*/, /^lib-.*/],
98+
};
99+
```
100+
91101
## `ignoreExportsUsedInFile`
92102

93103
In files with multiple exports, some of them might be used only internally. If

0 commit comments

Comments
 (0)
Please sign in to comment.