Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 46e0f17

Browse files
committed
Generate TypeScript rules
1 parent 7f43eed commit 46e0f17

File tree

170 files changed

+4817
-497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+4817
-497
lines changed

scripts/generate-rule-files.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-expect-error
2+
import eslintPluginTypeScript from '@typescript-eslint/eslint-plugin';
13
import { camelCase, pascalCase } from 'change-case';
24
import type { Rule } from 'eslint';
35
// @ts-expect-error
@@ -16,6 +18,7 @@ import { upperCaseFirst } from 'upper-case-first';
1618

1719
interface Plugin {
1820
name: string;
21+
prefix?: string;
1922
rules: Record<string, Rule.RuleModule>;
2023
}
2124

@@ -40,6 +43,11 @@ const generationMap: Record<string, Plugin> = {
4043
name: 'Spellcheck',
4144
rules: (eslintPluginSpellcheck as Plugin).rules
4245
},
46+
'typescript-eslint': {
47+
name: 'TypeScript',
48+
prefix: '@typescript-eslint',
49+
rules: (eslintPluginTypeScript as Plugin).rules
50+
},
4351
vue: {
4452
name: 'Vue',
4553
rules: (eslintPluginVue as Plugin).rules
@@ -51,7 +59,7 @@ const rulesDir: string = path.resolve(__dirname, '../src/rules');
5159

5260
async function main(): Promise<void> {
5361
for (const pluginName in generationMap) {
54-
const { rules, name } = generationMap[pluginName]!;
62+
const { rules, name, prefix } = generationMap[pluginName]!;
5563

5664
const ruleProviderDir: string = path.resolve(rulesDir, pluginName);
5765

@@ -63,7 +71,10 @@ async function main(): Promise<void> {
6371

6472
const ruleNamePascalCase: string = pascalCase(ruleName);
6573

66-
const description: string = upperCaseFirst(meta?.docs?.description ?? '');
74+
let description: string = upperCaseFirst(meta?.docs?.description ?? '');
75+
if (description.length > 0 && !description.endsWith('.')) {
76+
description += '.';
77+
}
6778
const seeDocLink: string = meta?.docs?.url ? `@see [${ruleName}](${meta.docs.url})` : '';
6879

6980
const schema: JSONSchema4 | JSONSchema4[] | undefined = meta?.schema;
@@ -167,7 +178,7 @@ export type ${ruleNamePascalCase}Options = [${ruleNamePascalCase}Option?${
167178
*
168179
* ${seeDocLink}
169180
*/
170-
'${camelCase(pluginName)}/${ruleName}': ${ruleNamePascalCase}RuleConfig;
181+
'${prefix ?? camelCase(pluginName)}/${ruleName}': ${ruleNamePascalCase}RuleConfig;
171182
}
172183
`;
173184
ruleContent = format(ruleContent, PRETTIER_OPTIONS);
@@ -200,6 +211,6 @@ main()
200211
.then(() => {
201212
//
202213
})
203-
.catch(() => {
204-
//
214+
.catch((error) => {
215+
console.log('Failed to generate rule files.', error);
205216
});

src/rules/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { JSDocRules } from './jsdoc';
44
import type { NodeRules } from './node';
55
import type { RuleConfig } from './rule-config';
66
import type { SpellcheckRules } from './spellcheck';
7-
import type { TypeScriptEslintRules } from './typescript-eslint';
7+
import type { TypeScriptRules } from './typescript-eslint';
88
import type { VueRules } from './vue';
99

1010
/**
@@ -14,7 +14,7 @@ import type { VueRules } from './vue';
1414
*/
1515
export type Rules = Partial<
1616
EslintRules &
17-
TypeScriptEslintRules &
17+
TypeScriptRules &
1818
NodeRules &
1919
ImportRules &
2020
JSDocRules &

src/rules/typescript-eslint/adjacent-overload-signatures.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Require that member overloads be consecutive.
55
*
6-
* @see [adjacent-overload-signatures](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md)
6+
* @see [adjacent-overload-signatures](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md)
77
*/
88
export type AdjacentOverloadSignaturesRuleConfig = RuleConfig<[]>;
99

1010
/**
1111
* Require that member overloads be consecutive.
1212
*
13-
* @see [adjacent-overload-signatures](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md)
13+
* @see [adjacent-overload-signatures](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md)
1414
*/
1515
export interface AdjacentOverloadSignaturesRule {
1616
/**
1717
* Require that member overloads be consecutive.
1818
*
19-
* @see [adjacent-overload-signatures](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md)
19+
* @see [adjacent-overload-signatures](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md)
2020
*/
2121
'@typescript-eslint/adjacent-overload-signatures': AdjacentOverloadSignaturesRuleConfig;
2222
}
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import type { RuleConfig } from '../rule-config';
22

3-
/**
4-
* Array Option.
5-
*/
6-
export type ArrayOption = 'array' | 'generic' | 'array-simple';
7-
83
/**
94
* Option.
105
*/
11-
export type ArrayTypeOption = {
6+
export interface ArrayTypeOption {
127
/**
138
* Sets the array type expected for mutable cases.
149
*
1510
* @default 'array'
1611
*
1712
* @see [default](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md#options)
1813
*/
19-
default: ArrayOption;
14+
default?: 'array' | 'generic' | 'array-simple';
2015
/**
2116
* Sets the array type expected for readonly arrays. If this is omitted, then the value for default will be used.
2217
*
2318
* @see [readonly](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md#options)
2419
*/
25-
readonly?: ArrayOption;
26-
};
20+
readonly?: 'array' | 'generic' | 'array-simple';
21+
[k: string]: any;
22+
}
2723

2824
/**
2925
* Options.
@@ -33,20 +29,20 @@ export type ArrayTypeOptions = [ArrayTypeOption?];
3329
/**
3430
* Requires using either `T[]` or `Array<T>` for arrays.
3531
*
36-
* @see [array-type](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md)
32+
* @see [array-type](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/array-type.md)
3733
*/
3834
export type ArrayTypeRuleConfig = RuleConfig<ArrayTypeOptions>;
3935

4036
/**
4137
* Requires using either `T[]` or `Array<T>` for arrays.
4238
*
43-
* @see [array-type](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md)
39+
* @see [array-type](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/array-type.md)
4440
*/
4541
export interface ArrayTypeRule {
4642
/**
4743
* Requires using either `T[]` or `Array<T>` for arrays.
4844
*
49-
* @see [array-type](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md)
45+
* @see [array-type](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/array-type.md)
5046
*/
5147
'@typescript-eslint/array-type': ArrayTypeRuleConfig;
5248
}

src/rules/typescript-eslint/await-thenable.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Disallows awaiting a value that is not a Thenable.
55
*
6-
* @see [await-thenable](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/await-thenable.md)
6+
* @see [await-thenable](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/await-thenable.md)
77
*/
88
export type AwaitThenableRuleConfig = RuleConfig<[]>;
99

1010
/**
1111
* Disallows awaiting a value that is not a Thenable.
1212
*
13-
* @see [await-thenable](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/await-thenable.md)
13+
* @see [await-thenable](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/await-thenable.md)
1414
*/
1515
export interface AwaitThenableRule {
1616
/**
1717
* Disallows awaiting a value that is not a Thenable.
1818
*
19-
* @see [await-thenable](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/await-thenable.md)
19+
* @see [await-thenable](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/await-thenable.md)
2020
*/
2121
'@typescript-eslint/await-thenable': AwaitThenableRuleConfig;
2222
}

src/rules/typescript-eslint/ban-ts-comment.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Option.
55
*/
6-
export type BanTsCommentOption = {
6+
export interface BanTsCommentOption {
77
'ts-expect-error'?: boolean | 'allow-with-description';
88
'ts-ignore'?: boolean | 'allow-with-description';
99
'ts-nocheck'?: boolean | 'allow-with-description';
1010
'ts-check'?: boolean | 'allow-with-description';
1111
minimumDescriptionLength?: number;
12-
};
12+
}
1313

1414
/**
1515
* Options.
@@ -19,20 +19,20 @@ export type BanTsCommentOptions = [BanTsCommentOption?];
1919
/**
2020
* Bans `@ts-<directive>` comments from being used or requires descriptions after directive.
2121
*
22-
* @see [ban-ts-comment](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md)
22+
* @see [ban-ts-comment](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-ts-comment.md)
2323
*/
2424
export type BanTsCommentRuleConfig = RuleConfig<BanTsCommentOptions>;
2525

2626
/**
2727
* Bans `@ts-<directive>` comments from being used or requires descriptions after directive.
2828
*
29-
* @see [ban-ts-comment](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md)
29+
* @see [ban-ts-comment](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-ts-comment.md)
3030
*/
3131
export interface BanTsCommentRule {
3232
/**
3333
* Bans `@ts-<directive>` comments from being used or requires descriptions after directive.
3434
*
35-
* @see [ban-ts-comment](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md)
35+
* @see [ban-ts-comment](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-ts-comment.md)
3636
*/
3737
'@typescript-eslint/ban-ts-comment': BanTsCommentRuleConfig;
3838
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Bans `// tslint:<rule-flag>` comments from being used.
5+
*
6+
* @see [ban-tslint-comment](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-tslint-comment.md)
7+
*/
8+
export type BanTslintCommentRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Bans `// tslint:<rule-flag>` comments from being used.
12+
*
13+
* @see [ban-tslint-comment](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-tslint-comment.md)
14+
*/
15+
export interface BanTslintCommentRule {
16+
/**
17+
* Bans `// tslint:<rule-flag>` comments from being used.
18+
*
19+
* @see [ban-tslint-comment](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-tslint-comment.md)
20+
*/
21+
'@typescript-eslint/ban-tslint-comment': BanTslintCommentRuleConfig;
22+
}

src/rules/typescript-eslint/ban-types.d.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Option.
55
*/
6-
export type BanTypesOption = {
6+
export interface BanTypesOption {
77
/**
88
* An object whose keys are the types you want to ban, and the values are error messages.
99
*
1010
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
1111
*/
12-
types?: Record<
13-
string,
14-
| false
15-
| string
16-
| {
17-
/**
18-
* The message to display when the type is matched.
19-
*
20-
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
21-
*/
22-
message: string;
23-
/**
24-
* A string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
25-
*
26-
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
27-
*/
28-
fixWith?: string;
29-
}
30-
>;
31-
12+
types?: {
13+
[k: string]:
14+
| null
15+
| boolean
16+
| string
17+
| {
18+
/**
19+
* The message to display when the type is matched.
20+
*
21+
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
22+
*/
23+
message?: string;
24+
/**
25+
* A string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
26+
*
27+
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
28+
*/
29+
fixWith?: string;
30+
};
31+
};
3232
/**
3333
* If you're specifying custom `types`, you can set this to `true` to extend the default types configuration.
3434
*
3535
* @see [extendDefaults](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
3636
*/
3737
extendDefaults?: boolean;
38-
};
38+
}
3939

4040
/**
4141
* Options.
@@ -45,20 +45,20 @@ export type BanTypesOptions = [BanTypesOption?];
4545
/**
4646
* Bans specific types from being used.
4747
*
48-
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
48+
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-types.md)
4949
*/
5050
export type BanTypesRuleConfig = RuleConfig<BanTypesOptions>;
5151

5252
/**
5353
* Bans specific types from being used.
5454
*
55-
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
55+
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-types.md)
5656
*/
5757
export interface BanTypesRule {
5858
/**
5959
* Bans specific types from being used.
6060
*
61-
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
61+
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/ban-types.md)
6262
*/
6363
'@typescript-eslint/ban-types': BanTypesRuleConfig;
6464
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Config.
5+
*/
6+
export interface BraceStyleConfig {
7+
allowSingleLine?: boolean;
8+
}
9+
10+
/**
11+
* Option.
12+
*/
13+
export type BraceStyleOption = '1tbs' | 'stroustrup' | 'allman';
14+
15+
/**
16+
* Options.
17+
*/
18+
export type BraceStyleOptions = [BraceStyleOption?, BraceStyleConfig?];
19+
20+
/**
21+
* Enforce consistent brace style for blocks.
22+
*
23+
* @see [brace-style](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/brace-style.md)
24+
*/
25+
export type BraceStyleRuleConfig = RuleConfig<BraceStyleOptions>;
26+
27+
/**
28+
* Enforce consistent brace style for blocks.
29+
*
30+
* @see [brace-style](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/brace-style.md)
31+
*/
32+
export interface BraceStyleRule {
33+
/**
34+
* Enforce consistent brace style for blocks.
35+
*
36+
* @see [brace-style](https://github.com/typescript-eslint/typescript-eslint/blob/v4.31.2/packages/eslint-plugin/docs/rules/brace-style.md)
37+
*/
38+
'@typescript-eslint/brace-style': BraceStyleRuleConfig;
39+
}

0 commit comments

Comments
 (0)