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

Error when using explicit resource management #182

Closed skycoop closed 1 month ago

skycoop commented 1 month ago

Your Environment

Describe the bug

When using keywords from Explicit Resource Management (i.e. using/await using), this plugin causes prettier to fail.

To Reproduce

Use using/await using in any file.

Expected behavior

No error

Screenshots, code sample, etc

# app/.server/utils/action.ts
...
await using fileStorage = new TempFileStorage("spanda-");
...

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

/** @type {import("prettier").Config} */
export default {
  plugins: [
    "@ianvs/prettier-plugin-sort-imports",
    "prettier-plugin-tailwindcss",
  ],
  importOrder: [
    "<BUILTIN_MODULES>",
    "",
    "^@remix-run/",
    "^react$",
    "<THIRD_PARTY_MODULES>",
    "",
    "^@\\/.*$",
    "^[.]",
    "",
    "^(?!.*[.]css$)[./].*$",
    ".css$",
  ],
  importOrderTypeScriptVersion: "5.0.0",
};

Error log

app/.server/utils/action.ts
[error] app/.server/utils/action.ts: SyntaxError: This experimental syntax requires enabling the parser plugin: "explicitResourceManagement". (119:4)

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

skycoop commented 1 month ago

Ah ok I found that adding explicitResourceManagement to importOrderParserPlugins fixes it. I half wonder if the error message could be improved to suggest this?

IanVS commented 1 month ago

Glad you figured it out. Feel free to try improving the error message, but it's coming from babel, so I think you'd need to make a PR there. It should probably at least be something like This experimental syntax requires enabling the _babel_ parser plugin ...