Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compatibility with eslint-plugin-prettier #612

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading