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

Commit 90bd9ba

Browse files
committed
Improve option type generation
1 parent 8677c16 commit 90bd9ba

File tree

135 files changed

+666
-950
lines changed

Some content is hidden

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

135 files changed

+666
-950
lines changed

scripts/generate-files.ts

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,45 @@ function generateType(propertyDefinition: JSONSchema4): string {
7373
return 'any';
7474
}
7575

76+
function generateOptionType(schema: JSONSchema4): string {
77+
let result: string = 'any';
78+
79+
switch (schema.type) {
80+
case 'object':
81+
if (schema.properties) {
82+
result = '{\n';
83+
result += Object.entries(schema.properties)
84+
.map(([propertyName, propertyDefinition]) => `'${propertyName}'?: ${generateType(propertyDefinition)};`)
85+
.join('\n');
86+
result += '}';
87+
} else {
88+
// TODO: Identify further
89+
result = 'Record<string, any>;';
90+
}
91+
break;
92+
case 'string':
93+
result = 'string;';
94+
if (schema.enum) {
95+
result = `'${schema.enum.join("' | '")}';`;
96+
}
97+
break;
98+
case 'array':
99+
result = 'any[];';
100+
break;
101+
case undefined:
102+
if (schema.enum) {
103+
result = `'${schema.enum.join("' | '")}';`;
104+
}
105+
// TODO: Identify further
106+
break;
107+
default:
108+
// TODO: Something else?
109+
break;
110+
}
111+
112+
return result;
113+
}
114+
76115
for (const pluginName in generationMap) {
77116
const { rules, name } = generationMap[pluginName]!;
78117

@@ -91,41 +130,36 @@ for (const pluginName in generationMap) {
91130

92131
const schema: JSONSchema4 | JSONSchema4[] | undefined = meta?.schema;
93132
const mainSchema: JSONSchema4 | undefined = Array.isArray(schema) ? schema[0] : schema;
94-
const hasOptionProperties: boolean = !!mainSchema?.properties;
95-
if (mainSchema?.properties) {
133+
const sideSchema: JSONSchema4 | undefined =
134+
schema && Array.isArray(schema) && schema.length > 1 ? schema[1] : undefined;
135+
if (sideSchema) {
136+
// console.log(pluginName, ruleName, mainSchema, sideSchema);
137+
}
138+
// TODO: vue/max-len has also a third schema
139+
if (mainSchema) {
96140
ruleContent += `
97141
98142
/**
99143
* Option.
100144
*/
101-
export type ${ruleNamePascalCase}Option = {`;
102-
103-
Object.entries(mainSchema.properties).forEach(([propertyName, propertyDefinition]) => {
104-
ruleContent += `
105-
/**
106-
* ${seeDocLink}
107-
*/
108-
'${propertyName}'?: ${generateType(propertyDefinition)};\n`;
109-
});
110-
111-
ruleContent += `}
145+
export type ${ruleNamePascalCase}Option = ${generateOptionType(mainSchema)}
112146
113147
/**
114148
* Options.
115149
*/
116150
export type ${ruleNamePascalCase}Options = [${ruleNamePascalCase}Option?];`;
117151
}
118152

153+
// TODO: Add side and third option
154+
119155
ruleContent += `
120156
121157
/**
122158
* ${description}
123159
*
124160
* ${seeDocLink}
125161
*/
126-
export type ${ruleNamePascalCase}RuleConfig = RuleConfig<${
127-
hasOptionProperties ? `${ruleNamePascalCase}Options` : '[]'
128-
}>;
162+
export type ${ruleNamePascalCase}RuleConfig = RuleConfig<${mainSchema ? `${ruleNamePascalCase}Options` : '[]'}>;
129163
130164
/**
131165
* ${description}

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

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,22 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type CheckExamplesOption = {
7-
/**
8-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
9-
*/
107
allowInlineConfig?: boolean;
11-
12-
/**
13-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
14-
*/
158
baseConfig?: Record<string, any>;
16-
17-
/**
18-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
19-
*/
209
captionRequired?: boolean;
21-
22-
/**
23-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
24-
*/
2510
checkDefaults?: boolean;
26-
27-
/**
28-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
29-
*/
3011
checkEslintrc?: boolean;
31-
32-
/**
33-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
34-
*/
3512
checkParams?: boolean;
36-
37-
/**
38-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
39-
*/
4013
checkProperties?: boolean;
41-
42-
/**
43-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
44-
*/
4514
configFile?: string;
46-
47-
/**
48-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
49-
*/
5015
exampleCodeRegex?: string;
51-
52-
/**
53-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
54-
*/
5516
matchingFileName?: string;
56-
57-
/**
58-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
59-
*/
6017
matchingFileNameDefaults?: string;
61-
62-
/**
63-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
64-
*/
6518
matchingFileNameParams?: string;
66-
67-
/**
68-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
69-
*/
7019
matchingFileNameProperties?: string;
71-
72-
/**
73-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
74-
*/
7520
noDefaultExampleRules?: boolean;
76-
77-
/**
78-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
79-
*/
8021
paddedIndent?: number;
81-
82-
/**
83-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
84-
*/
8522
rejectExampleCodeRegex?: string;
86-
87-
/**
88-
* @see [check-examples](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples)
89-
*/
9023
reportUnusedDisableDirectives?: boolean;
9124
};
9225

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type CheckIndentationOption = {
7-
/**
8-
* @see [check-indentation](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-indentation)
9-
*/
107
excludeTags?: any[];
118
};
129

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import type { RuleConfig } from '../rule-config';
22

3+
/**
4+
* Option.
5+
*/
6+
export type CheckLineAlignmentOption = 'always' | 'never';
7+
8+
/**
9+
* Options.
10+
*/
11+
export type CheckLineAlignmentOptions = [CheckLineAlignmentOption?];
12+
313
/**
414
* Reports invalid alignment of JSDoc block lines.
515
*
616
* @see [check-line-alignment](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-line-alignment)
717
*/
8-
export type CheckLineAlignmentRuleConfig = RuleConfig<[]>;
18+
export type CheckLineAlignmentRuleConfig = RuleConfig<CheckLineAlignmentOptions>;
919

1020
/**
1121
* Reports invalid alignment of JSDoc block lines.

src/rules/jsdoc/check-param-names.d.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,12 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type CheckParamNamesOption = {
7-
/**
8-
* @see [check-param-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names)
9-
*/
107
allowExtraTrailingParamDocs?: boolean;
11-
12-
/**
13-
* @see [check-param-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names)
14-
*/
158
checkDestructured?: boolean;
16-
17-
/**
18-
* @see [check-param-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names)
19-
*/
209
checkRestProperty?: boolean;
21-
22-
/**
23-
* @see [check-param-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names)
24-
*/
2510
checkTypesPattern?: string;
26-
27-
/**
28-
* @see [check-param-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names)
29-
*/
3011
disableExtraPropertyReporting?: boolean;
31-
32-
/**
33-
* @see [check-param-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names)
34-
*/
3512
enableFixer?: boolean;
36-
37-
/**
38-
* @see [check-param-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names)
39-
*/
4013
useDefaultObjectProperties?: boolean;
4114
};
4215

src/rules/jsdoc/check-property-names.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type CheckPropertyNamesOption = {
7-
/**
8-
* @see [check-property-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-property-names)
9-
*/
107
enableFixer?: boolean;
118
};
129

src/rules/jsdoc/check-tag-names.d.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type CheckTagNamesOption = {
7-
/**
8-
* @see [check-tag-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-tag-names)
9-
*/
107
definedTags?: any[];
11-
12-
/**
13-
* @see [check-tag-names](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-tag-names)
14-
*/
158
jsxTags?: boolean;
169
};
1710

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,8 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type CheckTypesOption = {
7-
/**
8-
* @see [check-types](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types)
9-
*/
107
exemptTagContexts?: any[];
11-
12-
/**
13-
* @see [check-types](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types)
14-
*/
158
noDefaults?: boolean;
16-
17-
/**
18-
* @see [check-types](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types)
19-
*/
209
unifyParentAndChildTypeChecks?: boolean;
2110
};
2211

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,9 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type CheckValuesOption = {
7-
/**
8-
* @see [check-values](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-values)
9-
*/
107
allowedAuthors?: any[];
11-
12-
/**
13-
* @see [check-values](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-values)
14-
*/
158
allowedLicenses?: any;
16-
17-
/**
18-
* @see [check-values](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-values)
19-
*/
209
licensePattern?: string;
21-
22-
/**
23-
* @see [check-values](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-values)
24-
*/
2510
numericOnlyVariation?: boolean;
2611
};
2712

src/rules/jsdoc/empty-tags.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import type { RuleConfig } from '../rule-config';
44
* Option.
55
*/
66
export type EmptyTagsOption = {
7-
/**
8-
* @see [empty-tags](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-empty-tags)
9-
*/
107
tags?: any[];
118
};
129

0 commit comments

Comments
 (0)