IanVS / prettier-plugin-sort-imports

An opinionated but flexible prettier plugin to sort import statements
Apache License 2.0
1.03k stars 25 forks source link

Conflicts with prettier-plugin-tailwindcss #36

Closed mattiaz9 closed 2 years ago

mattiaz9 commented 2 years ago

Your Environment

Describe the bug

It seems like this plugin is conflicting with prettier-plugin-tailwindcss and by uninstalling prettier-plugin-sort-imports it starts to work again.

To Reproduce

Expected behavior

I expect the tailwind plugin to sort all my classes.

Screenshots, code sample, etc

Before installing prettier-plugin-sort-imports:

Screenshot 2022-09-07 at 18 57 43

After installing prettier-plugin-sort-imports:

Screenshot 2022-09-07 at 19 04 01

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

{
  "htmlWhitespaceSensitivity": "ignore",
  "printWidth": 100,
  "singleQuote": false,
  "semi": false,
  "useTabs": false,
  "proseWrap": "always",
  "arrowParens": "avoid",
  "bracketSpacing": true,
  "trailingComma": "es5",
  "importOrder": [
    "",
    "^react",
    "<THIRD_PARTY_MODULES>",
    "",
    ".s?css$",
    "^@heroicons",
    "^@/assets",
    "",
    "^[./]",
    "^@/",
    "",
    "<THIRD_PARTY_TYPES>",
    "<TYPE>"
  ],
  "importOrderSeparation": false,
  "importOrderMergeDuplicateImports": true,
  "plugins": [
    "prettier-plugin-tailwindcss",
    "@ianvs/prettier-plugin-sort-imports"
  ]
}

Error log

no errors

IanVS commented 2 years ago

Unfortunately this is a known issue since both plugins use some of the same APIs. You can read more, with some workarounds, in https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/9.

mattiaz9 commented 2 years ago

@IanVS thanks for the info, but unfortunately that workaround isn't working for me

IanVS commented 2 years ago

How about this one? https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/31#issuecomment-1195411734

mattiaz9 commented 2 years ago

@IanVS yes that worked, thank you! 🎉

felixgren commented 1 year ago

That fix didn't work for me due to TypeError: Cannot read properties of undefined (reading 'map').

This workaround solved it.

const baseConfig = require('../../prettier.config.cjs');

const pluginSortImports = require('@ianvs/prettier-plugin-sort-imports');
const pluginTailwindcss = require('prettier-plugin-tailwindcss');

/** @type {import("prettier").Plugin}  */
const mixedPlugin = {
  parsers: {
    typescript: {
      ...pluginTailwindcss.parsers.typescript,
      preprocess: pluginSortImports.parsers.typescript.preprocess,
    },
  },
  options: {
    ...pluginSortImports.options,
  },
};

module.exports = {
  ...baseConfig,
  tailwindConfig: './tailwind.config.cjs',
  plugins: [mixedPlugin],
};