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

Commit 1d8733c

Browse files
authored
Patch types generated by jsonschema compiler (#190)
1 parent 6b485d9 commit 1d8733c

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

scripts/generate-rule-files/src/json-schema-to-ts.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,36 @@ function cleanJsDoc(content: string): string {
1616
.join('\n');
1717
}
1818

19+
/**
20+
* Replace some types that are generated by `json-schema-to-typescript`.
21+
*/
22+
export function patchTypes(content: string): string {
23+
const replacements: Array<{
24+
pattern: RegExp;
25+
replacement: string;
26+
}> = [
27+
{
28+
pattern:
29+
/\(string & \{\s*\[k: string\]: any\s*\} & \{\s*\[k: string\]: any\s*\}\)\[\]/,
30+
replacement: 'string[]',
31+
},
32+
];
33+
34+
for (const { pattern, replacement } of replacements) {
35+
content = content.replace(pattern, replacement);
36+
}
37+
38+
return content;
39+
}
40+
1941
/**
2042
* Generate a type from the given JSON schema.
2143
*/
2244
export async function generateTypeFromSchema(
2345
schema: JSONSchema4,
2446
typeName: string,
2547
): Promise<string> {
26-
const result: string = await compile(schema, typeName, {
48+
let result: string = await compile(schema, typeName, {
2749
format: false,
2850
bannerComment: '',
2951
style: {
@@ -33,5 +55,8 @@ export async function generateTypeFromSchema(
3355
unknownAny: false,
3456
});
3557

36-
return cleanJsDoc(result);
58+
result = cleanJsDoc(result);
59+
result = patchTypes(result);
60+
61+
return result;
3762
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import type { RuleConfig } from '../rule-config';
44
* Config.
55
*/
66
export interface AttributeHyphenationConfig {
7-
ignore?: (string & {
8-
[k: string]: any;
9-
} & {
10-
[k: string]: any;
11-
})[];
7+
ignore?: string[];
128
}
139

1410
/**

src/rules/vue/html-indent.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ export interface HtmlIndentConfig {
1515
};
1616
switchCase?: number;
1717
alignAttributesVertically?: boolean;
18-
ignores?: (string & {
19-
[k: string]: any;
20-
} & {
21-
[k: string]: any;
22-
})[];
18+
ignores?: string[];
2319
}
2420

2521
/**

src/rules/vue/script-indent.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import type { RuleConfig } from '../rule-config';
66
export interface ScriptIndentConfig {
77
baseIndent?: number;
88
switchCase?: number;
9-
ignores?: (string & {
10-
[k: string]: any;
11-
} & {
12-
[k: string]: any;
13-
})[];
9+
ignores?: string[];
1410
}
1511

1612
/**

src/rules/vue/v-on-event-hyphenation.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import type { RuleConfig } from '../rule-config';
55
*/
66
export interface VOnEventHyphenationConfig {
77
autofix?: boolean;
8-
ignore?: (string & {
9-
[k: string]: any;
10-
} & {
11-
[k: string]: any;
12-
})[];
8+
ignore?: string[];
139
}
1410

1511
/**

0 commit comments

Comments
 (0)