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: use of prettier-ignore #689

Closed
wants to merge 1 commit into from

Conversation

alex12306
Copy link

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: #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
Copy link

stackblitz bot commented Sep 5, 2023

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

@antfu
Copy link
Member

antfu commented Sep 5, 2023

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.

@alex12306
Copy link
Author

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 (^ ^)

@alex12306 alex12306 closed this Sep 5, 2023
@busybox11
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants