Skip to content

Commit

Permalink
feat: support handling .svelte files (#950)
Browse files Browse the repository at this point in the history
Co-authored-by: JounQin <[email protected]>
  • Loading branch information
robertheessels and JounQin authored Jan 20, 2024
1 parent 689f67a commit 8418438
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-foxes-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"prettier-eslint": minor
---

feat: support handling `.svelte` files
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
"JounQin (https://www.1stG.me) <[email protected]>"
],
"license": "MIT",
"peerDependencies": {
"prettier-plugin-svelte": "^3.0.0",
"svelte-eslint-parser": "*"
},
"peerDependenciesMeta": {
"prettier-plugin-svelte": {
"optional": true
},
"svelte-eslint-parser": {
"optional": true
}
},
"dependencies": {
"@typescript-eslint/parser": "^6.7.5",
"common-tags": "^1.4.0",
Expand Down Expand Up @@ -49,8 +61,11 @@
"nps": "^5.7.1",
"nps-utils": "^1.3.0",
"prettier-eslint-cli": "^8.0.0",
"prettier-plugin-svelte": "^3.1.2",
"rimraf": "^5.0.5",
"strip-indent": "^3.0.0"
"strip-indent": "^3.0.0",
"svelte": "^4.2.9",
"svelte-eslint-parser": "^0.33.1"
},
"engines": {
"node": ">=16.10.0"
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ const tests = [
output:
'<template>\n <div></div>\n</template>\n<script>\nfunction foo () {\n return "foo";\n}\n</script>\n<style></style>'
},
{
title: 'Svelte example',
input: {
prettierOptions: {
plugins: ['prettier-plugin-svelte'],
overrides: [{ files: '*.svelte', options: { parser: 'svelte' } }]
},
text: '<script>\nfunction foo() { return "foo" }\n</script>\n <div>test</div>\n<style>\n</style>',
filePath: path.resolve('./test.svelte')
},
output:
'<script>\n function foo() {\n return "foo";\n }\n</script>\n\n<div>test</div>\n\n<style>\n</style>'
},
{
title: 'GraphQL example',
input: {
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async function format(options) {
* `r.output` is the formatted string and `r.messages` is an array of
* message specifications from eslint.
*/
// eslint-disable-next-line complexity
async function analyze(options) {
const { logLevel = getDefaultLogLevel() } = options;
logger.setLevel(logLevel);
Expand Down Expand Up @@ -112,7 +113,8 @@ async function analyze(options) {
'.ts',
'.tsx',
'.mjs',
'.vue'
'.vue',
'.svelte'
];
const fileExtension = path.extname(filePath || '');

Expand All @@ -138,6 +140,10 @@ async function analyze(options) {
formattingOptions.eslint.parser ||= require.resolve('vue-eslint-parser');
}

if (['.svelte'].includes(fileExtension)) {
formattingOptions.eslint.parser ||= require.resolve('svelte-eslint-parser');
}

const eslintFix = await createEslintFix(formattingOptions.eslint, eslintPath);

if (prettierLast) {
Expand Down

0 comments on commit 8418438

Please sign in to comment.