Skip to content

Scheduling infrastructure for absolutely everyone.

Fix prettier importOrderSeparation not working (#1796)

Demian Caldelas04314f5e0578
diff --git a/.prettierrc.js b/.prettierrc.js
index a24db20059f..26ec750baa8 100644
--- a/.prettierrc.js
+++ b/.prettierrc.js
@@ -9,5 +9,5 @@ module.exports = {
arrowParens: "always",
importOrder: ["^@ee/(.*)$", "^@lib/(.*)$", "^@components/(.*)$", "^@(server|trpc)/(.*)$", "^[./]"],
importOrderSeparation: true,
- plugins: [require("prettier-plugin-tailwindcss")],
+ plugins: [require("./merged-prettier-plugin")],
};
diff --git a/merged-prettier-plugin.js b/merged-prettier-plugin.js
new file mode 100644
index 00000000000..cc77502db59
--- /dev/null
+++ b/merged-prettier-plugin.js
@@ -0,0 +1,21 @@
+/* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/31#issuecomment-1024722576 */
+const tailwind = require("prettier-plugin-tailwindcss");
+const sortImports = require("@trivago/prettier-plugin-sort-imports");
+
+const combinedFormatter = {
+ ...tailwind,
+ parsers: {
+ ...tailwind.parsers,
+ ...Object.keys(sortImports.parsers).reduce((acc, key) => {
+ acc[key] = {
+ ...tailwind.parsers[key],
+ preprocess(code, options) {
+ return sortImports.parsers[key].preprocess(code, options);
+ },
+ };
+ return acc;
+ }, {}),
+ },
+};
+
+module.exports = combinedFormatter;