Last active
February 27, 2022 21:25
-
-
Save nirtamir2/8833046af60233e5f5557d5bc2352579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
plugins: [ | |
require.resolve("@trivago/prettier-plugin-sort-imports"), | |
require.resolve("prettier-plugin-packagejson"), | |
require.resolve("@nirtamir2/prettier-plugin-css-order"), | |
], | |
// @see https://github.com/trivago/prettier-plugin-sort-imports | |
importOrder: [ | |
"^react$", | |
"<THIRD_PARTY_MODULES>", | |
// Internal modules | |
"^@core/(.*)$", | |
"^@server/(.*)$", | |
"^@ui/(.*)$", | |
"^@*/(.*)$", | |
// Relative imports | |
"^[./]", | |
], | |
overrides: [ | |
{ | |
files: "*.svg", | |
options: { | |
parser: "html", | |
}, | |
}, | |
], | |
}; |
Plugins:
- prettier-plugin-packagejson sorts package.json files.
- @nirtamir2/prettier-plugin-css-order - sort css properties with order that I like.
- @trivago/prettier-plugin-sort-imports - sort imports with configuration.
- prettier-plugin-organize-imports sorts imports.
- prettier-plugin-style-order - sort css properties order.
- prettier-plugin-tailwindcss sort tailwindcss css classes.
pnpm add -D prettier prettier-plugin-packagejson @trivago/prettier-plugin-sort-imports @nirtamir2/prettier-plugin-css-order
FAQ
Using prettier for imports formatting instead of ESLint
I don't want to see any errors in the IDE due to bad import formatting (l don't use eslint-plugin-prettier). I think those should be handled well (I have a pre-commit hook for it), but it's also not an error. Prettier plugins should be faster than eslint for formatting, but eslint understands AST (abstract syntax tree) so it can infer the code better. Another reason is that those rules are slow - https://typescript-eslint.io/docs/linting/troubleshooting/#eslint-plugin-import.The package.json script for prettier is
"format": "prettier --write --ignore-unknown **",
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also - for i18n I used to add large enough
printWidth
so the keys will be one by one (and add eslint plugin to sort keys).Or