Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Sep 6, 2024
1 parent 0fe67f5 commit 273cf04
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/docs/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export default defineConfig({
label: 'Blog',
autogenerate: { directory: 'blog' },
},
{
label: 'Read more',
collapsed: true,
autogenerate: { directory: 'typescript' },
},
],
expressiveCode: {
emitExternalStylesheet: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/mock/tweets.json
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@
{
"id": "481186762",
"username": "Mokkapps",
"profile_image_url": "https://pbs.twimg.com/profile_images/1556918231159504898/8cXgvuyP_normal.jpg",
"profile_image_url": "https://pbs.twimg.com/profile_images/1825498937911889920/FtBqvqgK_400x400.jpg",
"name": "Michael Hoffmann"
},
{
Expand Down
20 changes: 20 additions & 0 deletions packages/docs/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Use `knip --exports` to also include class and enum members.
- [dependency-check][7]
- [deadfile][8]
- [npm-check][9] (used depcheck)
- [find-unused-exports][10]

[1]: ../features/monorepos-and-workspaces.md
[2]: ../overview/getting-started.mdx
Expand All @@ -102,3 +103,4 @@ Use `knip --exports` to also include class and enum members.
[7]: https://github.com/dependency-check-team/dependency-check
[8]: https://github.com/M-Izadmehr/deadfile
[9]: https://github.com/dylang/npm-check
[10]: https://github.com/jaydenseric/find-unused-exports
2 changes: 2 additions & 0 deletions packages/docs/src/content/docs/explanations/why-use-knip.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ code":
- Keeping dead code around has a negative value on readability, as it can be
misleading and distracting. Even if it serves no purpose it will need to be
maintained (source: [Safe dead code removal → YAGNI][1]).
- Also see
[Why are unused dependencies a problem?](../typescript/unused-dependencies.md#why-are-unused-dependencies-a-problem)

## Automation

Expand Down
4 changes: 4 additions & 0 deletions packages/docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ Special thanks to the wonderful people who have contributed to this project:

<Tweets />

## Read More

- [Unused dependencies](./typescript/unused-dependencies.md)

[1]: ./sponsors
[2]: ./overview/getting-started.mdx
[3]: ./explanations/why-use-knip.md
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/content/docs/overview/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
title: Features
---

Overview of capabilities in support of the core feature: find [issues][1]
(clutter).
Overview of capabilities in support of the core feature: find many [types of
issues][1].

There are also [things Knip does **not** do][2].

Expand Down
6 changes: 3 additions & 3 deletions packages/docs/src/content/docs/reference/unsupported.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This page is an overview of related features Knip does not support.

## Unused variables

Knip doesn't look for unused variables within a file. It only looks for values
and types that are imported and/or exported.
Knip doesn't look for unused variables within a file. It looks for exported and
imported values and types.

Use [ESLint][1], [Biome][2] or [oxc][3].
Use [ESLint][1], [Biome][2] or [oxc][3] to find unused variables within files.

## Unused properties

Expand Down
83 changes: 83 additions & 0 deletions packages/docs/src/content/docs/typescript/unused-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: Unused dependencies
description: Find and remove unused dependencies with Knip
prev: false
next: false
---

One of Knip's core features is finding unused dependencies in your JavaScript
and TypeScript projects. And it comes with many more features to remove clutter
and keep your projects in great shape.

## Why are unused dependencies a problem?

Having unused dependencies in your `package.json` is an issue for various
reasons:

- They might end up in the final production bundle, increasing size and load
times for end users.
- They waste space in `node_modules` and add to the installation time of the
project.
- They slow down tooling such as linters and bundlers that analyze dependencies.
- They are confusing and noisy in `package.json`.
- They cause unnecessary extra work when managing and upgrading dependencies.
- They can cause version conflicts with other dependencies in use.
- They can cause false security alerts.
- They might have restrictive licenses and make your project subject to theirs.
- They usually come with transitive dependencies that have the same issues.

## How do I find unused dependencies?

Use Knip to find and remove unused dependencies. It also finds dependencies that
are missing in `package.json` and has a lot more features to keep your
JavaScript and TypeScript projects tidy.

It's easy to [get started](../overview/getting-started.mdx) and make package
management easier and more fun!

<div style="display: flex; justify-content: center; margin: 4rem auto;">
<img src="/logo.svg" alt="Logo of Knip, to find unused files, dependencies and exports" class="logo-border" />
</div>

## How does Knip identify unused dependencies?

Knip works by analyzing `package.json` files, source code and configuration
files for other tooling in the project to find unused and missing dependencies.
Knip has many heuristics, [plugins](../reference/plugins.md) and
[compilers](../features/compilers.md) to fully automate the process.

## Can Knip remove unused dependencies?

Yes, Knip can automatically remove unused dependencies for you. Add the `--fix`
argument to [auto-fix](../features/auto-fix.mdx) and remove unused dependencies
from `package.json`.

## Can Knip detect missing dependencies?

Yes, Knip detects missing dependencies. It analyzes `package.json` files, and
reports packages that are missing. They should be added to `package.json` to
avoid relying on transitive dependencies that can cause version mismatches and
breakage.

## Does Knip work with monorepos?

Yes, Knip has first-class support for
[monorepos and workspaces](../features/monorepos-and-workspaces.md). It analyzes
all workspaces in the project and understands their relationship.

For instance, if a dependency is listed in the root `package.json` it does not
need to be listed in other workspaces. Except if you enable `--strict` checking.

## Does Knip separate dependencies and devDependencies?

Yes, Knip understands the difference between dependencies and devDependencies.
It has a [production mode](../features/production-mode.md) to focus on
production code only and find dead code and dependencies that would otherwise
only be referenced by tests and other tooling. This allows you to remove both
unused exported code and their tests.

## Does Knip work with my package manager?

Yes, Knip works with any package manager: npm, pnpm, Bun and Yarn are all
supported. It's easy to [get started](../overview/getting-started.mdx) with any
package manager.
6 changes: 6 additions & 0 deletions packages/docs/src/styles/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,9 @@ section.plugins li {
.sl-markdown-content .mw500 {
max-width: 500px;
}

.logo-border {
width: 200px;
border: 2px solid var(--sl-color-white);
border-radius: 40px;
}

0 comments on commit 273cf04

Please sign in to comment.