-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
config.ts
100 lines (95 loc) · 2.54 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import type Monaco from 'monaco-editor';
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
import { getTypescriptOptions } from '../config/utils';
export function createCompilerOptions(
jsx = false,
tsConfig: Record<string, unknown> = {},
): Monaco.languages.typescript.CompilerOptions {
return {
noResolve: true,
// ts and monaco has different type as monaco types are not changing base on ts version
target: window.ts.ScriptTarget.ESNext as number,
module: window.ts.ModuleKind.ESNext as number,
...tsConfig,
jsx: jsx ? window.ts.JsxEmit.Preserve : window.ts.JsxEmit.None,
moduleResolution: undefined,
plugins: undefined,
typeRoots: undefined,
paths: undefined,
moduleDetection: undefined,
baseUrl: undefined,
};
}
export function getEslintSchema(
rules: { name: string; description?: string }[],
): JSONSchema4 {
const properties = rules.reduce<Record<string, JSONSchema4>>(
(rules, item) => {
rules[item.name] = {
description: item.description,
oneOf: [
{
type: ['string', 'number'],
enum: ['off', 'warn', 'error', 0, 1, 2],
},
{
type: 'array',
items: [
{
type: ['string', 'number'],
enum: ['off', 'warn', 'error', 0, 1, 2],
},
],
},
],
};
return rules;
},
{},
);
return {
type: 'object',
properties: {
rules: {
type: 'object',
properties: properties,
additionalProperties: false,
},
},
};
}
export function getTsConfigSchema(): JSONSchema4 {
const properties = getTypescriptOptions().reduce((options, item) => {
if (item.type === 'boolean') {
options[item.name] = {
type: 'boolean',
description: item.description!.message,
};
} else if (item.type === 'list' && item.element?.type instanceof Map) {
options[item.name] = {
type: 'array',
items: {
type: 'string',
enum: Array.from(item.element.type.keys()),
},
description: item.description!.message,
};
} else if (item.type instanceof Map) {
options[item.name] = {
type: 'string',
description: item.description!.message,
enum: Array.from(item.type.keys()),
};
}
return options;
}, {});
return {
type: 'object',
properties: {
compilerOptions: {
type: 'object',
properties: properties,
},
},
};
}