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

[prettier-plugin-autocorrect] No changes are made #276

Open
queengooborg opened this issue Jul 27, 2023 · 4 comments
Open

[prettier-plugin-autocorrect] No changes are made #276

queengooborg opened this issue Jul 27, 2023 · 4 comments
Assignees
Labels
accepted bug Something isn't working enhancement New feature or request

Comments

@queengooborg
Copy link

After installing the plugin and telling Prettier to use it, none of the desired changes are produced for our Markdown files. When doing a little debugging, it appears that the print() function isn't getting called.

@JounQin
Copy link
Member

JounQin commented Jul 28, 2023

Can you provide a reproduction?

@queengooborg
Copy link
Author

Of course -- here's a basic script to reproduce the issue:

import assert from "node:assert";
import prettier from "prettier";
import autocorrect from "autocorrect-node";

const input =
  "**`:host`** [CSS](/zh-CN/docs/Web/CSS) [伪类](/zh-CN/docs/Web/CSS/Pseudo-classes) 选择内部使用了该CSS的[影子DOM(shadow DOM)](/zh-CN/docs/Web/API/Web_components/Using_shadow_DOM)的影子宿主(shadow host)——换句话说,这允许你从其影子DOM内部选择自定义元素。";
const expected = autocorrect.format(input);

const actual = await prettier.format(input, {
  parser: "markdown",
  plugins: ["prettier-plugin-autocorrect"],
});

assert.deepEqual(actual, expected);

(This is with Prettier v3.0.0 and prettier-plugin-autocorrect v0.4.1.)

@JounQin
Copy link
Member

JounQin commented Jul 28, 2023

OK, the problem is this prettier does not recognize to use prettier-plugin-autocorrect as its parser

import assert from "node:assert";
import prettier from "prettier";
import autocorrect from "autocorrect-node";

const input =
  "**`:host`** [CSS](/zh-CN/docs/Web/CSS) [伪类](/zh-CN/docs/Web/CSS/Pseudo-classes) 选择内部使用了该CSS的[影子DOM(shadow DOM)](/zh-CN/docs/Web/API/Web_components/Using_shadow_DOM)的影子宿主(shadow host)——换句话说,这允许你从其影子DOM内部选择自定义元素。";
const expected = autocorrect.formatFor(input, 'test.md'); // `formatFor` is required

const actual = await prettier.format(input, {
  parser: "autocorrect", // override default inferred parser
  plugins: ["prettier-plugin-autocorrect"],
  filepath: "test.md", // a filepath is required
});

assert.deepEqual(actual, expected);

However, this will make the default markdown printer unusable, I need to find a better solution for this.

@JounQin
Copy link
Member

JounQin commented Nov 27, 2023

I got the idea that we can detect the default parser for files in the autocorrect plugin automatically and run prettier without autocorrect first, and run autocorrect.formatFor after then.

@JounQin JounQin pinned this issue Nov 27, 2023
@JounQin JounQin self-assigned this Nov 27, 2023
@JounQin JounQin added bug Something isn't working enhancement New feature or request accepted labels Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants