Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jun 13, 2024
1 parent e9b3e66 commit 1c9361f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
36 changes: 27 additions & 9 deletions packages/docs/src/content/docs/features/auto-fix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ sidebar:

import { Tabs, TabItem } from '@astrojs/starlight/components';

Run Knip as you normally would, and then run it again with the `--fix` flag to
let Knip automatically apply fixes. Currently includes:
Run Knip as you normally would, and if the report looks good then run it again
with the `--fix` flag to let Knip automatically apply fixes.

Knip currently can fix these [issue types][1]:

- Remove `export` keyword for unused exports and exported types
- Remove unused `dependencies` and `devDependencies` from `package.json`
- Remove unused files
- Works across workspaces in a monorepo

## Flags

Add the `--fix` flag to remove unused exports and dependencies:

```sh
Expand All @@ -28,11 +32,18 @@ Add `--allow-remove-files` to allow Knip to remove unused files:
knip --fix --allow-remove-files
```

Use `--fix-type` to fix only specific issue types (`files`, `exports`, `types`
and/or `dependencies`). Example:
Use `--fix-type` to fix only specific issue types:

- `files`
- `exports`
- `types`
- `dependencies`

Example:

```sh
knip --fix-type exports,types
knip --fix-type exports --fix-type types # same as above
```

Use VCS/Git to review and undo changes if necessary.
Expand All @@ -41,11 +52,16 @@ Use VCS/Git to review and undo changes if necessary.

After Knip has fixed issues, there are two things to consider:

1. Use tools like ESLint or Biome to find and remove unused variables inside
files. This may result in more deleted code, and Knip may then find more
unused code. Rinse and repeat!
2. Verify changes in `package.json` and update dependencies using your package
manager:
### Unused variables

Use tools like ESLint or Biome to find and remove unused variables inside files.
This may result in more deleted code, and Knip may then find more unused code.
Rinse and repeat!

### Unused dependencies

Verify changes in `package.json` and update dependencies using your package
manager:

<Tabs>
<TabItem label="npm">
Expand Down Expand Up @@ -141,3 +157,5 @@ export const { , } = { a, b };

export const [, ] = [c, d];
```

[1]: ../reference/issue-types.md
7 changes: 4 additions & 3 deletions packages/docs/src/content/docs/features/compilers.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ Knip has built-in "compilers" for the following file extensions:

Note that "compilers" is quoted, as they are not real compilers, but regular
expressions to collect `import` statements from files with those extensions.
This allows Knip to build the dependency graph.
This is fast, requires no dependencies, and enough for Knip to build the
dependency graph.

On the other hand, real compilers may expose their own challenges in the context
of Knip. For instance, the Svelte compiler keeps `exports` intact, while they
might represent component properties. This results in those exports being
reported as unused by Knip.

In short, the built-in functions seem to do a decent job, but you can override
them however you like.
The built-in functions seem to do a decent job, but you can override them
however you like.

## Custom compilers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ const B = { option: true };

module.exports = { __esModule: true, A, B };
```

The `__esModule` key could be named differently (but I think makes sense given
it's an informal "CJS/ESM interop" standard amongst compilers and bundlers).
9 changes: 7 additions & 2 deletions packages/docs/src/content/docs/overview/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { Tabs, TabItem } from '@astrojs/starlight/components';

Knip v5 requires Node.js v18.6 or higher. Or Bun.

Looking for docs of previous versions? Go to [v3.knip.dev][1] or
[v4.knip.dev][2].

## Installation

This is the easiest and recommended way to install Knip:
Expand Down Expand Up @@ -78,7 +81,7 @@ Now you can run Knip to lint your project:

Knip will lint your project and report unused files, dependencies and exports.

You can skip the rest of this page and go to [configuration][1].
You can skip the rest of this page and go to [configuration][3].

## Manual

Expand Down Expand Up @@ -166,4 +169,6 @@ To run Knip without adding it to your project:
In this scenario `typescript` and `@types/node` are expected to be installed
already.

[1]: ./configuration.md
[1]: https://v3.knip.dev/overview/getting-started
[2]: https://v4.knip.dev/overview/getting-started
[3]: ./configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ An example screenshot showing `--performance` output for the Knip codebase:

<img src="/screenshots/performance.png" alt="performance" class="mw500" />

Also see [--performance](../reference/cli.md#--performance).
Also see [--performance][4].

[1]: ../reference/cli.md#--watch
[2]: ../features/auto-fix.mdx
[3]: ../guides/troubleshooting.md#trace
[4]: ../reference/cli.md#--performance
2 changes: 1 addition & 1 deletion packages/docs/src/content/docs/reference/issue-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Knip reports the following types of issues:

| Title | Description | | Key |
| :----------------------------------- | :--------------------------------------------------------- | --- | :------------- |
| Unused files | Unable to find a reference to this file | | `files` |
| Unused files | Unable to find a reference to this file | 🔧 | `files` |
| Unused dependencies | Unable to find a reference to this dependency | 🔧 | `dependencies` |
| Unused devDependencies | Unable to find a reference to this devDependency | 🔧 | `dependencies` |
| Referenced optional peerDependencies | Optional peer dependency is referenced | | `dependencies` |
Expand Down

0 comments on commit 1c9361f

Please sign in to comment.