1
1
import type { OptionsFormatters , StylisticConfig , TypedFlatConfigItem } from '../types'
2
- import type { VendoredPrettierOptions } from '../vender/prettier-types'
2
+ import type { VendoredPrettierOptions , VendoredPrettierRuleOptions } from '../vender/prettier-types'
3
3
4
4
import { isPackageExists } from 'local-pkg'
5
5
import { GLOB_ASTRO , GLOB_ASTRO_TS , GLOB_CSS , GLOB_GRAPHQL , GLOB_HTML , GLOB_LESS , GLOB_MARKDOWN , GLOB_POSTCSS , GLOB_SCSS , GLOB_SVG , GLOB_XML } from '../globs'
6
6
7
7
import { ensurePackages , interopDefault , isPackageInScope , parserPlain } from '../utils'
8
8
import { StylisticConfigDefaults } from './stylistic'
9
9
10
+ function mergePrettierOptions (
11
+ options : VendoredPrettierOptions ,
12
+ overrides : VendoredPrettierRuleOptions = { } ,
13
+ ) : VendoredPrettierRuleOptions {
14
+ return {
15
+ ...options ,
16
+ ...overrides ,
17
+ plugins : [
18
+ ...( overrides . plugins || [ ] ) ,
19
+ ...( options . plugins || [ ] ) ,
20
+ ] ,
21
+ }
22
+ }
23
+
10
24
export async function formatters (
11
25
options : OptionsFormatters | true = { } ,
12
26
stylistic : StylisticConfig = { } ,
@@ -57,7 +71,7 @@ export async function formatters(
57
71
options . prettierOptions || { } ,
58
72
)
59
73
60
- const prettierXmlOptions = {
74
+ const prettierXmlOptions : VendoredPrettierOptions = {
61
75
xmlQuoteAttributes : 'double' ,
62
76
xmlSelfClosingSpace : true ,
63
77
xmlSortAttributesByKey : false ,
@@ -95,10 +109,9 @@ export async function formatters(
95
109
rules : {
96
110
'format/prettier' : [
97
111
'error' ,
98
- {
99
- ...prettierOptions ,
112
+ mergePrettierOptions ( prettierOptions , {
100
113
parser : 'css' ,
101
- } ,
114
+ } ) ,
102
115
] ,
103
116
} ,
104
117
} ,
@@ -111,10 +124,9 @@ export async function formatters(
111
124
rules : {
112
125
'format/prettier' : [
113
126
'error' ,
114
- {
115
- ...prettierOptions ,
127
+ mergePrettierOptions ( prettierOptions , {
116
128
parser : 'scss' ,
117
- } ,
129
+ } ) ,
118
130
] ,
119
131
} ,
120
132
} ,
@@ -127,10 +139,9 @@ export async function formatters(
127
139
rules : {
128
140
'format/prettier' : [
129
141
'error' ,
130
- {
131
- ...prettierOptions ,
142
+ mergePrettierOptions ( prettierOptions , {
132
143
parser : 'less' ,
133
- } ,
144
+ } ) ,
134
145
] ,
135
146
} ,
136
147
} ,
@@ -147,10 +158,9 @@ export async function formatters(
147
158
rules : {
148
159
'format/prettier' : [
149
160
'error' ,
150
- {
151
- ...prettierOptions ,
161
+ mergePrettierOptions ( prettierOptions , {
152
162
parser : 'html' ,
153
- } ,
163
+ } ) ,
154
164
] ,
155
165
} ,
156
166
} )
@@ -166,14 +176,12 @@ export async function formatters(
166
176
rules : {
167
177
'format/prettier' : [
168
178
'error' ,
169
- {
170
- ...prettierXmlOptions ,
171
- ...prettierOptions ,
179
+ mergePrettierOptions ( { ...prettierXmlOptions , ...prettierOptions } , {
172
180
parser : 'xml' ,
173
181
plugins : [
174
182
'@prettier/plugin-xml' ,
175
183
] ,
176
- } ,
184
+ } ) ,
177
185
] ,
178
186
} ,
179
187
} )
@@ -188,14 +196,12 @@ export async function formatters(
188
196
rules : {
189
197
'format/prettier' : [
190
198
'error' ,
191
- {
192
- ...prettierXmlOptions ,
193
- ...prettierOptions ,
199
+ mergePrettierOptions ( { ...prettierXmlOptions , ...prettierOptions } , {
194
200
parser : 'xml' ,
195
201
plugins : [
196
202
'@prettier/plugin-xml' ,
197
203
] ,
198
- } ,
204
+ } ) ,
199
205
] ,
200
206
} ,
201
207
} )
@@ -223,11 +229,10 @@ export async function formatters(
223
229
[ `format/${ formater } ` ] : [
224
230
'error' ,
225
231
formater === 'prettier'
226
- ? {
227
- ...prettierOptions ,
228
- embeddedLanguageFormatting : 'off' ,
229
- parser : 'markdown' ,
230
- }
232
+ ? mergePrettierOptions ( prettierOptions , {
233
+ embeddedLanguageFormatting : 'off' ,
234
+ parser : 'markdown' ,
235
+ } )
231
236
: {
232
237
...dprintOptions ,
233
238
language : 'markdown' ,
@@ -246,14 +251,13 @@ export async function formatters(
246
251
rules : {
247
252
'format/prettier' : [
248
253
'error' ,
249
- {
250
- ...prettierOptions ,
254
+ mergePrettierOptions ( prettierOptions , {
251
255
embeddedLanguageFormatting : 'off' ,
252
256
parser : 'slidev' ,
253
257
plugins : [
254
258
'prettier-plugin-slidev' ,
255
259
] ,
256
- } ,
260
+ } ) ,
257
261
] ,
258
262
} ,
259
263
} )
@@ -270,13 +274,12 @@ export async function formatters(
270
274
rules : {
271
275
'format/prettier' : [
272
276
'error' ,
273
- {
274
- ...prettierOptions ,
277
+ mergePrettierOptions ( prettierOptions , {
275
278
parser : 'astro' ,
276
279
plugins : [
277
280
'prettier-plugin-astro' ,
278
281
] ,
279
- } ,
282
+ } ) ,
280
283
] ,
281
284
} ,
282
285
} )
@@ -306,10 +309,9 @@ export async function formatters(
306
309
rules : {
307
310
'format/prettier' : [
308
311
'error' ,
309
- {
310
- ...prettierOptions ,
312
+ mergePrettierOptions ( prettierOptions , {
311
313
parser : 'graphql' ,
312
- } ,
314
+ } ) ,
313
315
] ,
314
316
} ,
315
317
} )
0 commit comments