Skip to content

Commit

Permalink
patch types
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Apr 22, 2023
1 parent c848987 commit f47efb6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
29 changes: 27 additions & 2 deletions scripts/generate-rule-files/src/json-schema-to-ts.ts
Expand Up @@ -16,14 +16,36 @@ function cleanJsDoc(content: string): string {
.join('\n');
}

/**
* Replace some types that are generated by `json-schema-to-typescript`.
*/
export function patchTypes(content: string): string {
const replacements: Array<{
pattern: RegExp;
replacement: string;
}> = [
{
pattern:
/\(string & \{\s*\[k: string\]: any\s*\} & \{\s*\[k: string\]: any\s*\}\)\[\]/,
replacement: 'string[]',
},
];

for (const { pattern, replacement } of replacements) {
content = content.replace(pattern, replacement);
}

return content;
}

/**
* Generate a type from the given JSON schema.
*/
export async function generateTypeFromSchema(
schema: JSONSchema4,
typeName: string,
): Promise<string> {
const result: string = await compile(schema, typeName, {
let result: string = await compile(schema, typeName, {
format: false,
bannerComment: '',
style: {
Expand All @@ -33,5 +55,8 @@ export async function generateTypeFromSchema(
unknownAny: false,
});

return cleanJsDoc(result);
result = cleanJsDoc(result);
result = patchTypes(result);

return result;
}
6 changes: 1 addition & 5 deletions src/rules/vue/attribute-hyphenation.d.ts
Expand Up @@ -4,11 +4,7 @@ import type { RuleConfig } from '../rule-config';
* Config.
*/
export interface AttributeHyphenationConfig {
ignore?: (string & {
[k: string]: any;
} & {
[k: string]: any;
})[];
ignore?: string[];
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/rules/vue/html-indent.d.ts
Expand Up @@ -15,11 +15,7 @@ export interface HtmlIndentConfig {
};
switchCase?: number;
alignAttributesVertically?: boolean;
ignores?: (string & {
[k: string]: any;
} & {
[k: string]: any;
})[];
ignores?: string[];
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/rules/vue/script-indent.d.ts
Expand Up @@ -6,11 +6,7 @@ import type { RuleConfig } from '../rule-config';
export interface ScriptIndentConfig {
baseIndent?: number;
switchCase?: number;
ignores?: (string & {
[k: string]: any;
} & {
[k: string]: any;
})[];
ignores?: string[];
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/rules/vue/v-on-event-hyphenation.d.ts
Expand Up @@ -5,11 +5,7 @@ import type { RuleConfig } from '../rule-config';
*/
export interface VOnEventHyphenationConfig {
autofix?: boolean;
ignore?: (string & {
[k: string]: any;
} & {
[k: string]: any;
})[];
ignore?: string[];
}

/**
Expand Down

0 comments on commit f47efb6

Please sign in to comment.