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

Commit c3fd7f9

Browse files
committed
Use json-schema-to-typescript for side schema
1 parent 2d55c0c commit c3fd7f9

15 files changed

+101
-108
lines changed

scripts/generate-files.ts

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -49,78 +49,6 @@ const generationMap: Record<string, Plugin> = {
4949
// Generating rule files
5050
const rulesDir: string = path.resolve(__dirname, '../src/rules');
5151

52-
function generateType(propertyDefinition: JSONSchema4): string {
53-
switch (propertyDefinition.type) {
54-
case 'string':
55-
case 'boolean':
56-
case 'number':
57-
return propertyDefinition.type;
58-
case 'integer':
59-
// TODO: Read further details
60-
return 'number';
61-
case 'array': {
62-
const items: JSONSchema4 | JSONSchema4[] | undefined = propertyDefinition.items;
63-
if (items && !Array.isArray(items)) {
64-
if (items.type === 'string') {
65-
return 'string[]';
66-
}
67-
// TODO: Could be enum or something else
68-
}
69-
// TODO: Handle array
70-
return 'any[]';
71-
}
72-
case 'object':
73-
// TODO: Handle nested objects
74-
return 'Record<string, any>';
75-
case undefined:
76-
// TODO: Could be an object
77-
break;
78-
default:
79-
console.log(propertyDefinition.type);
80-
break;
81-
}
82-
return 'any';
83-
}
84-
85-
function generateOptionType(schema: JSONSchema4): string {
86-
let result: string = 'any';
87-
88-
switch (schema.type) {
89-
case 'object':
90-
if (schema.properties) {
91-
result = '{\n';
92-
result += Object.entries(schema.properties)
93-
.map(([propertyName, propertyDefinition]) => `'${propertyName}'?: ${generateType(propertyDefinition)};`)
94-
.join('\n');
95-
result += '}';
96-
} else {
97-
// TODO: Identify further
98-
result = 'Record<string, any>;';
99-
}
100-
break;
101-
case 'string':
102-
result = 'string;';
103-
if (schema.enum) {
104-
result = `'${schema.enum.join("' | '")}';`;
105-
}
106-
break;
107-
case 'array':
108-
result = 'any[];';
109-
break;
110-
case undefined:
111-
if (schema.enum) {
112-
result = `'${schema.enum.join("' | '")}';`;
113-
}
114-
// TODO: Identify further
115-
break;
116-
default:
117-
// TODO: Something else?
118-
break;
119-
}
120-
121-
return result;
122-
}
123-
12452
async function main(): Promise<void> {
12553
for (const pluginName in generationMap) {
12654
const { rules, name } = generationMap[pluginName]!;
@@ -145,12 +73,25 @@ async function main(): Promise<void> {
14573
// TODO: vue/max-len has also a third schema
14674
if (mainSchema) {
14775
if (sideSchema) {
76+
const ruleConfig: string = await compile(sideSchema, `${ruleNamePascalCase}Config`, {
77+
bannerComment: '',
78+
style: {
79+
bracketSpacing: true,
80+
printWidth: 120,
81+
semi: true,
82+
singleQuote: true,
83+
tabWidth: 2,
84+
trailingComma: 'none',
85+
useTabs: false
86+
},
87+
unknownAny: false
88+
});
14889
ruleContent += `
14990
15091
/**
15192
* Config.
15293
*/
153-
export type ${ruleNamePascalCase}Config = ${generateOptionType(sideSchema)}`;
94+
${ruleConfig}`;
15495
}
15596

15697
const ruleOption: string = await compile(mainSchema, `${ruleNamePascalCase}Option`, {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type CheckLineAlignmentConfig = {
7-
customSpacings?: any;
6+
export interface CheckLineAlignmentConfig {
7+
customSpacings?: {
8+
postDelimiter?: number;
9+
postName?: number;
10+
postTag?: number;
11+
postType?: number;
12+
};
813
preserveMainDescriptionPostDelimiter?: boolean;
914
tags?: string[];
10-
};
15+
}
1116

1217
/**
1318
* Option.

src/rules/jsdoc/require-asterisk-prefix.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type RequireAsteriskPrefixConfig = {
7-
tags?: Record<string, any>;
8-
};
6+
export interface RequireAsteriskPrefixConfig {
7+
tags?: {
8+
always?: string[];
9+
any?: string[];
10+
never?: string[];
11+
[k: string]: any;
12+
};
13+
}
914

1015
/**
1116
* Option.

src/rules/jsdoc/require-hyphen-before-param-description.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type RequireHyphenBeforeParamDescriptionConfig = {
7-
tags?: any;
8-
};
6+
export interface RequireHyphenBeforeParamDescriptionConfig {
7+
tags?:
8+
| {
9+
[k: string]: 'always' | 'never';
10+
}
11+
| 'any';
12+
}
913

1014
/**
1115
* Option.

src/rules/jsdoc/tag-lines.d.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type TagLinesConfig = {
6+
export interface TagLinesConfig {
77
/**
88
* Use with "always" to indicate the number of lines to require be present.
99
*
@@ -20,8 +20,14 @@ export type TagLinesConfig = {
2020
* @see [noEndLines](https://github.com/gajus/eslint-plugin-jsdoc#noendlines-defaults-to-false)
2121
*/
2222
noEndLines?: boolean;
23-
tags?: Record<string, any>;
24-
};
23+
tags?: {
24+
[k: string]: {
25+
count?: number;
26+
lines?: 'always' | 'never' | 'any';
27+
};
28+
};
29+
[k: string]: any;
30+
}
2531

2632
/**
2733
* Option.

src/rules/vue/array-bracket-spacing.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type ArrayBracketSpacingConfig = {
6+
export interface ArrayBracketSpacingConfig {
77
singleValue?: boolean;
88
objectsInArrays?: boolean;
99
arraysInArrays?: boolean;
10-
};
10+
}
1111

1212
/**
1313
* Option.

src/rules/vue/attribute-hyphenation.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type AttributeHyphenationConfig = {
7-
ignore?: any[];
8-
};
6+
export interface AttributeHyphenationConfig {
7+
ignore?: (string & {
8+
[k: string]: any;
9+
} & {
10+
[k: string]: any;
11+
})[];
12+
}
913

1014
/**
1115
* Option.

src/rules/vue/brace-style.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type BraceStyleConfig = {
6+
export interface BraceStyleConfig {
77
allowSingleLine?: boolean;
8-
};
8+
}
99

1010
/**
1111
* Option.

src/rules/vue/comma-style.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type CommaStyleConfig = {
7-
exceptions?: Record<string, any>;
8-
};
6+
export interface CommaStyleConfig {
7+
exceptions?: {
8+
[k: string]: boolean;
9+
};
10+
}
911

1012
/**
1113
* Option.

src/rules/vue/component-name-in-template-casing.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import type { RuleConfig } from '../rule-config';
33
/**
44
* Config.
55
*/
6-
export type ComponentNameInTemplateCasingConfig = {
6+
export interface ComponentNameInTemplateCasingConfig {
77
ignores?: string[];
88
registeredComponentsOnly?: boolean;
9-
};
9+
}
1010

1111
/**
1212
* Option.

0 commit comments

Comments
 (0)