diff --git a/.changeset/perfect-goats-exercise.md b/.changeset/perfect-goats-exercise.md new file mode 100644 index 00000000..956f5838 --- /dev/null +++ b/.changeset/perfect-goats-exercise.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": patch +--- + +fix: compatibility with eslint-plugin-prettier diff --git a/src/main.ts b/src/main.ts index c8227535..60bdec0a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,8 +10,13 @@ export { type StyleContextSuccess, type StyleContextUnknownLang, } from "./parser/index.js"; -export * as meta from "./meta.js"; export { name } from "./meta.js"; +// If we use `export * as meta from "./meta.js"`, +// the structuredClone performed by eslint-plugin-prettier will fail, +// so we will need to re-export it as a plain object. +// https://github.com/prettier/eslint-plugin-prettier/blob/b307125faeb58b6dbfd5d8812b2dffcfdc8358df/eslint-plugin-prettier.js#L199 +import * as metaModule from "./meta.js"; +export const meta = { ...metaModule }; export type { SvelteConfig } from "./svelte-config/index.js"; export { AST, ParseError }; diff --git a/tests/fixtures/integrations/prettier-plugin/prettier.config.cjs b/tests/fixtures/integrations/prettier-plugin/prettier.config.cjs new file mode 100644 index 00000000..74301b30 --- /dev/null +++ b/tests/fixtures/integrations/prettier-plugin/prettier.config.cjs @@ -0,0 +1,3 @@ +module.exports = { + plugins: ["prettier-plugin-svelte"], +}; diff --git a/tests/fixtures/integrations/prettier-plugin/x-input.svelte b/tests/fixtures/integrations/prettier-plugin/x-input.svelte new file mode 100644 index 00000000..d38c4896 --- /dev/null +++ b/tests/fixtures/integrations/prettier-plugin/x-input.svelte @@ -0,0 +1,5 @@ + + +
{value}
diff --git a/tests/fixtures/integrations/prettier-plugin/x-output.json b/tests/fixtures/integrations/prettier-plugin/x-output.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/tests/fixtures/integrations/prettier-plugin/x-output.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/fixtures/integrations/prettier-plugin/x-setup.ts b/tests/fixtures/integrations/prettier-plugin/x-setup.ts new file mode 100644 index 00000000..70a21e9d --- /dev/null +++ b/tests/fixtures/integrations/prettier-plugin/x-setup.ts @@ -0,0 +1,24 @@ +import type { Linter } from "eslint"; +import { generateParserOptions } from "../../../src/parser/test-utils.js"; +import prettier from "eslint-plugin-prettier"; +import * as parser from "../../../../src/index.js"; +import globals from "globals"; + +export function getConfig(): Linter.Config { + return { + plugins: { + prettier, + }, + languageOptions: { + parser, + parserOptions: generateParserOptions(), + globals: { + ...globals.browser, + ...globals.es2021, + }, + }, + rules: { + "prettier/prettier": "error", + }, + }; +} diff --git a/tests/src/meta.ts b/tests/src/meta.ts index 28d849ea..e7e227f6 100644 --- a/tests/src/meta.ts +++ b/tests/src/meta.ts @@ -9,6 +9,6 @@ const expectedMeta = { describe("Test for meta object", () => { it("A parser should have a meta object.", () => { - assert.deepStrictEqual({ ...parser.meta }, expectedMeta); + assert.deepStrictEqual(parser.meta, expectedMeta); }); });