From 84184387e6adadc4fb800194edfcf499a46585d4 Mon Sep 17 00:00:00 2001 From: Robert Heessels Date: Sat, 20 Jan 2024 16:32:02 +0100 Subject: [PATCH] feat: support handling `.svelte` files (#950) Co-authored-by: JounQin --- .changeset/fair-foxes-brake.md | 5 +++++ package.json | 17 ++++++++++++++++- src/__tests__/index.js | 13 +++++++++++++ src/index.js | 8 +++++++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .changeset/fair-foxes-brake.md diff --git a/.changeset/fair-foxes-brake.md b/.changeset/fair-foxes-brake.md new file mode 100644 index 00000000..abf86b30 --- /dev/null +++ b/.changeset/fair-foxes-brake.md @@ -0,0 +1,5 @@ +--- +"prettier-eslint": minor +--- + +feat: support handling `.svelte` files diff --git a/package.json b/package.json index 5fae637a..dd4905b9 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,18 @@ "JounQin (https://www.1stG.me) " ], "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", @@ -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" diff --git a/src/__tests__/index.js b/src/__tests__/index.js index a6c73eff..4c83d71e 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -193,6 +193,19 @@ const tests = [ output: '\n\n' }, + { + title: 'Svelte example', + input: { + prettierOptions: { + plugins: ['prettier-plugin-svelte'], + overrides: [{ files: '*.svelte', options: { parser: 'svelte' } }] + }, + text: '\n
test
\n', + filePath: path.resolve('./test.svelte') + }, + output: + '\n\n
test
\n\n' + }, { title: 'GraphQL example', input: { diff --git a/src/index.js b/src/index.js index 3426da22..4661b274 100644 --- a/src/index.js +++ b/src/index.js @@ -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); @@ -112,7 +113,8 @@ async function analyze(options) { '.ts', '.tsx', '.mjs', - '.vue' + '.vue', + '.svelte' ]; const fileExtension = path.extname(filePath || ''); @@ -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) {