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

Commit f048a31

Browse files
committed
Generate options from schema
1 parent 9c1ef78 commit f048a31

File tree

236 files changed

+4397
-217
lines changed

Some content is hidden

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

236 files changed

+4397
-217
lines changed

scripts/generate-files.ts

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { pascalCase } from 'change-case';
1+
import { camelCase, pascalCase } from 'change-case';
22
import type { Rule } from 'eslint';
33
// @ts-expect-error
4+
import eslintPluginJSDoc from 'eslint-plugin-jsdoc';
5+
// @ts-expect-error
46
import eslintPluginVue from 'eslint-plugin-vue';
57
import * as fs from 'fs';
8+
import type { JSONSchema4 } from 'json-schema';
69
import * as path from 'path';
710
import type { Options } from 'prettier';
811
import { format } from 'prettier';
@@ -23,52 +26,100 @@ const PRETTIER_OPTIONS: Options = {
2326
useTabs: false
2427
};
2528

29+
const generationMap: Record<string, Plugin> = {
30+
jsdoc: {
31+
rules: (eslintPluginJSDoc as Plugin).rules
32+
},
33+
vue: {
34+
rules: (eslintPluginVue as Plugin).rules
35+
}
36+
};
37+
2638
// Generating rule files
2739
const rulesDir: string = path.resolve(__dirname, '../src/rules');
2840

