Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

docs: update README #39

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ However when this declaration is exported and is not referenced by any file in t
export const a = 'a';
```

This is when ts-remove-unused comes in handy. ts-remove-unused is a CLI tool made on top of TypeScript that reports/fixes unused exports. Here are some examples of how ts-remove-unused auto-fixes unused code.
This is when ts-remove-unused comes in handy. ts-remove-unused is a CLI tool built on top of TypeScript that finds unused exports and auto-fixes unused code.

Here are some examples of how ts-remove-unused auto-fixes unused code.

<!-- prettier-ignore-start -->

Expand Down Expand Up @@ -58,7 +60,7 @@ When `b` is not used within the project but `f()` is used within the project:
}
```

When `f()` is not used within the project and deleting it will result in `import` being unnecessary:
When `f()` is not used within the project and when deleting it will result in `import` being unnecessary:

```diff
--- src/c.ts
Expand All @@ -73,6 +75,23 @@ When `f()` is not used within the project and deleting it will result in `import
-}
```

When `f()` and `exported` are not used within the project and when deleting `f()` will result in `exported` and `local` being unnecessary:

```diff
--- src/d.ts
+++ src/d.ts
@@ -1,8 +1 @@
-export const exported = "exported";
-const local = "local";
-
export const d = "d";
-
-export function f() {
- return { exported, local };
-}

```

<!-- prettier-ignore-end -->

In addition to the behavior shown in the examples above, ts-remove-unused will delete files that have no used exports.
Expand Down Expand Up @@ -110,7 +129,7 @@ Options:
-v, --version Display version number
```

ts-remove-unused's behavior heavily depends on your `tsconfig.json`. TypeScript's compiler internally holds the list of project files by parsing relevant rules such as `include` and `exclude`. ts-remove-unused scans through this list and searches for references to determine if an export/file is "unused". You may need to maintain/update your `tsconfig` (or you can create another one for `--project`) so that the set of covered files are right.
ts-remove-unused's behavior heavily depends on your `tsconfig.json`. TypeScript's compiler internally holds the list of project files by parsing relevant rules such as `include` and `exclude`. ts-remove-unused scans through this list and searches for references to determine if an export/file is "unused". You may need to maintain/update your `tsconfig` (or you can create another file for `--project`) so that the set of covered files are right.

Here's an example of using the CLI. Your entry point file must be skipped or else every file will be removed.

Expand All @@ -126,7 +145,7 @@ npx @line/ts-remove-unused --skip 'src/main\.ts'
Use `--check` to check for unused files and exports without making changes to project files. The command will exit with exit code 1 if there are any unused files or exports discovered.

```bash
npx @line/ts-remove-unused --check
npx @line/ts-remove-unused --skip 'src/main\.ts' --check
```

### Use the JavaScript API
Expand Down
Loading