-
Notifications
You must be signed in to change notification settings - Fork 30
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
build: setup Prettier with ESLint #121
Conversation
@antfu thank you so much for this! I tested it out today, and it works except it doesn't seem to have any of the Vue recommended rules. Can you add in the Vue3 recommended rule sets? Getting those to work and not conflict with Prettier and ES Lint is very confusing. It also worth mentioning that it seems to require these two VS Code plugins to work, which is fine, just documenting it here for future: |
Just the Vue recommended set. Perhaps I have this wrong, it didn’t appear to be doing the basics like attributes on multiple lines when I looked. https://eslint.vuejs.org/rules/#priority-c-recommended-potentially-dangerous-patterns |
Yeah, so I tried it with a more complicated component, and I get a flash of formatting, then back to what it was. Here is a video of what I see: |
I see. That's the one of the reason I personally won't recommend using Prettier - it doesn't give you granular control over newlines - and it's fundamentally by design of their approach. I guess you need to make the trade-off here by not using Prettier, or not care about this rule |
OK I see. Is it possible to achieve the same thing with ES Lint then? I thought it didn’t really handle CSS? We did have ES Lint and Prettier working well in the 2.x branch, but that was Nuxt 2. |
Sorry, I was taking some day offs. I just pushed a commit that uses ESLint (with ESLint Stylistic) and disabled Prettier. Again I didn't commit the lock of formatting to make this PR easier to review - please run npm install and restart VS Code, and run |
OK so deactivate VS code prettier plugin, but keep the es lint plugin active? |
Yes, the config should already disabled Prettier so you don't need to do it manually |
OK, this is now linting Vue Also, it is not linting Again, just to re-state the goal here: Format and fix errors on save for Vue, CSS, HTML, JS, TS, MJS, and JSON files, respecting the Vue recommended style guide rules for Vue, and Prettier for the rest. Stretch goal would be PHP files too. |
Something I noticed, from this Stackoverflow post: https://stackoverflow.com/questions/79176202/getting-prettier-and-es-lint-working-on-save-with-nuxt-3/79188343#79188343 If I set my
Then my CSS files and blocks will be fixed on save, but Vue template recommended rules don't work then... |
Through process of elimination I figured out it was Man, I have to vent... Why the hell is this so hard?! 😭 |
So i tried using the exact setup shown here: https://stackoverflow.com/a/79188343/503546 It seems to run on all files now, but with weird results.
I'm at a dead end again. Would love your help from here @antfu. |
I am not sure I understand what you are looking for exactly. I see:
And I just installed the JSON plugin for you to add 4 space indent I committed the formatted result to this branch to better show you the result. Is there anything missing? |
|
From my test everything you mentioned should be working already, no? (see the diff of this PR for example) |
Thanks @antfu for persisting here. After your new changes, I tested the following:
Here is my screen recording showing the tests (except I didn't include HTML file). Screen.Recording.2024-12-11.at.10.15.33.AM.movSo just to be really specific, currently these needs to be implemented:
|
I fixed the CSS part for the format on saving. Should we have this merge and iterate then? |
OK, great. Merging, and can add SVG after |
#117 #118
This PR setup Prettier to use alongside with ESLint.
stylistic
in ESLintI didn't update the npm-lock, so CI might fails. After installing the packages, you might want to restart VS Code to have ESLint effective. Meanwhile there are some linting and formatting can be applied by running
npm run format
that I didn't cover in this PR