UNPKG

4.79 kBJavaScriptView Raw
1// flow-typed signature: 4eed8da2dc730dc33e7710b465eaa44b
2// flow-typed version: cc7a557b34/prettier_v1.x.x/flow_>=v0.56.x
3
4declare module "prettier" {
5 declare type AST = Object;
6 declare type Doc = Object;
7 declare type FastPath = Object;
8
9 declare type PrettierParserName =
10 | "babylon"
11 | "flow"
12 | "typescript"
13 | "postcss"
14 | "css"
15 | "less"
16 | "scss"
17 | "json"
18 | "graphql"
19 | "markdown"
20 | "vue";
21
22 declare type PrettierParser = {
23 [name: PrettierParserName]: (text: string, options?: Object) => AST
24 };
25
26 declare type CustomParser = (
27 text: string,
28 parsers: PrettierParser,
29 options: Options
30 ) => AST;
31
32 declare type Options = {|
33 printWidth?: number,
34 tabWidth?: number,
35 useTabs?: boolean,
36 semi?: boolean,
37 singleQuote?: boolean,
38 trailingComma?: "none" | "es5" | "all",
39 bracketSpacing?: boolean,
40 jsxBracketSameLine?: boolean,
41 arrowParens?: "avoid" | "always",
42 rangeStart?: number,
43 rangeEnd?: number,
44 parser?: PrettierParserName | CustomParser,
45 filepath?: string,
46 requirePragma?: boolean,
47 insertPragma?: boolean,
48 proseWrap?: "always" | "never" | "preserve",
49 plugins?: Array<string | Plugin>
50 |};
51
52 declare type Plugin = {
53 languages: SupportLanguage,
54 parsers: { [parserName: string]: Parser },
55 printers: { [astFormat: string]: Printer }
56 };
57
58 declare type Parser = {
59 parse: (
60 text: string,
61 parsers: { [parserName: string]: Parser },
62 options: Object
63 ) => AST,
64 astFormat: string
65 };
66
67 declare type Printer = {
68 print: (
69 path: FastPath,
70 options: Object,
71 print: (path: FastPath) => Doc
72 ) => Doc,
73 embed: (
74 path: FastPath,
75 print: (path: FastPath) => Doc,
76 textToDoc: (text: string, options: Object) => Doc,
77 options: Object
78 ) => ?Doc
79 };
80
81 declare type CursorOptions = {|
82 cursorOffset: number,
83 printWidth?: $PropertyType<Options, "printWidth">,
84 tabWidth?: $PropertyType<Options, "tabWidth">,
85 useTabs?: $PropertyType<Options, "useTabs">,
86 semi?: $PropertyType<Options, "semi">,
87 singleQuote?: $PropertyType<Options, "singleQuote">,
88 trailingComma?: $PropertyType<Options, "trailingComma">,
89 bracketSpacing?: $PropertyType<Options, "bracketSpacing">,
90 jsxBracketSameLine?: $PropertyType<Options, "jsxBracketSameLine">,
91 arrowParens?: $PropertyType<Options, "arrowParens">,
92 parser?: $PropertyType<Options, "parser">,
93 filepath?: $PropertyType<Options, "filepath">,
94 requirePragma?: $PropertyType<Options, "requirePragma">,
95 insertPragma?: $PropertyType<Options, "insertPragma">,
96 proseWrap?: $PropertyType<Options, "proseWrap">,
97 plugins?: $PropertyType<Options, "plugins">
98 |};
99
100 declare type CursorResult = {|
101 formatted: string,
102 cursorOffset: number
103 |};
104
105 declare type ResolveConfigOptions = {|
106 useCache?: boolean,
107 config?: string,
108 editorconfig?: boolean
109 |};
110
111 declare type SupportLanguage = {
112 name: string,
113 since: string,
114 parsers: Array<string>,
115 group?: string,
116 tmScope: string,
117 aceMode: string,
118 codemirrorMode: string,
119 codemirrorMimeType: string,
120 aliases?: Array<string>,
121 extensions: Array<string>,
122 filenames?: Array<string>,
123 linguistLanguageId: number,
124 vscodeLanguageIds: Array<string>
125 };
126
127 declare type SupportOption = {|
128 since: string,
129 type: "int" | "boolean" | "choice" | "path",
130 deprecated?: string,
131 redirect?: SupportOptionRedirect,
132 description: string,
133 oppositeDescription?: string,
134 default: SupportOptionValue,
135 range?: SupportOptionRange,
136 choices?: SupportOptionChoice
137 |};
138
139 declare type SupportOptionRedirect = {|
140 options: string,
141 value: SupportOptionValue
142 |};
143
144 declare type SupportOptionRange = {|
145 start: number,
146 end: number,
147 step: number
148 |};
149
150 declare type SupportOptionChoice = {|
151 value: boolean | string,
152 description?: string,
153 since?: string,
154 deprecated?: string,
155 redirect?: SupportOptionValue
156 |};
157
158 declare type SupportOptionValue = number | boolean | string;
159
160 declare type SupportInfo = {|
161 languages: Array<SupportLanguage>,
162 options: Array<SupportOption>
163 |};
164
165 declare type Prettier = {|
166 format: (source: string, options?: Options) => string,
167 check: (source: string, options?: Options) => boolean,
168 formatWithCursor: (source: string, options: CursorOptions) => CursorResult,
169 resolveConfig: {
170 (filePath: string, options?: ResolveConfigOptions): Promise<?Options>,
171 sync(filePath: string, options?: ResolveConfigOptions): Promise<?Options>
172 },
173 clearConfigCache: () => void,
174 getSupportInfo: (version?: string) => SupportInfo
175 |};
176
177 declare export default Prettier;
178}