Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(website): generate rule docs options automatically#5386

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
29 commits
Select commitHold shift + click to select a range
1ca21c4
chore(website): generate rule docs options automatically
JoshuaKGoldbergJul 26, 2022
532a803
Apply suggestions from code review
JoshuaKGoldbergJul 28, 2022
0b1ce8a
First round of changes
JoshuaKGoldbergJul 28, 2022
2e6b6b4
Simplify Prettier types
JoshuaKGoldbergJul 28, 2022
029c2a8
Progress on using defs
JoshuaKGoldbergJul 28, 2022
30a0862
Progress, through the letter 'd' for rules
JoshuaKGoldbergJul 29, 2022
005f0c6
Through explicit-module-boundary-types
JoshuaKGoldbergJul 29, 2022
6cb1909
rip, ban-types defaults
JoshuaKGoldbergJul 29, 2022
8f160f4
Cleaner separation for adding headers
JoshuaKGoldbergJul 29, 2022
20f277c
...I meant headings
JoshuaKGoldbergJul 29, 2022
6e49529
Finished specifically base rule extensions
JoshuaKGoldbergJul 29, 2022
cabf242
Fix unit test, and enable debug cypress logging
JoshuaKGoldbergAug 1, 2022
16e1883
Fix deprecation notices, and ci.yml env indent
JoshuaKGoldbergAug 1, 2022
913a143
Fix up lang and <sup>
JoshuaKGoldbergAug 1, 2022
b26c710
No, not sup
JoshuaKGoldbergAug 1, 2022
89268d3
Removed bunch more options docs cruft
JoshuaKGoldbergAug 1, 2022
dcfb464
naming-convention, I give up
JoshuaKGoldbergAug 1, 2022
6724746
Aha, a missing lint rule
JoshuaKGoldbergAug 1, 2022
e86e0b7
member-ordering, I give up on you too
JoshuaKGoldbergAug 1, 2022
8ac1a5b
Several more docs automations
JoshuaKGoldbergAug 1, 2022
ba912c3
Fixed options index
JoshuaKGoldbergAug 1, 2022
26f7a69
Also above Related To
JoshuaKGoldbergAug 1, 2022
50078b7
Aha, jsx working
JoshuaKGoldbergAug 1, 2022
b0910d4
Thanks lint - correct no-inferrable-types headings
JoshuaKGoldbergAug 1, 2022
2bcade6
Update packages/eslint-plugin/src/rules/no-implicit-any-catch.ts
JoshuaKGoldbergAug 7, 2022
0719010
Fix explicit-function-return-type
JoshuaKGoldbergAug 7, 2022
8e5a1c6
Merge branch 'main' into rule-docs-generated-options
JoshuaKGoldbergAug 7, 2022
7de8641
Merge branch 'main'
JoshuaKGoldbergAug 7, 2022
cfd750d
Merge branch 'main'
JoshuaKGoldbergAug 17, 2022
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
4 changes: 3 additions & 1 deletion.github/workflows/ci.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,7 +188,9 @@ jobs:
- name: Install Cypress
run: yarn cypress install

- name: Cypress run
- env:
DEBUG: '@cypress/github-action'
name: Cypress run
uses: cypress-io/github-action@v2
with:
project: ./packages/website
Expand Down
27 changes: 0 additions & 27 deletionspackages/eslint-plugin/docs/rules/TEMPLATE.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,33 +20,6 @@ To fill out: tell us more about this rule.
// To fill out: correct code
```

## Options

This rule is not configurable.

```jsonc
// .eslintrc.json
{
"rules": {
"@typescript-eslint/your-rule-name": "error"
}
}
```

If not configurable: This rule is not configurable.

If configurable...

```ts
type Options = {
someOption?: boolean;
};

const defaultOptions: Options = {
someOption: false,
};
```

## When Not To Use It

To fill out: why wouldn't you want to use this rule?
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,19 +88,6 @@ export function foo(n: number): void;
export function foo(sn: string | number): void;
```

## Options

```jsonc
// .eslintrc.json
{
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error"
}
}
```

This rule is not configurable.

## When Not To Use It

If you don't care about the general structure of the code, then you will not need this rule.
19 changes: 0 additions & 19 deletionspackages/eslint-plugin/docs/rules/array-type.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,25 +14,6 @@ This rule aims to standardize usage of array types within your codebase.

