Skip to content

docs(eslint-plugin): [ban-ts-comment] include descriptionFormat #5283

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2022
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
35 changes: 31 additions & 4 deletions packages/eslint-plugin/docs/rules/ban-ts-comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ By default, only `@ts-check` is allowed, as it enables rather than suppresses er
The configuration looks like this:

```ts
type DirectiveConfig =
| boolean
| 'allow-with-description'
| { descriptionFormat: string };

interface Options {
'ts-expect-error'?: boolean | 'allow-with-description';
'ts-ignore'?: boolean | 'allow-with-description';
'ts-nocheck'?: boolean | 'allow-with-description';
'ts-check'?: boolean | 'allow-with-description';
'ts-expect-error'?: DirectiveConfig;
'ts-ignore'?: DirectiveConfig;
'ts-nocheck'?: DirectiveConfig;
'ts-check'?: DirectiveConfig;
minimumDescriptionLength?: number;
}

Expand Down Expand Up @@ -105,6 +110,28 @@ if (false) {
}
```

### `descriptionFormat`

For each directive type, you can specify a custom format in the form of a regular expression. Only description that matches the pattern will be allowed.

For example, with `{ 'ts-expect-error': { descriptionFormat: '^: TS\\d+ because .+$' } }`:

<!--tabs-->

#### ❌ Incorrect

```ts
// @ts-expect-error: the library definition is wrong
const a = doSomething('hello');
```

#### ✅ Correct

```ts
// @ts-expect-error: TS1234 because the library definition is wrong
const a = doSomething('hello');
```

### `minimumDescriptionLength`

Use `minimumDescriptionLength` to set a minimum length for descriptions when using the `allow-with-description` option for a directive.
Expand Down