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

Commit 3af93c2

Browse files
committed
Generate eslint rules
1 parent 46e0f17 commit 3af93c2

File tree

427 files changed

+10182
-804
lines changed

Some content is hidden

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

427 files changed

+10182
-804
lines changed

scripts/generate-rule-files.ts

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import eslintPluginTypeScript from '@typescript-eslint/eslint-plugin';
33
import { camelCase, pascalCase } from 'change-case';
44
import type { Rule } from 'eslint';
5+
import * as eslint from 'eslint';
56
// @ts-expect-error
67
import eslintPluginJSDoc from 'eslint-plugin-jsdoc';
78
// @ts-expect-error
@@ -35,6 +36,10 @@ const PRETTIER_OPTIONS: Options = {
3536
};
3637

3738
const generationMap: Record<string, Plugin> = {
39+
eslint: {
40+
name: 'Eslint',
41+
rules: Object.fromEntries(new eslint.Linter().getRules().entries())
42+
},
3843
jsdoc: {
3944
name: 'JSDoc',
4045
rules: (eslintPluginJSDoc as Plugin).rules
@@ -65,28 +70,50 @@ async function main(): Promise<void> {
6570

6671
fs.mkdirSync(ruleProviderDir, { mode: 0o755, recursive: true });
6772

73+
const failedRules: string[] = [];
6874
for (const [ruleName, { meta }] of Object.entries(rules)) {
69-
const rulePath: string = path.resolve(ruleProviderDir, `${ruleName}.d.ts`);
70-
let ruleContent: string = "import type { RuleConfig } from '../rule-config';";
75+
try {
76+
const rulePath: string = path.resolve(ruleProviderDir, `${ruleName}.d.ts`);
77+
let ruleContent: string = "import type { RuleConfig } from '../rule-config';";
7178

72-
const ruleNamePascalCase: string = pascalCase(ruleName);
79+
const ruleNamePascalCase: string = pascalCase(ruleName);
7380

74-
let description: string = upperCaseFirst(meta?.docs?.description ?? '');
75-
if (description.length > 0 && !description.endsWith('.')) {
76-
description += '.';
77-
}
78-
const seeDocLink: string = meta?.docs?.url ? `@see [${ruleName}](${meta.docs.url})` : '';
79-
80-
const schema: JSONSchema4 | JSONSchema4[] | undefined = meta?.schema;
81-
const mainSchema: JSONSchema4 | undefined = Array.isArray(schema) ? schema[0] : schema;
82-
const sideSchema: JSONSchema4 | undefined =
83-
schema && Array.isArray(schema) && schema.length > 1 ? schema[1] : undefined;
84-
const thirdSchema: JSONSchema4 | undefined =
85-
schema && Array.isArray(schema) && schema.length > 2 ? schema[2] : undefined;
86-
if (mainSchema) {
87-
if (sideSchema) {
88-
if (thirdSchema) {
89-
const ruleSetting: string = await compile(thirdSchema, `${ruleNamePascalCase}Setting`, {
81+
let description: string = upperCaseFirst(meta?.docs?.description ?? '');
82+
if (description.length > 0 && !description.endsWith('.')) {
83+
description += '.';
84+
}
85+
const seeDocLink: string = meta?.docs?.url ? `@see [${ruleName}](${meta.docs.url})` : '';
86+
87+
const schema: JSONSchema4 | JSONSchema4[] | undefined = meta?.schema;
88+
const mainSchema: JSONSchema4 | undefined = Array.isArray(schema) ? schema[0] : schema;
89+
const sideSchema: JSONSchema4 | undefined =
90+
schema && Array.isArray(schema) && schema.length > 1 ? schema[1] : undefined;
91+
const thirdSchema: JSONSchema4 | undefined =
92+
schema && Array.isArray(schema) && schema.length > 2 ? schema[2] : undefined;
93+
if (mainSchema) {
94+
if (sideSchema) {
95+
if (thirdSchema) {
96+
const ruleSetting: string = await compile(thirdSchema, `${ruleNamePascalCase}Setting`, {
97+
bannerComment: '',
98+
style: {
99+
bracketSpacing: true,
100+
printWidth: 120,
101+
semi: true,
102+
singleQuote: true,
103+
tabWidth: 2,
104+
trailingComma: 'none',
105+
useTabs: false
106+
},
107+
unknownAny: false
108+
});
109+
ruleContent += `
110+
111+
/**
112+
* Setting.
113+
*/
114+
${ruleSetting}`;
115+
}
116+
const ruleConfig: string = await compile(sideSchema, `${ruleNamePascalCase}Config`, {
90117
bannerComment: '',
91118
style: {
92119
bracketSpacing: true,
@@ -102,11 +129,12 @@ async function main(): Promise<void> {
102129
ruleContent += `
103130
104131
/**
105-
* Setting.
132+
* Config.
106133
*/
107-
${ruleSetting}`;
134+
${ruleConfig}`;
108135
}
109-
const ruleConfig: string = await compile(sideSchema, `${ruleNamePascalCase}Config`, {
136+
137+
const ruleOption: string = await compile(mainSchema, `${ruleNamePascalCase}Option`, {
110138
bannerComment: '',
111139
style: {
112140
bracketSpacing: true,
@@ -119,29 +147,8 @@ ${ruleSetting}`;
119147
},
120148
unknownAny: false
121149
});
122-
ruleContent += `
123150

124-
/**
125-
* Config.
126-
*/
127-
${ruleConfig}`;
128-
}
129-
130-
const ruleOption: string = await compile(mainSchema, `${ruleNamePascalCase}Option`, {
131-
bannerComment: '',
132-
style: {
133-
bracketSpacing: true,
134-
printWidth: 120,
135-
semi: true,
136-
singleQuote: true,
137-
tabWidth: 2,
138-
trailingComma: 'none',
139-
useTabs: false
140-
},
141-
unknownAny: false
142-
});
143-
144-
ruleContent += `
151+
ruleContent += `
145152
146153
/**
147154
* Option.
@@ -152,13 +159,13 @@ ${ruleOption}
152159
* Options.
153160
*/
154161
export type ${ruleNamePascalCase}Options = [${ruleNamePascalCase}Option?${
155-
sideSchema ? `, ${ruleNamePascalCase}Config?${thirdSchema ? `, ${ruleNamePascalCase}Setting?` : ''}` : ''
156-
}];`;
157-
}
162+
sideSchema ? `, ${ruleNamePascalCase}Config?${thirdSchema ? `, ${ruleNamePascalCase}Setting?` : ''}` : ''
163+
}];`;
164+
}
158165

159-
// TODO: Add third option
166+
// TODO: Add third option
160167

161-
ruleContent += `
168+
ruleContent += `
162169
163170
/**
164171
* ${description}
@@ -178,16 +185,23 @@ export type ${ruleNamePascalCase}Options = [${ruleNamePascalCase}Option?${
178185
*
179186
* ${seeDocLink}
180187
*/
181-
'${prefix ?? camelCase(pluginName)}/${ruleName}': ${ruleNamePascalCase}RuleConfig;
188+
'${
189+
pluginName !== 'eslint' ? `${prefix ?? camelCase(pluginName)}/` : ''
190+
}${ruleName}': ${ruleNamePascalCase}RuleConfig;
182191
}
183192
`;
184-
ruleContent = format(ruleContent, PRETTIER_OPTIONS);
185-
fs.writeFileSync(rulePath, ruleContent);
193+
ruleContent = format(ruleContent, PRETTIER_OPTIONS);
194+
fs.writeFileSync(rulePath, ruleContent);
195+
} catch (error) {
196+
console.log(`Failed to generate rule ${ruleName} for ${name}`, error);
197+
failedRules.push(ruleName);
198+
}
186199
}
187200

188201
// Generating index.d.ts for rules
189202
const indexPath: string = path.resolve(ruleProviderDir, 'index.d.ts');
190203
let indexContent: string = Object.keys(rules)
204+
.filter((name) => !failedRules.includes(name))
191205
.map((name) => `import type { ${pascalCase(name)}Rule } from './${name}';`)
192206
.join('\n');
193207

@@ -197,6 +211,7 @@ export type ${ruleNamePascalCase}Options = [${ruleNamePascalCase}Option?${
197211
* All ${name} rules.
198212
*/
199213
export type ${name}Rules = ${Object.keys(rules)
214+
.filter((name) => !failedRules.includes(name))
200215
.map((name) => `${pascalCase(name)}Rule`)
201216
.join(' & ')}
202217
`;

src/rules/eslint/accessor-pairs.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export interface AccessorPairsOption {
7+
getWithoutSet?: boolean;
8+
setWithoutGet?: boolean;
9+
enforceForClassMembers?: boolean;
10+
}
11+
12+
/**
13+
* Options.
14+
*/
15+
export type AccessorPairsOptions = [AccessorPairsOption?];
16+
17+
/**
18+
* Enforce getter and setter pairs in objects and classes.
19+
*
20+
* @see [accessor-pairs](https://eslint.org/docs/rules/accessor-pairs)
21+
*/
22+
export type AccessorPairsRuleConfig = RuleConfig<AccessorPairsOptions>;
23+
24+
/**
25+
* Enforce getter and setter pairs in objects and classes.
26+
*
27+
* @see [accessor-pairs](https://eslint.org/docs/rules/accessor-pairs)
28+
*/
29+
export interface AccessorPairsRule {
30+
/**
31+
* Enforce getter and setter pairs in objects and classes.
32+
*
33+
* @see [accessor-pairs](https://eslint.org/docs/rules/accessor-pairs)
34+
*/
35+
'accessor-pairs': AccessorPairsRuleConfig;
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type ArrayBracketNewlineOption =
7+
| ('always' | 'never' | 'consistent')
8+
| {
9+
multiline?: boolean;
10+
minItems?: number | null;
11+
};
12+
13+
/**
14+
* Options.
15+
*/
16+
export type ArrayBracketNewlineOptions = [ArrayBracketNewlineOption?];
17+
18+
/**
19+
* Enforce linebreaks after opening and before closing array brackets.
20+
*
21+
* @see [array-bracket-newline](https://eslint.org/docs/rules/array-bracket-newline)
22+
*/
23+
export type ArrayBracketNewlineRuleConfig = RuleConfig<ArrayBracketNewlineOptions>;
24+
25+
/**
26+
* Enforce linebreaks after opening and before closing array brackets.
27+
*
28+
* @see [array-bracket-newline](https://eslint.org/docs/rules/array-bracket-newline)
29+
*/
30+
export interface ArrayBracketNewlineRule {
31+
/**
32+
* Enforce linebreaks after opening and before closing array brackets.
33+
*
34+
* @see [array-bracket-newline](https://eslint.org/docs/rules/array-bracket-newline)
35+
*/
36+
'array-bracket-newline': ArrayBracketNewlineRuleConfig;
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Config.
5+
*/
6+
export interface ArrayBracketSpacingConfig {
7+
singleValue?: boolean;
8+
objectsInArrays?: boolean;
9+
arraysInArrays?: boolean;
10+
}
11+
12+
/**
13+
* Option.
14+
*/
15+
export type ArrayBracketSpacingOption = 'always' | 'never';
16+
17+
/**
18+
* Options.
19+
*/
20+
export type ArrayBracketSpacingOptions = [ArrayBracketSpacingOption?, ArrayBracketSpacingConfig?];
21+
22+
/**
23+
* Enforce consistent spacing inside array brackets.
24+
*
25+
* @see [array-bracket-spacing](https://eslint.org/docs/rules/array-bracket-spacing)
26+
*/
27+
export type ArrayBracketSpacingRuleConfig = RuleConfig<ArrayBracketSpacingOptions>;
28+
29+
/**
30+
* Enforce consistent spacing inside array brackets.
31+
*
32+
* @see [array-bracket-spacing](https://eslint.org/docs/rules/array-bracket-spacing)
33+
*/
34+
export interface ArrayBracketSpacingRule {
35+
/**
36+
* Enforce consistent spacing inside array brackets.
37+
*
38+
* @see [array-bracket-spacing](https://eslint.org/docs/rules/array-bracket-spacing)
39+
*/
40+
'array-bracket-spacing': ArrayBracketSpacingRuleConfig;
41+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export interface ArrayCallbackReturnOption {
7+
allowImplicit?: boolean;
8+
checkForEach?: boolean;
9+
}
10+
11+
/**
12+
* Options.
13+
*/
14+
export type ArrayCallbackReturnOptions = [ArrayCallbackReturnOption?];
15+
16+
/**
17+
* Enforce `return` statements in callbacks of array methods.
18+
*
19+
* @see [array-callback-return](https://eslint.org/docs/rules/array-callback-return)
20+
*/
21+
export type ArrayCallbackReturnRuleConfig = RuleConfig<ArrayCallbackReturnOptions>;
22+
23+
/**
24+
* Enforce `return` statements in callbacks of array methods.
25+
*
26+
* @see [array-callback-return](https://eslint.org/docs/rules/array-callback-return)
27+
*/
28+
export interface ArrayCallbackReturnRule {
29+
/**
30+
* Enforce `return` statements in callbacks of array methods.
31+
*
32+
* @see [array-callback-return](https://eslint.org/docs/rules/array-callback-return)
33+
*/
34+
'array-callback-return': ArrayCallbackReturnRuleConfig;
35+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type ArrayElementNewlineOption =
7+
| []
8+
| [
9+
| BasicConfig
10+
| {
11+
ArrayExpression?: BasicConfig;
12+
ArrayPattern?: BasicConfig;
13+
}
14+
];
15+
export type BasicConfig =
16+
| ('always' | 'never' | 'consistent')
17+
| {
18+
multiline?: boolean;
19+
minItems?: number | null;
20+
};
21+
22+
/**
23+
* Options.
24+
*/
25+
export type ArrayElementNewlineOptions = [ArrayElementNewlineOption?];
26+
27+
/**
28+
* Enforce line breaks after each array element.
29+
*
30+
* @see [array-element-newline](https://eslint.org/docs/rules/array-element-newline)
31+
*/
32+
export type ArrayElementNewlineRuleConfig = RuleConfig<ArrayElementNewlineOptions>;
33+
34+
/**
35+
* Enforce line breaks after each array element.
36+
*
37+
* @see [array-element-newline](https://eslint.org/docs/rules/array-element-newline)
38+
*/
39+
export interface ArrayElementNewlineRule {
40+
/**
41+
* Enforce line breaks after each array element.
42+
*
43+
* @see [array-element-newline](https://eslint.org/docs/rules/array-element-newline)
44+
*/
45+
'array-element-newline': ArrayElementNewlineRuleConfig;
46+
}

0 commit comments

Comments
 (0)