## Options

```ts
type ArrayOption = 'array' | 'generic' | 'array-simple';
type Options = {
default: ArrayOption;
readonly?: ArrayOption;
};

const defaultOptions: Options = {
default: 'array',
};
```

The rule accepts an options object with the following properties:

- `default` - sets the array type expected for mutable cases.
- `readonly` - sets the array type expected for readonly arrays. If this is omitted, then the value for `default` will be used.

Each property can be set to one of three strings: `'array' | 'generic' | 'array-simple'`.

The default config will enforce that all mutable and readonly arrays use the `'array'` syntax.

### `"array"`
Expand Down
13 changes: 0 additions & 13 deletionspackages/eslint-plugin/docs/rules/await-thenable.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,19 +33,6 @@ const createValue = async () => 'value';
await createValue();
```

## Options

```jsonc
// .eslintrc.json
{
"rules": {
"@typescript-eslint/await-thenable": "error"
}
}
```

This rule is not configurable.

## When Not To Use It

If you want to allow code to `await` non-Promise values.
Expand Down
26 changes: 2 additions & 24 deletionspackages/eslint-plugin/docs/rules/ban-ts-comment.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,32 +21,10 @@ The directive comments supported by TypeScript are:
## Rule Details

This rule lets you set which directive comments you want to allow in your codebase.
By default, only `@ts-check` is allowed, as it enables rather than suppresses errors.

The configuration looks like this:

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

interface Options {
'ts-expect-error'?: DirectiveConfig;
'ts-ignore'?: DirectiveConfig;
'ts-nocheck'?: DirectiveConfig;
'ts-check'?: DirectiveConfig;
minimumDescriptionLength?: number;
}
## Options

const defaultOptions: Options = {
'ts-expect-error': 'allow-with-description',
'ts-ignore': true,
'ts-nocheck': true,
'ts-check': false,
minimumDescriptionLength: 3,
};
```
By default, only `@ts-check` is allowed, as it enables rather than suppresses errors.

### `ts-expect-error`, `ts-ignore`, `ts-nocheck`, `ts-check` directives

Expand Down
13 changes: 0 additions & 13 deletionspackages/eslint-plugin/docs/rules/ban-tslint-comment.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,19 +34,6 @@ someCode(); // tslint:disable-line
someCode(); // This is a comment that just happens to mention tslint
```

## Options

```jsonc
// .eslintrc.json
{
"rules": {
"@typescript-eslint/ban-tslint-comment": "warn"
}
}
```

This rule is not configurable.

## When Not To Use It

If you are still using TSLint.
161 changes: 68 additions & 93 deletionspackages/eslint-plugin/docs/rules/ban-types.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,80 +6,61 @@ description: 'Disallow certain types.'
>
> See **https://typescript-eslint.io/rules/ban-types** for documentation.

Somebuiltin types have aliases, some types are considered dangerous or harmful.
Somebuilt-in types have aliases, while some types are considered dangerous or harmful.
It's often a good idea to ban certain types to help with consistency and safety.

## Rule Details

This rule bans specific types and can suggest alternatives.
Note that it does not ban the corresponding runtime objects from being used.

## Options

```ts
type Options = {
types?: {
[typeName: string]:
| false
| string
| {
message: string;
fixWith?: string;
};
};
extendDefaults?: boolean;
};
```

The rule accepts a single object as options.

### `types`
Examples of code with the default options:

An object whose keys are the types you want to ban, and the values are error messages.
<!--tabs-->

The type can either be a type name literal (`Foo`), a type name with generic parameter instantiation(s) (`Foo<Bar>`), the empty object literal (`{}`), or the empty tuple type (`[]`).
### ❌ Incorrect

The values can be:
```ts
// use lower-case primitives for consistency
const str: String = 'foo';
const bool: Boolean = true;
const num: Number = 1;
const symb: Symbol = Symbol('foo');
const bigInt: BigInt = 1n;

- A string, which is the error message to be reported; or
- `false` to specifically un-ban this type (useful when you are using `extendDefaults`); or
- An object with the following properties:
- `message: string` - the message to display when the type is matched.
- `fixWith?: string` - a string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
// use a proper function type
const func: Function = () => 1;

