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.2k stars 127 forks source link

'SyntaxError: Decorators cannot be used to decorate parameters.' - Angular tests could be updated with correct combination of importOrderParserPlugins #123

Open adam-marshall opened 2 years ago

adam-marshall commented 2 years ago

Discussed in https://github.com/trivago/prettier-plugin-sort-imports/discussions/122

the Angular unit test fails due to an error SyntaxError: Decorators cannot be used to decorate parameters. if the example includes parameters with decorators.

the unit test could be updated and an FAQ added if different plugins are required to support this.

leomayer commented 2 years ago

I don't know what's the "correct" way to fix this issue. It is working for me with

"importOrderParserPlugins": ["typescript", "decorators-legacy"]

Just in case if somebody else stumbles over this bug.

Klariff commented 1 year ago

I don't know what's the "correct" way to fix this issue. It is working for me with

"importOrderParserPlugins": ["typescript", "decorators-legacy"]

Just in case if somebody else stumbles over this bug.

Where did you define that?

janeklb commented 1 year ago

Where did you define that?

In .prettierrc

laustdeleuran commented 8 months ago

I'm still seeing the SyntaxError: Decorators cannot be used to decorate parameters. error, even with

  importOrderParserPlugins: [
    'typescript',
    'classProperties',
    '["decorators", { "version": "legacy" }]',
  ]

Any advice?

laustdeleuran commented 8 months ago

Actually, what I get is just error Parsing error: prettier/prettier, on every instance of us using decorators on parameters, when running eslint.

If I try to run prettier directly, I get this:

SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "decorators", "decorators-legacy".

But I have it enabled, as you can tell from my config posted above.

laustdeleuran commented 8 months ago

Ah, this seem to be an actual bug in prettier-plugin-sort-imports.

locnt19 commented 4 months ago

Could you try a prettier config below? It's worked for me with the same issue.

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