Skip to content

Commit

Permalink
Update comparison page + auto-format
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Dec 11, 2024
1 parent dbb153d commit e6340b0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ knip --include exports,types,nsExports,nsTypes

Use `knip --exports` to also include class and enum members.

### ts-remove-unused
### tsr

> Remove unused code from your TypeScript Project
[ts-remove-unused][8] removes unused exports, and works based on a single
`tsconfig.json` file (`includes` and `excludes`) and requires no configuration.
It removes the `export` keyword or the whole export declaration.
[tsr][8] (previously `ts-remove-unused`) removes unused exports, and works based
on a single `tsconfig.json` file (`includes` and `excludes`) and requires no
configuration. It removes the `export` keyword or the whole export declaration.

## Related projects

Expand All @@ -102,8 +102,9 @@ Additional alternative and related projects include:
- [DepClean][10]
- [dependency-check][11]
- [find-unused-exports][12]
- [npm-check][13]
- [renoma][14]
- [next-unused][13]
- [npm-check][14]
- [renoma][15]

[1]: ./why-use-knip.md#comprehensive
[2]: ../features/monorepos-and-workspaces.md
Expand All @@ -112,10 +113,11 @@ Additional alternative and related projects include:
[5]: https://github.com/smeijer/unimported
[6]: https://github.com/nadeesha/ts-prune
[7]: https://github.com/pzavolinsky/ts-unused-exports
[8]: https://github.com/line/ts-remove-unused
[8]: https://github.com/line/tsr
[9]: https://github.com/M-Izadmehr/deadfile
[10]: https://github.com/mysteryven/depclean
[11]: https://github.com/dependency-check-team/dependency-check
[12]: https://github.com/jaydenseric/find-unused-exports
[13]: https://github.com/dylang/npm-check
[14]: https://github.com/bluwy/renoma
[13]: https://github.com/pacocoursey/next-unused
[14]: https://github.com/dylang/npm-check
[15]: https://github.com/bluwy/renoma
49 changes: 24 additions & 25 deletions packages/docs/src/content/docs/guides/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,33 @@ complicated". Knip and documentation are always a work in progress.

