kingyue737 / vitify-admin

🖖 Vite + Vuetify, Opinionated Admin Starter Template
https://vitify-admin.netlify.app/
MIT License
149 stars 14 forks source link

Do we need to specify editorconfig in .prettierrc? #6

Closed paolodina closed 2 years ago

paolodina commented 2 years ago

Hi and thanks for the wonderful work you did.

After cloning the repo and open some file I see a lot of prettier warnings like

image

Not a huge problem, but I tried to run prettier manually getting another kind of warning

$ pnpm exec prettier --check src/*
Checking formatting...
[warn] Ignored unknown option { editorconfig: true }.
[warn] src/api/users.ts
[warn] Ignored unknown option { editorconfig: true }.
[warn] src/App.vue
...etc...

Now:

paolodina commented 2 years ago

It's also uncommon that after prettier has run, adding the fixed files to git gives:

$ git add .
...
warning: CRLF will be replaced by LF in src/components/layout/AppBreadcrumbs.vue.
The file will have its original line endings in your working directory
warning: CRLF will be replaced by LF in src/components/layout/AppDrawer.vue.
The file will have its original line endings in your working directory
...
kingyue737 commented 2 years ago

Thank you very much, @paolodina ! You are right. editorconfig can be removed from .prettierrc as it will always be read by Prettier. I've never used Prettier CLI before, so I didn't notice this issue. We use Prettier extension and source files are automatically formatted when saved. It's a good idea to add a custom script to package.json or benefit git hooks to format code.

As all of my teammates are coding on Windows, I set eol to crlf. If you are using Linux, it is recommended to set lf as eol in .editorconfig.

end_of_line = lf

You can also select eol on status bar of VSCode.

image

warning: CRLF will be replaced by LF

As for the warning, I cannot reproduce it on my computer. I will investigate how to avoid this warning on different OS and with different git config. Maybe we should prevent git from converting eol.

kingyue737 commented 2 years ago

Oh I forgot one thing. Maybe we don't need a custom prettier script, because we already have pnpm lint. ESlint in this template is configured with eslint-plugin-prettier.

If you run pnpm lint, your code will be formatted according to prettier style.

paolodina commented 2 years ago

All clear, thanks!