Skip to content

Commit

Permalink
doc: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-zhong committed Jul 1, 2021
1 parent f55c25c commit 78f66e7
Showing 1 changed file with 37 additions and 41 deletions.
78 changes: 37 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@ A CLI tool for finding unused class variables and methods in a TypeScript projec
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#usage">Usage</a></li>
</ul>
</li>
<li>
<a href="#configuration">Configuration</a>
<ul>
<li><a href="#configuration-file">Configuration File</a></li>
<li><a href="#cli-options">CLI Options</a></li>
</ul>
</li>
<li><a href="#ignoring-a-specifc-declaration">Ignoring a Specifc Declaration</a></li>
<li><a href="#configuration">Configuration File</a></li>
<li><a href="#ignoring-a-specifc-declaration">Ignoring a Specific Declaration</a></li>
<li><a href="#acknowledgements">Acknowledgements</a></li>
</ol>
</details>
Expand All @@ -30,40 +25,47 @@ A CLI tool for finding unused class variables and methods in a TypeScript projec

### Prerequisites

`@faire/ts-unused-class-members` is hosted on :octocat:[GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#installing-a-package). To configure npm to download @faire packaes from Git Packages registry you'll need to

1. Create a personal access token with the `read:packages` scope
2. Add the personall access token to ~/.npmrc
```
echo "//npm.pkg.github.com/:_authToken=YOUR_TOKEN" >> ~/.npmrc
```
3. Configure npm to download @faire packages from Git Packages registry
```
npm config set @faire:registry https://npm.pkg.github.com
```
`@faire/ts-unused-class-members` is hosted on :octocat:[GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#installing-a-package). To configure npm to download @faire packages from GitHub Packages registry you need to

1. Create a [personal access token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) with the `read:packages` scope
2. Use the command below to add the personal access token to ~/.npmrc
```
echo "//npm.pkg.github.com/:_authToken=YOUR_TOKEN" >> ~/.npmrc
```
3. Use the command below to configure npm to download @faire packages from GitHub Packages registry
```
npm config set @faire:registry https://npm.pkg.github.com
```

### Usage

In the same directory as your `tsconfig.json`, run

```
npx @faire/ts-unused-class-members
```

## Configuration
### CLI Options

`ts-unused-class-members` supports both file and CLI configuration.
Run `ts-unused-class-members` with `--help` to see all available CLI options.

### Configuration File
```
Options:
--project Path to the project's tsconfig.json [string]
--path Path to a single directory/file to scan [string]
--ignoreFileRegex Regex pattern for excluding files [string]
```

`ts-unused-class-members` consumes configuration using [cosmiconfig](https://github.com/davidtheclark/cosmiconfig#cosmiconfig), which supports various config formats.
These options are optional, and you can also set them in a config file.

- a `ts-unused-class-members` property in package.json
- a `ts-unused-class-members.config.js` or `ts-unused-class-members.config.cjs` CommonJS module exporting an object
- a `.ts-unused-class-membersrc` file in JSON or YAML format
## Configuration File

Example configuration for a React + Mobx project:
By default, `ts-unused-class-members` flags every class member that has no references in the project. Depends on the framework/library you use, you may want to tell
the checker to ignore certain class members. You can do that by including a configuration file.

> ts-unused-class-members.config.js
Example config file for a React + MobX project:

> ts-unused-class-members.config.js in the project root
>
> ```js
> module.exports = {
Expand All @@ -81,32 +83,26 @@ Example configuration for a React + Mobx project:
> "UNSAFE_componentWillMount",
> ],
> /**
> * Ignore members decorated by Mobx's @disposeOnUnmount
> * Ignore members decorated by MobX's @disposeOnUnmount
> */
> ignoreDecoratorNames: ["disposeOnUnmount"],
> /**
> * Ignore members initialized with Mobx's reaction()
> * Ignore members initialized with MobX's reaction()
> * e.g. public myReaction = reaction(...);
> */
> ignoreInitializerNames: ["reaction"],
> };
> ```
### CLI Options
Run `ts-unused-class-members` with `--help` to see all avaiable CLI options.
`ts-unused-class-members` consumes configuration using [cosmiconfig](https://github.com/davidtheclark/cosmiconfig#cosmiconfig), which supports some other config formats too.
```
Options:
--project Path to the project's tsconfig.json [string]
--path Path to a single directory/file to scan [string]
--ignoreFileRegex Regex pattern for excluding files [string]
```
- a `ts-unused-class-members` property in package.json
- a `ts-unused-class-members.config.js` or `ts-unused-class-members.config.cjs` CommonJS module exporting an object
- a `.ts-unused-class-membersrc` file in JSON or YAML format
These options are optional and you can also set them using a config file.
## Ignoring a Specific Declaration
## Ignoring a Specifc Declaration
You can also tell `ts-unused-class-members` to ignore a specifc class or class member by prefixing its declaration with `// unused-class-members-ignore-next`.
You can also tell `ts-unused-class-members` to ignore a specific class or class member by prefixing its declaration with `// unused-class-members-ignore-next`.
```js
// unused-class-members-ignore-next
Expand Down

0 comments on commit 78f66e7

Please sign in to comment.