trivago / prettier-plugin-sort-imports

A prettier plugin to sort imports in typescript and javascript files by the provided RegEx order.
Apache License 2.0
3.4k stars 135 forks source link

Plugin does not support TypeScript `using` keyword #285

Closed valtyr closed 9 months ago

valtyr commented 9 months ago

Your Environment

Describe the bug

The plugin does not support the explicit resource management using keyword in TypeScript.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management

To Reproduce

using foo = 'bar';

Expected behavior

I expected the plugin to support this syntax. It seems like the version of Babel that the plugin uses does not, without enabling a specific configuration flag.

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

{
  "tabWidth": 2,
  "singleQuote": true,
  "bracketSameLine": true,
  "trailingComma": "all",
  "importOrder": [
    "^(react|react-native)$",
    "<THIRD_PARTY_MODULES>",
    "^@/components/.*$",
    "^@/.*$",
    "^@euler/.*$",
    "^@api/.*$",
    "^~/.*$",
    "^[./]"
  ],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true,
  "plugins": [
    "@trivago/prettier-plugin-sort-imports",
    "prettier-plugin-tailwindcss"
  ]
}

Error log

[error] apps/api/src/worker.ts: SyntaxError: This experimental syntax requires enabling the parser plugin: explicitResourceManagement". (40:4)

Contribute to @trivago/prettier-plugin-sort-imports

valtyr commented 9 months ago

Just realized that you already expose the plugins as a config variable. Solved by updating my prettier config to include this:

    "importOrderParserPlugins": [
      "typescript",
      "jsx",
      "explicitResourceManagement"
    ],