Skip to content

Commit 9e84b3e

Browse files
authored
fix: compatibility with eslint-plugin-prettier (#612)
1 parent 009f4ca commit 9e84b3e

File tree

7 files changed

+45
-2
lines changed

7 files changed

+45
-2
lines changed

Diff for: .changeset/perfect-goats-exercise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: compatibility with eslint-plugin-prettier

Diff for: src/main.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ export {
1010
type StyleContextSuccess,
1111
type StyleContextUnknownLang,
1212
} from "./parser/index.js";
13-
export * as meta from "./meta.js";
1413
export { name } from "./meta.js";
14+
// If we use `export * as meta from "./meta.js"`,
15+
// the structuredClone performed by eslint-plugin-prettier will fail,
16+
// so we will need to re-export it as a plain object.
17+
// https://github.com/prettier/eslint-plugin-prettier/blob/b307125faeb58b6dbfd5d8812b2dffcfdc8358df/eslint-plugin-prettier.js#L199
18+
import * as metaModule from "./meta.js";
19+
export const meta = { ...metaModule };
1520
export type { SvelteConfig } from "./svelte-config/index.js";
1621

1722
export { AST, ParseError };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
plugins: ["prettier-plugin-svelte"],
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
let value = "Hello";
3+
</script>
4+
5+
<div>{value}</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Linter } from "eslint";
2+
import { generateParserOptions } from "../../../src/parser/test-utils.js";
3+
import prettier from "eslint-plugin-prettier";
4+
import * as parser from "../../../../src/index.js";
5+
import globals from "globals";
6+
7+
export function getConfig(): Linter.Config {
8+
return {
9+
plugins: {
10+
prettier,
11+
},
12+
languageOptions: {
13+
parser,
14+
parserOptions: generateParserOptions(),
15+
globals: {
16+
...globals.browser,
17+
...globals.es2021,
18+
},
19+
},
20+
rules: {
21+
"prettier/prettier": "error",
22+
},
23+
};
24+
}

Diff for: tests/src/meta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ const expectedMeta = {
99

1010
describe("Test for meta object", () => {
1111
it("A parser should have a meta object.", () => {
12-
assert.deepStrictEqual({ ...parser.meta }, expectedMeta);
12+
assert.deepStrictEqual(parser.meta, expectedMeta);
1313
});
1414
});

0 commit comments

Comments
 (0)