File tree Expand file tree Collapse file tree 4 files changed +41
-2
lines changed
Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " prettier-eslint " : minor
3+ ---
4+
5+ feat: support handling ` .svelte ` files
Original file line number Diff line number Diff line change 2020 " JounQin (https://www.1stG.me) <[email protected] >" 2121 ],
2222 "license" : " MIT" ,
23+ "peerDependencies" : {
24+ "prettier-plugin-svelte" : " ^3.0.0" ,
25+ "svelte-eslint-parser" : " *"
26+ },
27+ "peerDependenciesMeta" : {
28+ "prettier-plugin-svelte" : {
29+ "optional" : true
30+ },
31+ "svelte-eslint-parser" : {
32+ "optional" : true
33+ }
34+ },
2335 "dependencies" : {
2436 "@typescript-eslint/parser" : " ^6.7.5" ,
2537 "common-tags" : " ^1.4.0" ,
4961 "nps" : " ^5.7.1" ,
5062 "nps-utils" : " ^1.3.0" ,
5163 "prettier-eslint-cli" : " ^8.0.0" ,
64+ "prettier-plugin-svelte" : " ^3.1.2" ,
5265 "rimraf" : " ^5.0.5" ,
53- "strip-indent" : " ^3.0.0"
66+ "strip-indent" : " ^3.0.0" ,
67+ "svelte" : " ^4.2.9" ,
68+ "svelte-eslint-parser" : " ^0.33.1"
5469 },
5570 "engines" : {
5671 "node" : " >=16.10.0"
Original file line number Diff line number Diff line change @@ -193,6 +193,19 @@ const tests = [
193193 output :
194194 '<template>\n <div></div>\n</template>\n<script>\nfunction foo () {\n return "foo";\n}\n</script>\n<style></style>'
195195 } ,
196+ {
197+ title : 'Svelte example' ,
198+ input : {
199+ prettierOptions : {
200+ plugins : [ 'prettier-plugin-svelte' ] ,
201+ overrides : [ { files : '*.svelte' , options : { parser : 'svelte' } } ]
202+ } ,
203+ text : '<script>\nfunction foo() { return "foo" }\n</script>\n <div>test</div>\n<style>\n</style>' ,
204+ filePath : path . resolve ( './test.svelte' )
205+ } ,
206+ output :
207+ '<script>\n function foo() {\n return "foo";\n }\n</script>\n\n<div>test</div>\n\n<style>\n</style>'
208+ } ,
196209 {
197210 title : 'GraphQL example' ,
198211 input : {
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ async function format(options) {
5656 * `r.output` is the formatted string and `r.messages` is an array of
5757 * message specifications from eslint.
5858 */
59+ // eslint-disable-next-line complexity
5960async function analyze ( options ) {
6061 const { logLevel = getDefaultLogLevel ( ) } = options ;
6162 logger . setLevel ( logLevel ) ;
@@ -112,7 +113,8 @@ async function analyze(options) {
112113 '.ts' ,
113114 '.tsx' ,
114115 '.mjs' ,
115- '.vue'
116+ '.vue' ,
117+ '.svelte'
116118 ] ;
117119 const fileExtension = path . extname ( filePath || '' ) ;
118120
@@ -138,6 +140,10 @@ async function analyze(options) {
138140 formattingOptions . eslint . parser ||= require . resolve ( 'vue-eslint-parser' ) ;
139141 }
140142
143+ if ( [ '.svelte' ] . includes ( fileExtension ) ) {
144+ formattingOptions . eslint . parser ||= require . resolve ( 'svelte-eslint-parser' ) ;
145+ }
146+
141147 const eslintFix = await createEslintFix ( formattingOptions . eslint , eslintPath ) ;
142148
143149 if ( prettierLast ) {
You can’t perform that action at this time.
0 commit comments