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.37k stars 133 forks source link

Unexpected token for import attribute "with" #294

Closed jase88 closed 6 months ago

jase88 commented 6 months ago

Your Environment

Describe the bug

Error if using import attribute with:

SyntaxError: Unexpected token, expected "{"

To Reproduce

import something from './something.json' with { type: 'json' };

https://v8.dev/features/import-attributes#deprecation-and-eventual-removal-of-assert

Expected behavior

Formatting works as for assert with importAssertions

import something from './something.json' assert { type: 'json' };

Screenshots, code sample, etc

see above

Configuration File (.prettierrc)

{
  "plugins": ["@trivago/prettier-plugin-sort-imports"],
  "singleQuote": true,
  "trailingComma": "es5",
  "importOrder": ["<THIRD_PARTY_MODULES>", "^@company/(.*)$", "^[./]"],
  "importOrderParserPlugins": ["typescript", "decorators-legacy", "importAttributes"],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true
}

Error log

✖ prettier --write: [error] script.mjs: SyntaxError: Unexpected token, expected "{" (2:58) [error] 1 | import something from './something.json' assert { type: 'json' };

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

jase88 commented 6 months ago

Probably duplicate of https://github.com/trivago/prettier-plugin-sort-imports/issues/270