dify icon indicating copy to clipboard operation
dify copied to clipboard

chore: use prettier to format code

Open TinsFox opened this issue 1 year ago • 1 comments

Description

Add prettier to automatically format the code when saving it so that it follows a consistent style. Currently works with eslint

Type of Change

Please delete options that are not relevant.

  • [x] Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement

How Has This Been Tested?

Feel free to modify the code and save it. But please make sure that format on save of vs code is turned on.

"editor.formatOnSave": true,

Suggested Checklist:

  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] My changes generate no new warnings
  • [x] I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

TinsFox avatar May 08 '24 11:05 TinsFox

I'm very sorry, I just saw that the project uses antfu's eslint configuration, and antfu does not use prettier. Maybe my PR should be closed.

But there are some issues that I think still need to be discussed

  1. The configuration of @antfu/eslint-config already supports eslint v9. The version in the project is still 8.x. Do we need to upgrade simultaneously?
  2. There are React related rules in @antfu/eslint-config, but our project is Next.js and there are still some differences. It may be necessary to rewrite some rules after upgrading to cover them.
  3. There are no tailwindcss related rules in @antfu/eslint-config. We need to introduce rules to restrict tailwindcss, such as repeated class use, class order, etc. Now there are situations where the same class is used image

My suggestion is to use eslint + prettier. Using the configuration of shadcn-ui can meet our basic needs. https://github.com/shadcn-ui/ui/blob/main/.eslintrc.json

TinsFox avatar May 09 '24 06:05 TinsFox

Prettier's opinionated nature often leads to undesirable results and cannot be optimized through configuration. Therefore, we prefer to use eslint for code formatting. Thank you for your suggestions on upgrading @antfu/eslint-config. Our team will choose an appropriate time to upgrade the plugin and relevant infrastructures, as upgrading lint rules may cause unwanted code conflicts. Given that we will not adopt prettier, close this for now.

nite-knite avatar May 11 '24 03:05 nite-knite