/
index.ts
100 lines (96 loc) · 2.94 KB
/
index.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 { RequiredOptions as PrettierRequiredOptions } from 'prettier';
import { parsers as babelParsers } from 'prettier/parser-babel';
import { parsers as flowParsers } from 'prettier/parser-flow';
import { parsers as typescriptParsers } from 'prettier/parser-typescript';
import { preprocessor } from './preprocessor';
import type { PrettierOptions } from './types';
// Not sure what the type from Prettier should be, but this is a good enough start.
interface PrettierOptionSchema {
type: string;
category: 'Global';
array?: boolean;
default: unknown;
description: string;
}
const options: Record<
Exclude<keyof PrettierOptions, keyof PrettierRequiredOptions>,
PrettierOptionSchema
> = {
importOrder: {
type: 'path',
category: 'Global',
array: true,
default: [{ value: [] }],
description: 'Provide an order to sort imports.',
},
importOrderCaseInsensitive: {
type: 'boolean',
category: 'Global',
default: false,
description: 'Provide a case sensitivity boolean flag',
},
importOrderParserPlugins: {
type: 'path',
category: 'Global',
array: true,
// By default, we add ts and jsx as parsers but if users define something
// we take that option
default: [{ value: ['typescript', 'jsx'] }],
description: 'Provide a list of plugins for special syntax',
},
importOrderSeparation: {
type: 'boolean',
category: 'Global',
default: false,
description: 'Should imports be separated by new line?',
},
importOrderGroupNamespaceSpecifiers: {
type: 'boolean',
category: 'Global',
default: false,
description:
'Should namespace specifiers be grouped at the top of their group?',
},
importOrderSortSpecifiers: {
type: 'boolean',
category: 'Global',
default: false,
description: 'Should specifiers be sorted?',
},
importOrderBuiltinModulesToTop: {
type: 'boolean',
category: 'Global',
default: false,
description: 'Should node-builtins be hoisted to the top?',
},
importOrderMergeDuplicateImports: {
type: 'boolean',
category: 'Global',
default: false,
description: 'Should duplicate imports be merged?',
},
importOrderMergeTypeImportsIntoRegular: {
type: 'boolean',
category: 'Global',
default: false,
description:
'Should import-type expressions be merged into import-value expressions?',
},
};
module.exports = {
parsers: {
babel: {
...babelParsers.babel,
preprocess: preprocessor,
},
flow: {
...flowParsers.flow,
preprocess: preprocessor,
},
typescript: {
...typescriptParsers.typescript,
preprocess: preprocessor,
},
},
options,
};