### `extendDefaults`
// use safer object types
const lowerObj: Object = {};
const capitalObj: Object = { a: 'string' };

If you're specifying custom `types`, you can set this to `true` to extend the default `types` configuration. This is a convenience option to save you copying across the defaults when adding another type.
const curly1: {} = 1;
const curly2: {} = { a: 'string' };
```

If this is `false`, the rule will _only_ use the types defined in your configuration.
### ✅ Correct

Example configuration:
```ts
// use lower-case primitives for consistency
const str: string = 'foo';
const bool: boolean = true;
const num: number = 1;
const symb: symbol = Symbol('foo');
const bigInt: bigint = 1n;

```jsonc
{
"@typescript-eslint/ban-types": [
"error",
{
"types": {
// add a custom message to help explain why not to use it
"Foo": "Don't use Foo because it is unsafe",
// use a proper function type
const func: () => number = () => 1;

// add a custom message, AND tell the plugin how to fix it
"OldAPI": {
"message": "Use NewAPI instead",
"fixWith": "NewAPI"
},
// use safer object types
const lowerObj: object = {};
const capitalObj: { a: string } = { a: 'string' };

// un-ban a type that's banned by default
"{}": false
},
"extendDefaults": true
}
]
}
const curly1: number = 1;
const curly2: Record<'a', string> = { a: 'string' };
```

### Default Options
## Options

The default options provide a set of "best practices", intended to provide safety and standardization in your codebase:

Expand DownExpand Up@@ -122,7 +103,6 @@ const defaultTypes = {
message: 'Use bigint instead',
fixWith: 'bigint',
},

Function: {
message: [
'The `Function` type accepts any function-like value.',
Expand All@@ -131,7 +111,6 @@ const defaultTypes = {
'If you are expecting the function to accept certain arguments, you should explicitly define the function shape.',
].join('\n'),
},

// object typing
Object: {
message: [
Expand All@@ -152,52 +131,48 @@ const defaultTypes = {

</details>

### Examples

Examples of code with the default options:

<!--tabs-->
### `types`

#### ❌ Incorrect
An object whose keys are the types you want to ban, and the values are error messages.

```ts
// use lower-case primitives for consistency
const str: String = 'foo';
const bool: Boolean = true;
const num: Number = 1;
const symb: Symbol = Symbol('foo');
const bigInt: BigInt = 1n;
The type can either be a type name literal (`Foo`), a type name with generic parameter instantiation(s) (`Foo<Bar>`), the empty object literal (`{}`), or the empty tuple type (`[]`).

// use a proper function type
const func: Function = () => 1;
The values can be:

// use safer object types
const capitalObj1: Object = 1;
const capitalObj2: Object = { a: 'string' };
- A string, which is the error message to be reported; or
- `false` to specifically un-ban this type (useful when you are using `extendDefaults`); or
- An object with the following properties:
- `message: string` - the message to display when the type is matched.
- `fixWith?: string` - a string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.

const curly1: {} = 1;
const curly2: {} = { a: 'string' };
```
### `extendDefaults`

#### ✅ Correct
If you're specifying custom `types`, you can set this to `true` to extend the default `types` configuration. This is a convenience option to save you copying across the defaults when adding another type.

```ts
// use lower-case primitives for consistency
const str: string = 'foo';
const bool: boolean = true;
const num: number = 1;
const symb: symbol = Symbol('foo');
const bigInt: bigint = 1n;
If this is `false`, the rule will _only_ use the types defined in your configuration.

// use a proper function type
const func: () => number = () => 1;
Example configuration:

// use safer object types
const lowerObj: object = {};
```jsonc
{
"@typescript-eslint/ban-types": [
"error",
{
"types": {
// add a custom message to help explain why not to use it
"Foo": "Don't use Foo because it is unsafe",

const capitalObj1: number = 1;
const capitalObj2: { a: string } = { a: 'string' };
// add a custom message, AND tell the plugin how to fix it
"OldAPI": {
"message": "Use NewAPI instead",
"fixWith": "NewAPI"
},

const curly1: number = 1;
const curly2: Record<'a', string> = { a: 'string' };
// un-ban a type that's banned by default
"{}": false
},
"extendDefaults": true
}
]
}
```
Loading

[8]ページ先頭

©2009-2025 Movatter.jp