If it doesn't come your way at the first try, please understand this also shows
the dynamic and innovative nature of the ecosystem. Often only small changes go
a long way towards success. Consider
[opening an issue](https://github.com/webpro-nl/knip/issues/new/choose) and/or
[ask away on Discord](https://discord.gg/r5uXTtbTpc). With the help of the
community (that's you!) we can improve Knip for everyone and make project
maintenance easier and more fun!
a long way towards success. Consider [opening an issue][5] and/or [ask away on
Discord][6]. With the help of the community (that's you!) we can improve Knip
for everyone and make project maintenance easier and more fun!

:::

## Lint issues reported by Knip

Knip reports lint issues in your codebase. See [handling issues][5] to deal with
Knip reports lint issues in your codebase. See [handling issues][7] to deal with
the reported issues.

If Knip reports false positives and you're considering filing a GitHub issue,
please do! It'll make Knip better for everyone. Please read [issue
reproduction][6] first.
reproduction][8] first.

Exit code 1 indicates a successful run, but lint issues were found.

## Exceptions thrown by Knip

Knip may throw an exception, resulting in an unsuccessful run.

See [known issues][7] as it may be listed there and a workaround may be
See [known issues][9] as it may be listed there and a workaround may be
available. If it isn't clear what's throwing the exception, try another run with
`--debug` to locate the cause of the issue with more details.

If Knip throws an exception and you're considering filing a GitHub issue, please
do! It'll make Knip better for everyone. Please read [issue reproduction][6]
do! It'll make Knip better for everyone. Please read [issue reproduction][8]
first.

Exit code 2 indicates an exception was thrown by Knip.
Expand Down Expand Up @@ -97,32 +95,33 @@ the opposite direction and shows where exports are imported.

## Opening an issue

If you want to open an issue, please see [issue reproduction][6].
If you want to open an issue, please see [issue reproduction][8].

## Understanding Knip

Looking to better understand how Knip works? The [entry files][8] and
[plugins][9] explanations cover two core concepts. After this you might want to
check out features like [production mode][10] and [monorepos & workspaces][11].
Looking to better understand how Knip works? The [entry files][10] and
[plugins][11] explanations cover two core concepts. After this you might want to
check out features like [production mode][12] and [monorepos & workspaces][13].

In a more general sense, [Why use Knip?][12] explains what Knip can do for you.
In a more general sense, [Why use Knip?][14] explains what Knip can do for you.

## Asking for help

If you can't find your answer in any of the aforementioned resources, feel free
to [open an issue on GitHub][13] or discuss it in [the Discord channel][14].
to [open an issue on GitHub][15] or discuss it in [the Discord channel][6].

[1]: #lint-issues-reported-by-knip
[2]: #exceptions-thrown-by-knip
[3]: #debug
[4]: #trace
[5]: ../guides/handling-issues.md
[6]: ./issue-reproduction.md
[7]: ../reference/known-issues.md
[8]: ../explanations/entry-files.md
[9]: ../explanations/plugins.md
[10]: ../features/production-mode.md
[11]: ../features/monorepos-and-workspaces.md
[12]: ../explanations/why-use-knip.md
[13]: https://github.com/webpro-nl/knip/issues
[14]: https://discord.gg/r5uXTtbTpc
[5]: https://github.com/webpro-nl/knip/issues/new/choose
[6]: https://discord.gg/r5uXTtbTpc
[7]: ../guides/handling-issues.md
[8]: ./issue-reproduction.md
[9]: ../reference/known-issues.md
[10]: ../explanations/entry-files.md
[11]: ../explanations/plugins.md
[12]: ../features/production-mode.md
[13]: ../features/monorepos-and-workspaces.md
[14]: ../explanations/why-use-knip.md
[15]: https://github.com/webpro-nl/knip/issues
60 changes: 31 additions & 29 deletions packages/docs/src/content/docs/reference/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ hands".

On the other hand, Knip is a project linter that should be part of QA. It lints,
reports and fixes only your own source code. A linter reporting issues hands
control back to you (unless you [auto-fix](../features/auto-fix.mdx)
everything).
control back to you (unless you [auto-fix][1] everything).

Besides those differences, Knip has a broader scope:

- Improve DX (see [less is more](../explanations/why-use-knip.md#less-is-more)).
- Improve DX (see [less is more][2]).
- Include non-production code and dependencies in the process by default.
- Report more [issue types](./issue-types.md) (such as unlisted dependencies).
- Report more [issue types][3] (such as unlisted dependencies).

## Synergy

Expand Down Expand Up @@ -88,13 +87,13 @@ Building up the module and dependency graph requires non-standard module
resolution and not only static but also dynamic analysis (i.e. actually load and
execute modules), such as for parsers of plugins to receive the exported value
of dynamic tooling configuration files. Additionally, [exports consumed by
external libraries][1] require type information, as supported by the TypeScript
external libraries][4] require type information, as supported by the TypeScript
backend. Last but not least, shell script parsing is required to find the right
entry files, configuration files and dependencies accurately.

The rippling effect of plugins and recursively adding entry files and
dependencies to build up the graph is also exactly what's meant by
["comprehensive" here][2].
["comprehensive" here][5].

## Building the graph

Expand Down Expand Up @@ -136,9 +135,8 @@ files (`config/vitest.config.ts` and `playwright.e2e.config.ts` in the examples
above). They're recognized as configuration files and passed to their respective
plugins, and may contain additional entry files.

Entry files are added to the module graph.
[Module resolution](#module-resolution) might result in additional entry files
recursively until no more entry files are found.
Entry files are added to the module graph. [Module resolution][6] might result
in additional entry files recursively until no more entry files are found.

### What does Knip look for in source files?

Expand All @@ -150,7 +148,7 @@ all nodes of the generated AST to find:
- Accessed properties on namespace imports and re-exports to track individual
export usage
- Calls to `require.resolve` and `import.meta.resolve`
- Scripts in template strings (passed to [script parser][3])
- Scripts in template strings (passed to [script parser][7])

### What's in the graph?

Expand Down Expand Up @@ -188,7 +186,7 @@ there are a few issues with this approach:

- It requires lockfile parsing for each lockfile format and version of each
package manager.
- The lockfile doesn't contain whether the package [has types included][4].
- The lockfile doesn't contain whether the package [has types included][8].

## Module Resolution

Expand All @@ -209,12 +207,12 @@ seem to meet all requirements to be usable on its own by Knip:
`module.js`

A few strategies have been tried and tweaked, and Knip currently uses a
combination of [enhanced-resolve][5], the TypeScript module resolver and a few
combination of [enhanced-resolve][9], the TypeScript module resolver and a few
customizations. This single custom module resolver function is hooked into the
TypeScript compiler and language service hosts.

Everything else outside the dependency graph is handled by `enhanced-resolve`
when doing things like [script parsing][3] and resolving references to files in
when doing things like [script parsing][7] and resolving references to files in
other workspaces.

### How does Knip handle non-standard import syntax?
Expand Down Expand Up @@ -245,7 +243,7 @@ file. They're not a concept in Knip.

A TypeScript program has a 1-to-1 relationship with workspaces if they're
analyzed in isolation. However, by default Knip optimizes for performance and
utilizes [workspace sharing][6]. That's why debug output contains messages like
utilizes [workspace sharing][10]. That's why debug output contains messages like
"Installed 2 programs for 29 workspaces".

### Why doesn't Knip match my TypeScript project structure?
Expand Down Expand Up @@ -277,7 +275,7 @@ Knip shares the files of multiple workspaces in a single program if their
configuration allows it. This optimization is enabled by default, while it also
allows the module resolver (one per program) to do some more caching.

Also see [workspace sharing][6].
Also see [workspace sharing][10].

### Why doesn't Knip just use `ts.findReferences`?

Expand All @@ -293,7 +291,7 @@ comprehensive graph include:
Without sacrificing these benefits, Knip does use `ts.findReferences` to find
references to class members (i.e. when the issue type `classMembers` is
included). In case analysis of exports requires type information of external
dependencies, the [`--include-libs ` flag][1] will trigger the same.
dependencies, the [`--include-libs ` flag][4] will trigger the same.

### Why can't I use path aliases to reference other workspaces?

Expand Down Expand Up @@ -359,7 +357,7 @@ other file types.
Knip comes with basic "compilers" for a few common non-standard file types.
They're not actual compilers, they're regular expressions only to extract import
statements. Override the built-in Vue "compiler" with the real one in your
project. Also see the answer to the previous question and [Compilers][7].
project. Also see the answer to the previous question and [Compilers][11].

## Miscellaneous

Expand All @@ -379,7 +377,7 @@ Which mode should've been the default? They both have their merits:
tooling, including most issues found in production mode. This mode has the
most impact on DX, for the same reason.

Also see [production mode][8].
Also see [production mode][12].

### Why doesn't Knip have...?

Expand All @@ -403,14 +401,18 @@ Examples of features that have been requested include:

These are all interesting ideas, but most increase the API surface area, and all
require more development efforts and maintenance. Time is limited and
[sponsorships][9] currently don't cover - this can change though!

[1]: ../guides/handling-issues.mdx#external-libraries
[2]: ../explanations/why-use-knip.md#comprehensive
[3]: ../features/script-parser.md
[4]: ../guides/handling-issues.mdx#types-packages
[5]: https://www.npmjs.com/package/enhanced-resolve
[6]: ../guides/performance.md#workspace-sharing
[7]: ../features/compilers.md
[8]: ../features/production-mode.md
[9]: /sponsors
[sponsorships][13] currently don't cover - this can change though!

[1]: ../features/auto-fix.mdx
[2]: ../explanations/why-use-knip.md#less-is-more
[3]: ./issue-types.md
[4]: ../guides/handling-issues.mdx#external-libraries
[5]: ../explanations/why-use-knip.md#comprehensive
[6]: #module-resolution
[7]: ../features/script-parser.md
[8]: ../guides/handling-issues.mdx#types-packages
[9]: https://www.npmjs.com/package/enhanced-resolve
[10]: ../guides/performance.md#workspace-sharing
[11]: ../features/compilers.md
[12]: ../features/production-mode.md
[13]: /sponsors

0 comments on commit e6340b0

Please sign in to comment.