1
1
import { isPackageExists } from 'local-pkg'
2
- import { GLOB_ASTRO , GLOB_CSS , GLOB_GRAPHQL , GLOB_HTML , GLOB_LESS , GLOB_MARKDOWN , GLOB_POSTCSS , GLOB_SCSS } from '../globs'
2
+ import { GLOB_ASTRO , GLOB_CSS , GLOB_GRAPHQL , GLOB_HTML , GLOB_LESS , GLOB_MARKDOWN , GLOB_POSTCSS , GLOB_SCSS , GLOB_XML } from '../globs'
3
3
import type { VendoredPrettierOptions } from '../vender/prettier-types'
4
4
import { ensurePackages , interopDefault , parserPlain } from '../utils'
5
5
import type { OptionsFormatters , StylisticConfig , TypedFlatConfigItem } from '../types'
@@ -17,13 +17,15 @@ export async function formatters(
17
17
html : true ,
18
18
markdown : true ,
19
19
slidev : isPackageExists ( '@slidev/cli' ) ,
20
+ xml : isPackageExists ( '@prettier/plugin-xml' ) ,
20
21
}
21
22
}
22
23
23
24
await ensurePackages ( [
24
25
'eslint-plugin-format' ,
25
26
options . markdown && options . slidev ? 'prettier-plugin-slidev' : undefined ,
26
27
options . astro ? 'prettier-plugin-astro' : undefined ,
28
+ options . xml ? '@prettier/plugin-xml' : undefined ,
27
29
] )
28
30
29
31
if ( options . slidev && options . markdown !== true && options . markdown !== 'prettier' )
@@ -50,6 +52,13 @@ export async function formatters(
50
52
options . prettierOptions || { } ,
51
53
)
52
54
55
+ const prettierXmlOptions = {
56
+ xmlQuoteAttributes : 'double' ,
57
+ xmlSelfClosingSpace : true ,
58
+ xmlSortAttributesByKey : false ,
59
+ xmlWhitespaceSensitivity : 'ignore' ,
60
+ }
61
+
53
62
const dprintOptions = Object . assign (
54
63
{
55
64
indentWidth : typeof indent === 'number' ? indent : 2 ,
@@ -142,6 +151,29 @@ export async function formatters(
142
151
} )
143
152
}
144
153
154
+ if ( options . xml ) {
155
+ configs . push ( {
156
+ files : [ GLOB_XML ] ,
157
+ languageOptions : {
158
+ parser : parserPlain ,
159
+ } ,
160
+ name : 'antfu/formatter/xml' ,
161
+ rules : {
162
+ 'format/prettier' : [
163
+ 'error' ,
164
+ {
165
+ ...prettierXmlOptions ,
166
+ ...prettierOptions ,
167
+ parser : 'xml' ,
168
+ plugins : [
169
+ '@prettier/plugin-xml' ,
170
+ ] ,
171
+ } ,
172
+ ] ,
173
+ } ,
174
+ } )
175
+ }
176
+
145
177
if ( options . markdown ) {
146
178
const formater = options . markdown === true
147
179
? 'prettier'
0 commit comments