prettier-plugin-sort-imports icon indicating copy to clipboard operation
prettier-plugin-sort-imports copied to clipboard

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

Open adam-marshall opened this issue 2 years ago • 7 comments

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.

adam-marshall avatar Jan 12 '22 10:01 adam-marshall

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.

leomayer avatar Jul 29 '22 12:07 leomayer

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?

Klariff avatar Sep 20 '22 00:09 Klariff

Where did you define that?

In .prettierrc

janeklb avatar Sep 21 '22 08:09 janeklb

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 avatar Dec 02 '23 01:12 laustdeleuran

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 avatar Dec 02 '23 01:12 laustdeleuran

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"]
}

locnt19 avatar Apr 11 '24 05:04 locnt19