29-
const ruleProviderDir: string = path.resolve(rulesDir, 'vue');
41+
for (const pluginName in generationMap) {
42+
const { rules } = generationMap[pluginName]!;
43+
44+
const ruleProviderDir: string = path.resolve(rulesDir, pluginName);
45+
46+
fs.mkdirSync(ruleProviderDir, { mode: 0o755, recursive: true });
47+
48+
Object.entries(rules).forEach(([name, { meta }]) => {
49+
const rulePath: string = path.resolve(ruleProviderDir, `${name}.d.ts`);
50+
let ruleContent: string = "import type { RuleConfig } from '../rule-config';";
51+
52+
const schema: JSONSchema4 | JSONSchema4[] | undefined = meta?.schema;
53+
const mainSchema: JSONSchema4 | undefined = Array.isArray(schema) ? schema[0] : schema;
54+
const hasOptionProperties: boolean = !!mainSchema?.properties;
55+
if (mainSchema?.properties) {
56+
ruleContent += `
57+
58+
/**
59+
* Option.
60+
*/
61+
export type ${pascalCase(name)}Option = {`;
3062

31-
fs.mkdirSync(ruleProviderDir, { mode: 0o755, recursive: true });
63+
Object.entries(mainSchema.properties).forEach(([propertyName, propertyDefinition]) => {
64+
ruleContent += `
65+
/**
66+
* @see [${name}](${meta?.docs?.url})
67+
*/
68+
'${propertyName}'?: any;\n`;
69+
});
3270

33-
Object.entries((eslintPluginVue as Plugin).rules).forEach(([name, { meta }]) => {
34-
const rulePath: string = path.resolve(ruleProviderDir, `${name}.d.ts`);
35-
let ruleContent: string = `import type { RuleConfig } from '../rule-config';
71+
ruleContent += `}
72+
73+
/**
74+
* Options.
75+
*/
76+
export type ${pascalCase(name)}Options = [${pascalCase(name)}Option?];`;
77+
}
78+
79+
ruleContent += `
3680
3781
/**
82+
* ${meta?.docs?.description}
3883
*
84+
* @see [${name}](${meta?.docs?.url})
3985
*/
40-
export type ${pascalCase(name)}RuleConfig = RuleConfig;
86+
export type ${pascalCase(name)}RuleConfig = RuleConfig<${hasOptionProperties ? `${pascalCase(name)}Options` : '[]'}>;
4187
4288
/**
89+
* ${meta?.docs?.description}
4390
*
91+
* @see [${name}](${meta?.docs?.url})
4492
*/
4593
export interface ${pascalCase(name)}Rule {
4694
/**
95+
* ${meta?.docs?.description}
4796
*
97+
* @see [${name}](${meta?.docs?.url})
4898
*/
49-
'vue/${name}': ${pascalCase(name)}RuleConfig;
99+
'${camelCase(pluginName)}/${name}': ${pascalCase(name)}RuleConfig;
50100
}
51101
`;
52-
ruleContent = format(ruleContent, PRETTIER_OPTIONS);
53-
fs.writeFileSync(rulePath, ruleContent);
54-
});
102+
ruleContent = format(ruleContent, PRETTIER_OPTIONS);
103+
fs.writeFileSync(rulePath, ruleContent);
104+
});
55105

56-
// Generating index.d.ts for rules
57-
const indexPath: string = path.resolve(ruleProviderDir, 'index.d.ts');
58-
let indexContent: string = Object.keys((eslintPluginVue as Plugin).rules)
59-
.map((name) => `import type { ${pascalCase(name)}Rule } from './${name}';`)
60-
.join('\n');
106+
// Generating index.d.ts for rules
107+
const indexPath: string = path.resolve(ruleProviderDir, 'index.d.ts');
108+
let indexContent: string = Object.keys(rules)
109+
.map((name) => `import type { ${pascalCase(name)}Rule } from './${name}';`)
110+
.join('\n');
61111

62-
indexContent += `
112+
indexContent += `
63113
64114
/**
65-
* All @typescript-eslint rules.
115+
* All ${camelCase(pluginName)} rules.
66116
*/
67-
export type VueRules = ${Object.keys((eslintPluginVue as Plugin).rules)
68-
.map((name) => `${pascalCase(name)}Rule`)
69-
.join(' & ')}
117+
export type ${pascalCase(pluginName)}Rules = ${Object.keys(rules)
118+
.map((name) => `${pascalCase(name)}Rule`)
119+
.join(' & ')}
70120
`;
71121

72-
indexContent = format(indexContent, PRETTIER_OPTIONS);
122+
indexContent = format(indexContent, PRETTIER_OPTIONS);
73123

74-
fs.writeFileSync(indexPath, indexContent);
124+
fs.writeFileSync(indexPath, indexContent);
125+
}

src/rules/jsdoc/check-access.d.ts

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+
* Checks that `@access` tags have a valid value.
5+
*
6+
* @see [check-access](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-access)
7+
*/
8+
export type CheckAccessRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Checks that `@access` tags have a valid value.
12+
*
13+
* @see [check-access](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-access)
14+
*/
15+
export interface CheckAccessRule {
16+
/**
17+
* Checks that `@access` tags have a valid value.
18+
*
19+
* @see [check-access](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-access)
20+
*/
21+
'jsdoc/check-access': CheckAccessRuleConfig;
22+
}

src/rules/jsdoc/check-alignment.d.ts

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+
* Reports invalid alignment of JSDoc block asterisks.
5+
*
6+
* @see [check-alignment](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-alignment)
7+
*/
8+
export type CheckAlignmentRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Reports invalid alignment of JSDoc block asterisks.
12+
*
13+
* @see [check-alignment](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-alignment)
14+
*/
15+
export interface CheckAlignmentRule {
16+
/**
17+
* Reports invalid alignment of JSDoc block asterisks.
18+
*
19+
* @see [check-alignment](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-alignment)
20+
*/
21+
'jsdoc/check-alignment': CheckAlignmentRuleConfig;
22+
}

src/rules/jsdoc/check-examples.d.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type CheckExamplesOption = {
7+
/**
8+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
9+
*/
10+
allowInlineConfig?: any;
11+
12+
/**
13+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
14+
*/
15+
baseConfig?: any;
16+
17+
/**
18+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
19+
*/
20+
captionRequired?: any;
21+
22+
/**
23+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
24+
*/
25+
checkDefaults?: any;
26+
27+
/**
28+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
29+
*/
30+
checkEslintrc?: any;
31+
32+
/**
33+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
34+
*/
35+
checkParams?: any;
36+
37+
/**
38+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
39+
*/
40+
checkProperties?: any;
41+
42+
/**
43+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
44+
*/
45+
configFile?: any;
46+
47+
/**
48+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
49+
*/
50+
exampleCodeRegex?: any;
51+
52+
/**
53+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
54+
*/
55+
matchingFileName?: any;
56+
57+
/**
58+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
59+
*/
60+
matchingFileNameDefaults?: any;
61+
62+
/**
63+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
64+
*/
65+
matchingFileNameParams?: any;
66+
67+
/**
68+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
69+
*/
70+
matchingFileNameProperties?: any;
71+
72+
/**
73+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
74+
*/
75+
noDefaultExampleRules?: any;
76+
77+
/**
78+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
79+
*/
80+
paddedIndent?: any;
81+
82+
/**
83+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
84+
*/
85+
rejectExampleCodeRegex?: any;
86+
87+
/**
88+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
89+
*/
90+
reportUnusedDisableDirectives?: any;
91+
};
92+
93+
/**
94+
* Options.
95+
*/
96+
export type CheckExamplesOptions = [CheckExamplesOption?];
97+
98+
/**
99+
* Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules.
100+
*
101+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
102+
*/
103+
export type CheckExamplesRuleConfig = RuleConfig<CheckExamplesOptions>;
104+
105+
/**
106+
* Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules.
107+
*
108+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
109+
*/
110+
export interface CheckExamplesRule {
111+
/**
112+
* Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules.
113+
*
114+
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
115+
*/
116+
'jsdoc/check-examples': CheckExamplesRuleConfig;
117+
}
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 CheckIndentationOption = {
7+
/**
8+
* @see [check-indentation](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-indentation)
9+
*/
10+
excludeTags?: any;
11+
};
12+
13+
/**
14+
* Options.
15+
*/
16+
export type CheckIndentationOptions = [CheckIndentationOption?];
17+
18+
/**
19+
* Reports invalid padding inside JSDoc blocks.
20+
*
21+
* @see [check-indentation](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-indentation)
22+
*/
23+
export type CheckIndentationRuleConfig = RuleConfig<CheckIndentationOptions>;
24+
25+
/**
26+
* Reports invalid padding inside JSDoc blocks.
27+
*
28+
* @see [check-indentation](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-indentation)
29+
*/
30+
export interface CheckIndentationRule {
31+
/**
32+
* Reports invalid padding inside JSDoc blocks.
33+
*
34+
* @see [check-indentation](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-indentation)
35+
*/
36+
'jsdoc/check-indentation': CheckIndentationRuleConfig;
37+
}
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+
* Reports invalid alignment of JSDoc block lines.
5+
*
6+
* @see [check-line-alignment](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-line-alignment)
7+
*/
8+
export type CheckLineAlignmentRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Reports invalid alignment of JSDoc block lines.
12+
*
13+
* @see [check-line-alignment](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-line-alignment)
14+
*/
15+
export interface CheckLineAlignmentRule {
16+
/**
17+
* Reports invalid alignment of JSDoc block lines.
18+
*
19+
* @see [check-line-alignment](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-line-alignment)
20+
*/
21+
'jsdoc/check-line-alignment': CheckLineAlignmentRuleConfig;
22+
}

0 commit comments

Comments
 (0)