Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andykog/no-unused
Finds unused properties in TypeScript code
https://github.com/andykog/no-unused
Last synced: about 1 month ago
JSON representation
Finds unused properties in TypeScript code
- Host: GitHub
- URL: https://github.com/andykog/no-unused
- Owner: andykog
- License: mit
- Created: 2022-11-20T19:45:31.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-24T18:22:57.000Z (about 2 years ago)
- Last Synced: 2024-10-14T05:26:08.251Z (3 months ago)
- Language: TypeScript
- Size: 519 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# no-unused
[experimental, early stage of development]
Finds unused properties in code utilizing TypeScript type system.
## Usage
```sh
npx no-unused src/**/*.ts
``````
Arguments:
pattern pattern for source files (omit to find automatically)Options:
-V, --version output the version number
-i, --ignore [pattern] pattern for ignored files (default: "**/*.@(spec|test).*")
-I, --ignoreExports [pattern] pattern for files where exports are ignored
-p, --project [string] path to tsconfig.json (omit to resolve automatically)
-e, --errors emit tsc errors
-h, --help display help for command
```*Note: files matched with `--ignore` won't be analyzed. Files containing `.spec.` or `.test.`
are ignored by default to also find identifiers that are used only in tests.*### Example
**Source file:**
```ts
const data = {name: 'John', surname: 'Smith'};type Params = {a?: number; wat?: string};
const selector = ({a}: Params) => [a, data.name];
selector({});
```**Output:**
```
src/example.ts:1:29 - message TS0: Unused identifier1 const data = {name: 'John', surname: 'Smith'};
~~~~~~~
src/example.ts:3:28 - message TS0: Unused identifier3 type Params = {a?: number; wat?: string};
~~~Total: 2 unused identifiers
```## Ignoring unused app entrypoints
App entrypoints appear unused because they are meant to be used by external code. To ignore them:
**Option 1**
Use `--ignoreExports entrypointsPattern`
```sh
npx no-unused src/**/*.ts --ignoreExports 'src/entrypoint.ts,src/otherEntrypoints/*.ts'
```**Option 2**
Add `/** @public */` comment for exports used by external code:
```ts
/** @public */
export const renderApp = () => {...};/** @public */
export const appConfig = {...};
```## Eslint plugin
See [eslint-plugin-no-unused](https://www.npmjs.com/package/eslint-plugin-no-unused)