Skip to content

Instantly share code, notes, and snippets.

@nirtamir2
Last active February 27, 2022 21:25
Show Gist options
  • Save nirtamir2/8833046af60233e5f5557d5bc2352579 to your computer and use it in GitHub Desktop.
Save nirtamir2/8833046af60233e5f5557d5bc2352579 to your computer and use it in GitHub Desktop.
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",
},
},
],
};
@nirtamir2
Copy link
Author

nirtamir2 commented Mar 26, 2021

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).

    {
      "files": "i18n/**.json",
      "options": {
        "printWidth": 100000
      }
    }

Or

 {
      "files": "**/i18n/locales/*.ts",
      "options": {
        "printWidth": 10000
      }
   }

@nirtamir2
Copy link
Author

nirtamir2 commented Mar 26, 2021

Plugins:

@nirtamir2
Copy link
Author

nirtamir2 commented Mar 26, 2021

pnpm add -D prettier prettier-plugin-packagejson @trivago/prettier-plugin-sort-imports @nirtamir2/prettier-plugin-css-order

@nirtamir2
Copy link
Author

nirtamir2 commented Mar 26, 2021

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.

@nirtamir2
Copy link
Author

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