knip 0.12.0 → 0.12.2
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/README.md +115 -75
- package/dist/cli.js +1 -2
- package/dist/help.js +1 -2
- package/dist/index.js +1 -4
- package/dist/runner.js +4 -4
- package/dist/types.d.ts +0 -4
- package/dist/util/parseArgs.d.ts +0 -1
- package/dist/util/parseArgs.js +0 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -17,12 +17,11 @@ things that can be removed?
|
|
|
17
17
|
The dots don't connect themselves. This is where Knip comes in:
|
|
18
18
|
|
|
19
19
|
- [x] Finds **unused files, dependencies and exports**.
|
|
20
|
-
- [x] Finds dependencies not listed in `package.json`.
|
|
21
|
-
- [x]
|
|
22
|
-
- [x] Supports JavaScript
|
|
23
|
-
- [x]
|
|
24
|
-
- [x]
|
|
25
|
-
- [x] Features multiple [reporters][1] and supports [custom reporters][2].
|
|
20
|
+
- [x] Finds used dependencies not listed in `package.json`.
|
|
21
|
+
- [x] Finds duplicate exports.
|
|
22
|
+
- [x] Supports JavaScript (without `tsconfig.json`, or TypeScript `allowJs: true`).
|
|
23
|
+
- [x] Features multiple [reporters][1] and supports [custom reporters][2] (think JSON and `CODEOWNERS`)
|
|
24
|
+
- [x] Run Knip as part of your CI environment to detect issues and prevent regressions.
|
|
26
25
|
|
|
27
26
|
Knip really shines in larger projects. A little bit of configuration will pay off, I promise. A comparison with similar
|
|
28
27
|
tools answers the question [why another unused file/dependency/export finder?][3]
|
|
@@ -32,11 +31,27 @@ Knip is a fresh take on keeping your projects clean & tidy!
|
|
|
32
31
|
[![An orange cow with scissors, Van Gogh style][5]][4] <sup>_“An orange cow with scissors, Van Gogh style” - generated
|
|
33
32
|
with OpenAI_</sup>
|
|
34
33
|
|
|
34
|
+
## Roadmap
|
|
35
|
+
|
|
36
|
+
Please report any false positives by [opening an issue in this repo][6]. Bonus points for adding a public repository or
|
|
37
|
+
opening a pull request with a directory and example files in `test/fixtures`. Correctness and bug fixes have priority
|
|
38
|
+
over new features:
|
|
39
|
+
|
|
40
|
+
### Upcoming Features
|
|
41
|
+
|
|
42
|
+
- [ ] Find unused members of classes and enums (#11 and #20).
|
|
43
|
+
- [ ] Custom dependency resolvers: find dependencies used in npm scripts.
|
|
44
|
+
- [ ] Custom dependency resolvers: find unused and unlisted plugins for Webpack, ESLint & Babel, etc. (#7)
|
|
45
|
+
- [ ] Smart default configurations and more fine-grained configuration options.
|
|
46
|
+
- [ ] Full support for monorepos (partial [monorepos support][7] with `--dir` exists).
|
|
47
|
+
- [ ] Fix issues: remove `export` keyword, uninstall unused dependencies, delete files (like `--fix` of ESLint).
|
|
48
|
+
- [ ] Add more reporters and report customization options (#3).
|
|
49
|
+
|
|
35
50
|
## Installation
|
|
36
51
|
|
|
37
52
|
npm install -D knip
|
|
38
53
|
|
|
39
|
-
Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.
|
|
54
|
+
Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.6. Knip is _cutting edge!_
|
|
40
55
|
|
|
41
56
|
## Usage
|
|
42
57
|
|
|
@@ -67,7 +82,7 @@ Knip works by creating two sets of files:
|
|
|
67
82
|
3. The subset of project files that is not production code will be reported as unused files (in red).
|
|
68
83
|
4. Then the production code (in blue) will be analyzed for unused exports.
|
|
69
84
|
|
|
70
|
-
![How it works][
|
|
85
|
+
![How it works][8]
|
|
71
86
|
|
|
72
87
|
## Options
|
|
73
88
|
|
|
@@ -88,7 +103,6 @@ Knip works by creating two sets of files:
|
|
|
88
103
|
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
89
104
|
--reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
|
|
90
105
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
91
|
-
--jsdoc Enable JSDoc parsing, with options: public
|
|
92
106
|
--debug Show debug output
|
|
93
107
|
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
94
108
|
--performance Measure running time of expensive functions and display stats table
|
|
@@ -99,20 +113,12 @@ Knip works by creating two sets of files:
|
|
|
99
113
|
|
|
100
114
|
$ knip
|
|
101
115
|
$ knip --dir packages/client --include files
|
|
102
|
-
$ knip -c ./knip.js --reporter compact
|
|
116
|
+
$ knip -c ./knip.js --reporter compact
|
|
103
117
|
$ knip --ignore 'lib/**/*.ts' --ignore build
|
|
104
118
|
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
105
119
|
|
|
106
120
|
More info: https://github.com/webpro/knip
|
|
107
121
|
|
|
108
|
-
## Performance
|
|
109
|
-
|
|
110
|
-
🚀 Knip is considerably faster when only the `files` and/or `duplicates` types are included. Finding unused exports
|
|
111
|
-
requires deeper analysis (`exports`, `nsExports`, `types`, `nsTypes`). The following example commands do the same:
|
|
112
|
-
|
|
113
|
-
knip --include files --include duplicates
|
|
114
|
-
knip --include files,duplicates
|
|
115
|
-
|
|
116
122
|
## Reading the report
|
|
117
123
|
|
|
118
124
|
After analyzing all the files resolved from the `entryFiles` against the `projectFiles`, the report contains the
|
|
@@ -125,7 +131,9 @@ following types of issues:
|
|
|
125
131
|
- `nsExports` - Unused exports in namespaces: did not find direct references to this exported variable (2)
|
|
126
132
|
- `types` - Unused types: did not find references to this exported type
|
|
127
133
|
- `nsTypes` - Unused types in namespaces: did not find direct references to this exported variable (2)
|
|
128
|
-
- `duplicates` - Duplicate exports: the same thing is exported more than once with different names
|
|
134
|
+
- `duplicates` - Duplicate exports: the same thing is exported more than once with different names
|
|
135
|
+
|
|
136
|
+
Notes:
|
|
129
137
|
|
|
130
138
|
1. This includes dependencies that could not be resolved. For instance, what does `unresolved/dir/module` mean?
|
|
131
139
|
- To target something in the (missing) `node_modules/unresolved` package?
|
|
@@ -147,14 +155,45 @@ As always, make sure to backup files or use Git before deleting files or making
|
|
|
147
155
|
- Unused exports and types: remove the `export` keyword in front of unused exports. Then you (or tools such as
|
|
148
156
|
TypeScript language services in VS Code and/or ESLint) can see whether the variable or type is used within the same
|
|
149
157
|
file. If this is not the case, it can be removed.
|
|
158
|
+
- Duplicate exports can be removed to export only once, make sure to import that everywhere.
|
|
150
159
|
|
|
151
160
|
🔁 Repeat the process to reveal new unused files and exports. Sometimes it's so liberating to remove things!
|
|
152
161
|
|
|
153
|
-
##
|
|
162
|
+
## Performance
|
|
163
|
+
|
|
164
|
+
🚀 Knip finds issues of type `files`, `dependencies`, `unlisted` and `duplicates` very fast. Finding unused exports
|
|
165
|
+
requires deeper analysis (`exports`, `nsExports`, `types`, `nsTypes`). The following example commands do the same:
|
|
166
|
+
|
|
167
|
+
knip --include files --include dependencies
|
|
168
|
+
knip --include files,dependencies
|
|
169
|
+
|
|
170
|
+
Use `--performance` to see where most of the time is spent.
|
|
171
|
+
|
|
172
|
+
## Configuration
|
|
173
|
+
|
|
174
|
+
### Libraries versus Applications
|
|
175
|
+
|
|
176
|
+
Libraries and applications are identical when it comes to files and dependencies: whatever is unused should be removed.
|
|
177
|
+
Yet libraries usually have exports meant to be used by other libraries or applications. Such public variables and types
|
|
178
|
+
in libraries can be marked with the JSDoc `@public` tag:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
/**
|
|
182
|
+
* Merge two objects.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
export const merge = function () {};
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Knip does not report public exports and types as unused.
|
|
191
|
+
|
|
192
|
+
### Production versus non-production code
|
|
154
193
|
|
|
155
194
|
Feels like you're getting too many false positives? Let's talk about `entryFiles` and `projectFiles`.
|
|
156
195
|
|
|
157
|
-
|
|
196
|
+
#### Production code
|
|
158
197
|
|
|
159
198
|
The default configuration for Knip is very strict and targets production code. Non-production files such as tests should
|
|
160
199
|
not be part of the `entryFiles` and `projectFiles`. Here's why: test and other non-production files often import
|
|
@@ -166,7 +205,7 @@ production files, which will prevent the production files from being reported as
|
|
|
166
205
|
|
|
167
206
|
This will ensure Knip understands what production code can be removed.
|
|
168
207
|
|
|
169
|
-
|
|
208
|
+
#### Non-production code
|
|
170
209
|
|
|
171
210
|
Non-production code includes files such as unit tests, end-to-end tests, tooling, scripts, Storybook stories, etc. Think
|
|
172
211
|
of it the same way as the convention to split `dependencies` and `devDependencies` in `package.json`.
|
|
@@ -245,9 +284,8 @@ To analyze the packages separately, using the matching pattern from the configur
|
|
|
245
284
|
|
|
246
285
|
#### Connected projects
|
|
247
286
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
`package.json`.
|
|
287
|
+
Let's take another example Nx project configuration using Next.js, Jest and Storybook, which has multiple apps and libs.
|
|
288
|
+
They are not published separately and don't have their own `package.json`.
|
|
251
289
|
|
|
252
290
|
This configuration file can also be a JavaScript file, which allows to add logic and/or comments (e.g. `knip.js`):
|
|
253
291
|
|
|
@@ -278,10 +316,10 @@ configuration can be tweaked further to the project structure.
|
|
|
278
316
|
|
|
279
317
|
Knip provides the following built-in reporters:
|
|
280
318
|
|
|
281
|
-
- [`json`]
|
|
282
|
-
- [`symbol`]
|
|
283
|
-
- [`compact`]
|
|
284
|
-
- [`codeowners`]
|
|
319
|
+
- [`json`][9]
|
|
320
|
+
- [`symbol`][10] (default)
|
|
321
|
+
- [`compact`][11]
|
|
322
|
+
- [`codeowners`][12]
|
|
285
323
|
|
|
286
324
|
### Custom Reporters
|
|
287
325
|
|
|
@@ -336,38 +374,31 @@ per file like this:
|
|
|
336
374
|
]
|
|
337
375
|
```
|
|
338
376
|
|
|
339
|
-
The keys match the [known issue types]
|
|
377
|
+
The keys match the [known issue types][13].
|
|
340
378
|
|
|
341
379
|
#### Usage Ideas
|
|
342
380
|
|
|
343
|
-
Use tools like [miller]
|
|
344
|
-
the JSON and render a table in the terminal.
|
|
381
|
+
Use tools like [miller][14] or [jtbl][15] to consume the JSON and render a table in the terminal.
|
|
345
382
|
|
|
346
383
|
##### Table
|
|
347
384
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
src/
|
|
352
|
-
src/ProductsList.tsx @org/team false - - ProductDetail -
|
|
353
|
-
```
|
|
385
|
+
$ npx knip --reporter json | mlr --ijson --opprint --no-auto-flatten cat
|
|
386
|
+
file owners files unlisted exports types duplicates
|
|
387
|
+
src/Registration.tsx @org/owner true react lowercaseFirstLetter, RegistrationBox RegistrationServices, RegistrationAction Registration, default
|
|
388
|
+
src/ProductsList.tsx @org/team false - - ProductDetail -
|
|
354
389
|
|
|
355
390
|
##### Markdown Table
|
|
356
391
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
|
360
|
-
|
|
|
361
|
-
| src/
|
|
362
|
-
| src/ProductsList.tsx | @org/team | false | |
|
|
363
|
-
```
|
|
392
|
+
$ npx knip --reporter json | mlr --ijson --omd --no-auto-flatten cat
|
|
393
|
+
| file | owners | files | duplicates |
|
|
394
|
+
| --- | --- | --- | --- |
|
|
395
|
+
| src/Registration.tsx | @org/owner | true | Registration, default |
|
|
396
|
+
| src/ProductsList.tsx | @org/team | false | |
|
|
364
397
|
|
|
365
398
|
Include specific issue types and/or replace the `cat` command with `put` for clean output:
|
|
366
399
|
|
|
367
|
-
|
|
368
|
-
npx knip --
|
|
369
|
-
npx knip --reporter json | mlr --ijson --omd --no-auto-flatten put 'for (e in $*) { if(is_array($[e])) { $[e] = joinv($[e], ", ") } }'
|
|
370
|
-
```
|
|
400
|
+
npx knip --include files,duplicates --reporter json | mlr --ijson --opprint --no-auto-flatten put 'for (e in $*) { if(is_array($[e])) { $[e] = joinv($[e], ", ") } }'
|
|
401
|
+
npx knip --reporter json | mlr --ijson --omd --no-auto-flatten put 'for (e in $*) { if(is_array($[e])) { $[e] = joinv($[e], ", ") } }'
|
|
371
402
|
|
|
372
403
|
### More Output Examples
|
|
373
404
|
|
|
@@ -464,20 +495,20 @@ collect the various issues in one go?
|
|
|
464
495
|
|
|
465
496
|
This table is a work in progress, but here's a first impression. Based on their docs (please report any mistakes):
|
|
466
497
|
|
|
467
|
-
| Feature | **knip** | [depcheck][
|
|
468
|
-
| --------------------------------- | :------: |
|
|
469
|
-
| Unused files | ✅ | -
|
|
470
|
-
| Unused dependencies | ✅ |
|
|
471
|
-
| Unlisted dependencies | ✅ |
|
|
472
|
-
| [Custom dependency resolvers][
|
|
473
|
-
| Unused exports | ✅ | -
|
|
474
|
-
| Duplicate exports | ✅ | -
|
|
475
|
-
| Search namespaces | ✅ | -
|
|
476
|
-
| Custom reporters | ✅ | -
|
|
477
|
-
|
|
|
478
|
-
| Configure entry files | ✅ |
|
|
479
|
-
| [Support monorepos][
|
|
480
|
-
| ESLint plugin available | - | -
|
|
498
|
+
| Feature | **knip** | [depcheck][16] | [unimported][17] | [ts-unused-exports][18] | [ts-prune][19] | [find-unused-exports][20] |
|
|
499
|
+
| --------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: | :-----------------------: |
|
|
500
|
+
| Unused files | ✅ | - | ✅ | - | - | - |
|
|
501
|
+
| Unused dependencies | ✅ | ✅ | ✅ | - | - | - |
|
|
502
|
+
| Unlisted dependencies | ✅ | ✅ | ✅ | - | - | - |
|
|
503
|
+
| [Custom dependency resolvers][21] | ❌ | ✅ | ❌ | - | - | - |
|
|
504
|
+
| Unused exports | ✅ | - | - | ✅ | ✅ | ✅ |
|
|
505
|
+
| Duplicate exports | ✅ | - | - | ❌ | ❌ | ❌ |
|
|
506
|
+
| Search namespaces | ✅ | - | - | ✅ | ❌ | ❌ |
|
|
507
|
+
| Custom reporters | ✅ | - | - | - | - | - |
|
|
508
|
+
| JavaScript support | ✅ | ✅ | ✅ | - | - | ✅ |
|
|
509
|
+
| Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
|
|
510
|
+
| [Support monorepos][22] | 🟠 | - | - | - | - | - |
|
|
511
|
+
| ESLint plugin available | - | - | - | ✅ | - | - |
|
|
481
512
|
|
|
482
513
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
483
514
|
|
|
@@ -492,7 +523,8 @@ directory of a monorepo is nice for DX. But Knip will need some help to find it
|
|
|
492
523
|
`eslint-plugin-cypress` _dependency_. Or see it is not listed in `package.json`. Or that the dependency is still listed,
|
|
493
524
|
but no longer in use. Many popular projects reference plugins in similar ways, such as Babel, Webpack and Storybook.
|
|
494
525
|
|
|
495
|
-
Big compliments to [depcheck][
|
|
526
|
+
Big compliments to [depcheck][23] which already does this! They call this "specials". This is on [Knip's roadmap][24],
|
|
527
|
+
as well, with the additional ambition to also find used dependencies that are not listed in `package.json`.
|
|
496
528
|
|
|
497
529
|
unimported is strict in this regard and works based on production files and `dependencies`, so does not have custom
|
|
498
530
|
dependency resolvers which are usually only needed for `devDependencies`.
|
|
@@ -514,14 +546,22 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
|
|
|
514
546
|
[3]: #really-another-unused-filedependencyexport-finder
|
|
515
547
|
[4]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
|
|
516
548
|
[5]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
|
|
517
|
-
[6]:
|
|
518
|
-
[7]:
|
|
519
|
-
[8]:
|
|
520
|
-
[9]:
|
|
521
|
-
[10]:
|
|
522
|
-
[11]:
|
|
523
|
-
[12]: #
|
|
524
|
-
[13]: #
|
|
525
|
-
[14]:
|
|
526
|
-
[15]: https://github.com/
|
|
527
|
-
[16]: https://github.com/
|
|
549
|
+
[6]: https://github.com/webpro/knip/issues
|
|
550
|
+
[7]: #monorepos
|
|
551
|
+
[8]: ./assets/how-it-works.drawio.svg
|
|
552
|
+
[9]: #json
|
|
553
|
+
[10]: #symbol-default
|
|
554
|
+
[11]: #compact
|
|
555
|
+
[12]: #code-owners
|
|
556
|
+
[13]: #reading-the-report
|
|
557
|
+
[14]: https://github.com/johnkerl/miller
|
|
558
|
+
[15]: https://github.com/kellyjonbrazil/jtbl
|
|
559
|
+
[16]: https://github.com/depcheck/depcheck
|
|
560
|
+
[17]: https://github.com/smeijer/unimported
|
|
561
|
+
[18]: https://github.com/pzavolinsky/ts-unused-exports
|
|
562
|
+
[19]: https://github.com/nadeesha/ts-prune
|
|
563
|
+
[20]: https://github.com/jaydenseric/find-unused-exports
|
|
564
|
+
[21]: #custom-dependency-resolvers
|
|
565
|
+
[22]: #monorepos-1
|
|
566
|
+
[23]: https://github.com/depcheck/depcheck#special
|
|
567
|
+
[24]: #roadmap
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { printHelp } from './help.js';
|
|
|
6
6
|
import reporters from './reporters/index.js';
|
|
7
7
|
import { ConfigurationError } from './util/errors.js';
|
|
8
8
|
import { measure } from './util/performance.js';
|
|
9
|
-
const { values: { help, dir, config: configFilePath, tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'include-entry-files': isIncludeEntryFiles = false, 'no-progress': noProgress = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', 'max-issues': maxIssues = '0',
|
|
9
|
+
const { values: { help, dir, config: configFilePath, tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'include-entry-files': isIncludeEntryFiles = false, 'no-progress': noProgress = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', 'max-issues': maxIssues = '0', debug: isDebug = false, 'debug-level': debugLevel = '1', }, } = parsedArgs;
|
|
10
10
|
if (help) {
|
|
11
11
|
printHelp();
|
|
12
12
|
process.exit(0);
|
|
@@ -29,7 +29,6 @@ const run = async () => {
|
|
|
29
29
|
isIncludeEntryFiles,
|
|
30
30
|
isDev,
|
|
31
31
|
isShowProgress,
|
|
32
|
-
jsDoc,
|
|
33
32
|
debug: {
|
|
34
33
|
isEnabled: isDebug,
|
|
35
34
|
level: isDebug ? Number(debugLevel) : 0,
|
package/dist/help.js
CHANGED
|
@@ -15,7 +15,6 @@ Options:
|
|
|
15
15
|
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
16
16
|
--reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
|
|
17
17
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
18
|
-
--jsdoc Enable JSDoc parsing, with options: public
|
|
19
18
|
--debug Show debug output
|
|
20
19
|
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
21
20
|
--performance Measure running time of expensive functions and display stats table
|
|
@@ -26,7 +25,7 @@ Examples:
|
|
|
26
25
|
|
|
27
26
|
$ knip
|
|
28
27
|
$ knip --dir packages/client --include files
|
|
29
|
-
$ knip -c ./knip.js --reporter compact
|
|
28
|
+
$ knip -c ./knip.js --reporter compact
|
|
30
29
|
$ knip --ignore 'lib/**/*.ts' --ignore build
|
|
31
30
|
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
32
31
|
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { ConfigurationError } from './util/errors.js';
|
|
|
9
9
|
import { debugLogObject, debugLogFiles, debugLogSourceFiles } from './util/debug.js';
|
|
10
10
|
import { getMessageUpdater } from './progress.js';
|
|
11
11
|
export const main = async (unresolvedConfiguration) => {
|
|
12
|
-
const { cwd, workingDir, configFilePath: configFilePathArg, tsConfigFilePath: tsConfigFilePathArg, include, exclude, ignore, gitignore, isIncludeEntryFiles, isDev, isShowProgress,
|
|
12
|
+
const { cwd, workingDir, configFilePath: configFilePathArg, tsConfigFilePath: tsConfigFilePathArg, include, exclude, ignore, gitignore, isIncludeEntryFiles, isDev, isShowProgress, debug, } = unresolvedConfiguration;
|
|
13
13
|
const updateMessage = getMessageUpdater(unresolvedConfiguration);
|
|
14
14
|
debugLogObject(debug, 1, 'Unresolved configuration', unresolvedConfiguration);
|
|
15
15
|
updateMessage('Reading configuration and manifest files...');
|
|
@@ -103,9 +103,6 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
103
103
|
isDev: Boolean(resolvedConfig?.dev),
|
|
104
104
|
tsConfigPathGlobs: tsConfigPathGlobs,
|
|
105
105
|
isShowProgress,
|
|
106
|
-
jsDocOptions: {
|
|
107
|
-
isReadPublicTag: jsDoc.includes('public'),
|
|
108
|
-
},
|
|
109
106
|
debug,
|
|
110
107
|
};
|
|
111
108
|
const { issues, counters } = await findIssues(config);
|
package/dist/runner.js
CHANGED
|
@@ -6,7 +6,7 @@ import { getDependencyAnalyzer } from './util/dependencies.js';
|
|
|
6
6
|
import { debugLogSourceFiles } from './util/debug.js';
|
|
7
7
|
import { getCountersUpdater, getMessageUpdater } from './progress.js';
|
|
8
8
|
export async function findIssues(configuration) {
|
|
9
|
-
const { workingDir, report,
|
|
9
|
+
const { workingDir, report, debug } = configuration;
|
|
10
10
|
const { entryFiles, productionFiles, projectFiles, isIncludeEntryFiles } = configuration;
|
|
11
11
|
const { manifestPath } = configuration;
|
|
12
12
|
const updateMessage = getMessageUpdater(configuration);
|
|
@@ -90,7 +90,7 @@ export async function findIssues(configuration) {
|
|
|
90
90
|
if (!report.exports && !type)
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
if (
|
|
93
|
+
if (ts.getJSDocPublicTag(declaration.compilerNode))
|
|
94
94
|
return;
|
|
95
95
|
let identifier;
|
|
96
96
|
let fakeIdentifier;
|
|
@@ -111,10 +111,10 @@ export async function findIssues(configuration) {
|
|
|
111
111
|
declaration.isKind(ts.SyntaxKind.TypeAliasDeclaration) ||
|
|
112
112
|
declaration.isKind(ts.SyntaxKind.InterfaceDeclaration) ||
|
|
113
113
|
declaration.isKind(ts.SyntaxKind.EnumDeclaration)) {
|
|
114
|
-
identifier = declaration.
|
|
114
|
+
identifier = declaration.getFirstChildByKind(ts.SyntaxKind.Identifier);
|
|
115
115
|
}
|
|
116
116
|
else if (declaration.isKind(ts.SyntaxKind.PropertyAccessExpression)) {
|
|
117
|
-
identifier = declaration.
|
|
117
|
+
identifier = declaration.getLastChildByKind(ts.SyntaxKind.Identifier);
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
120
120
|
identifier = declaration.getFirstDescendantByKind(ts.SyntaxKind.Identifier);
|
package/dist/types.d.ts
CHANGED
|
@@ -46,7 +46,6 @@ export declare type UnresolvedConfiguration = {
|
|
|
46
46
|
isIncludeEntryFiles: boolean;
|
|
47
47
|
isDev: boolean;
|
|
48
48
|
isShowProgress: boolean;
|
|
49
|
-
jsDoc: string[];
|
|
50
49
|
debug: {
|
|
51
50
|
isEnabled: boolean;
|
|
52
51
|
level: number;
|
|
@@ -67,9 +66,6 @@ export declare type Configuration = {
|
|
|
67
66
|
isDev: boolean;
|
|
68
67
|
tsConfigPathGlobs: string[];
|
|
69
68
|
isShowProgress: boolean;
|
|
70
|
-
jsDocOptions: {
|
|
71
|
-
isReadPublicTag: boolean;
|
|
72
|
-
};
|
|
73
69
|
debug: {
|
|
74
70
|
isEnabled: boolean;
|
|
75
71
|
level: number;
|
package/dist/util/parseArgs.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ declare const _default: {
|
|
|
14
14
|
'max-issues': string | undefined;
|
|
15
15
|
reporter: string | undefined;
|
|
16
16
|
'reporter-options': string | undefined;
|
|
17
|
-
jsdoc: string[] | undefined;
|
|
18
17
|
debug: boolean | undefined;
|
|
19
18
|
'debug-level': string | undefined;
|
|
20
19
|
performance: boolean | undefined;
|
package/dist/util/parseArgs.js
CHANGED
|
@@ -15,7 +15,6 @@ export default parseArgs({
|
|
|
15
15
|
'max-issues': { type: 'string' },
|
|
16
16
|
reporter: { type: 'string' },
|
|
17
17
|
'reporter-options': { type: 'string' },
|
|
18
|
-
jsdoc: { type: 'string', multiple: true },
|
|
19
18
|
debug: { type: 'boolean' },
|
|
20
19
|
'debug-level': { type: 'string' },
|
|
21
20
|
performance: { type: 'boolean' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"find",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
27
|
"scripts": {
|
|
28
|
-
"knip": "node ./dist/cli.js
|
|
28
|
+
"knip": "node ./dist/cli.js",
|
|
29
29
|
"test": "globstar -- node --loader tsx --test \"test/*.spec.ts\"",
|
|
30
30
|
"watch": "tsc --watch",
|
|
31
31
|
"build": "rm -rf dist && tsc",
|
|
32
32
|
"prepublishOnly": "npm test && npm run build && npm run knip",
|
|
33
|
+
"format": "remark README.md -o",
|
|
33
34
|
"release": "release-it"
|
|
34
35
|
},
|
|
35
36
|
"files": [
|
|
@@ -55,6 +56,8 @@
|
|
|
55
56
|
"globstar": "1.0.0",
|
|
56
57
|
"prettier": "2.7.1",
|
|
57
58
|
"release-it": "15.5.0",
|
|
59
|
+
"remark-cli": "11.0.0",
|
|
60
|
+
"remark-preset-webpro": "0.0.1",
|
|
58
61
|
"tsx": "3.11.0",
|
|
59
62
|
"type-fest": "3.1.0",
|
|
60
63
|
"typescript": "4.8.4"
|
|
@@ -64,6 +67,11 @@
|
|
|
64
67
|
"release": true
|
|
65
68
|
}
|
|
66
69
|
},
|
|
70
|
+
"remarkConfig": {
|
|
71
|
+
"plugins": [
|
|
72
|
+
"preset-webpro"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
67
75
|
"engines": {
|
|
68
76
|
"node": ">=16.17.0 <17 || >=18.6.0"
|
|
69
77
|
},
|