1
1
import { isPackageExists } from 'local-pkg'
2
- import { GLOB_ASTRO , GLOB_ASTRO_TS , GLOB_CSS , GLOB_GRAPHQL , GLOB_HTML , GLOB_LESS , GLOB_MARKDOWN , GLOB_POSTCSS , GLOB_SCSS , GLOB_XML } from '../globs'
2
+ 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'
3
3
import type { VendoredPrettierOptions } from '../vender/prettier-types'
4
4
import { ensurePackages , interopDefault , isPackageInScope , parserPlain } from '../utils'
5
5
import type { OptionsFormatters , StylisticConfig , TypedFlatConfigItem } from '../types'
@@ -10,22 +10,24 @@ export async function formatters(
10
10
stylistic : StylisticConfig = { } ,
11
11
) : Promise < TypedFlatConfigItem [ ] > {
12
12
if ( options === true ) {
13
+ const isPrettierPluginXmlInScope = isPackageInScope ( '@prettier/plugin-xml' )
13
14
options = {
14
15
astro : isPackageInScope ( 'prettier-plugin-astro' ) ,
15
16
css : true ,
16
17
graphql : true ,
17
18
html : true ,
18
19
markdown : true ,
19
20
slidev : isPackageExists ( '@slidev/cli' ) ,
20
- xml : isPackageInScope ( '@prettier/plugin-xml' ) ,
21
+ svg : isPrettierPluginXmlInScope ,
22
+ xml : isPrettierPluginXmlInScope ,
21
23
}
22
24
}
23
25
24
26
await ensurePackages ( [
25
27
'eslint-plugin-format' ,
26
28
options . markdown && options . slidev ? 'prettier-plugin-slidev' : undefined ,
27
29
options . astro ? 'prettier-plugin-astro' : undefined ,
28
- options . xml ? '@prettier/plugin-xml' : undefined ,
30
+ ( options . xml || options . svg ) ? '@prettier/plugin-xml' : undefined ,
29
31
] )
30
32
31
33
if ( options . slidev && options . markdown !== true && options . markdown !== 'prettier' )
@@ -174,6 +176,28 @@ export async function formatters(
174
176
} ,
175
177
} )
176
178
}
179
+ if ( options . svg ) {
180
+ configs . push ( {
181
+ files : [ GLOB_SVG ] ,
182
+ languageOptions : {
183
+ parser : parserPlain ,
184
+ } ,
185
+ name : 'antfu/formatter/svg' ,
186
+ rules : {
187
+ 'format/prettier' : [
188
+ 'error' ,
189
+ {
190
+ ...prettierXmlOptions ,
191
+ ...prettierOptions ,
192
+ parser : 'xml' ,
193
+ plugins : [
194
+ '@prettier/plugin-xml' ,
195
+ ] ,
196
+ } ,
197
+ ] ,
198
+ } ,
199
+ } )
200
+ }
177
201
178
202
if ( options . markdown ) {
179
203
const formater = options . markdown === true
0 commit comments