Skip to content

Commit

Permalink
fix: compatibility with eslint-plugin-prettier (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Dec 2, 2024
1 parent 009f4ca commit 9e84b3e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-goats-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: compatibility with eslint-plugin-prettier
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: ["prettier-plugin-svelte"],
};
5 changes: 5 additions & 0 deletions tests/fixtures/integrations/prettier-plugin/x-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
let value = "Hello";
</script>

<div>{value}</div>
1 change: 1 addition & 0 deletions tests/fixtures/integrations/prettier-plugin/x-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
24 changes: 24 additions & 0 deletions tests/fixtures/integrations/prettier-plugin/x-setup.ts
Original file line number Diff line number Diff line change
@@ -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",
},
};
}
2 changes: 1 addition & 1 deletion tests/src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 9e84b3e

Please sign in to comment.