unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue
https://www.npmjs.com/package/unplugin-vue-components
MIT License
3.66k stars 341 forks source link

fix: use of prettier-ignore #689

Closed alex12306 closed 10 months ago

alex12306 commented 10 months ago

Description

When I used prettier to format the code, I found that the components.d.ts file automatically generated by unplugin-vue-components was formatted, but the top of the file was written to prohibit eslint and prettier . After testing, I found that /* eslint-disable */ is effective, but /* prettier-ignore */ does not.

BUG reproduction: Before prettier formatting:

Snipaste_2023-09-05_21-55-06

After prettier formatting:

Snipaste_2023-09-05_21-55-19

You can see that single quotes have changed to double quotes, proving that/* prettier-ignore */has no effect

Then I checked the git history and found the changes proposed by this PR: https://github.com/unplugin/unplugin-vue-components/pull/597 The original intention of this change is to prevent eslint and prettier from formatting the entire file, not just the export {} line. So I added the last line /* prettier-ignore */ in the relevant code, this will ensure that the whole file will not be formatted and will not affect the functionality of other comments

Linked Issues

Additional context

stackblitz[bot] commented 10 months ago

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

antfu commented 10 months ago

I am impressed that Prettier does not allow ignoring the entire file via comments https://prettier.io/docs/en/ignore.html / https://github.com/prettier/prettier/issues/3634

In this case, I feel the fix is not solid enough, as we can't really prevent another statement in the middle. I'd suggest you add the file to .prettierignore as a workaround.

alex12306 commented 10 months ago

I am impressed that Prettier does not allow ignoring the entire file via comments https://prettier.io/docs/en/ignore.html / prettier/prettier#3634

In this case, I feel the fix is not solid enough, as we can't really prevent another statement in the middle. I'd suggest you add the file to .prettierignore as a workaround.

Yes it does not allow you to ignore an entire file through comments. I just look at the source code and see the generated code along with the comments and git history, and think maybe something is missing, so I'll just use.prettierignore (^ ^)

busybox11 commented 7 months ago

While I do agree that the .prettierignore is the best solution, unfortunately it doesn't work in my situation.

We sometimes have conflicts in this file, and saving it in VSCode triggers the auto formatting, even though it is in our .eslintignore AND .prettierignore definitions.

Having this rule everywhere would help us a lot - though this is only a supposition. Maybe there is a better way to do this that we haven't found. I'd like to know your opinion about this.