Skip to content

Commit

Permalink
Merge pull request #39 from line/docs/update-readme
Browse files Browse the repository at this point in the history
docs: update README
  • Loading branch information
kazushisan authored Sep 23, 2024
2 parents 8dff534 + d4a6920 commit 06d001c
Showing 1 changed file with 23 additions and 4 deletions.
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

0 comments on commit 06d001c

Please sign in to comment.