prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

VSCode Prettier 10.1.0 - doesn't work with angular Angular Control Syntax

Open radek-vizlib opened this issue 11 months ago • 7 comments

I've set .prettierrc with:

"overrides": {
    "files": ["*.html"],
    "options": {
        "parser": "angular"                  
     }
 }

as suggested in https://github.com/prettier/prettier/issues/15833 But seems that it doesn't work with the VSCode extension.

As in PLAYGROUD LINK

Expected behavior: INPUT:

@if (condition) { @if (anotherCondition) {
<div>ABC</div>
} } @else {
<div>DEF</div>
}

OUTPUT:

@if (condition) {
  @if (anotherCondition) {
    <div>ABC</div>
  }
} @else {
  <div>DEF</div>
}

But it doesn't work.

radek-vizlib avatar Mar 08 '24 11:03 radek-vizlib

The same problem here, I needed to disable the plugin, with @switch I have the same behaviour. Horrible and really hard to read.

akostmOR avatar Mar 12 '24 12:03 akostmOR

Another problem with the current VSCode Extension is:

Having something like this

@if (condition) {
    <div>ABC</div>
}

@if (anotherCondition) {
   <div>DEF</div>
} 

@if (thirdCondition) {
  <div>GHI</div>
}

results in

@if (condition) {
    <div>ABC</div>
} @if (anotherCondition) {
   <div>DEF</div>
} @if (thirdCondition) {
  <div>GHI</div>
}

In the prettier playground it works as expected.

Tucaen avatar Mar 18 '24 10:03 Tucaen

I use prettier inside eslint, so i tried this :

  {
      "files": ["*.component.html"],
      "extends": ["plugin:@angular-eslint/template/recommended", "plugin:prettier/recommended"],
      "rules": {
        "@angular-eslint/template/prefer-control-flow": "warn",
        "prettier/prettier": ["error", { "overrides": [{ "options": { "parser": "angular" } }] }]
      }
    }

which doesn't work while this inside .prettierrc works

    "overrides": [
    {
      "files": "*.component.html",
      "options": {
        "parser": "angular"
      }
    }
  ]

Can someone help ?

jonelleamio avatar Mar 20 '24 10:03 jonelleamio

The root cause is here https://github.com/prettier/prettier-vscode?tab=readme-ov-file#prettier-version-3

This is workaround: Add to devDependencies prettier that supports angular parser e.g. npm i [email protected] -D Then it will works as expected.

radek-vizlib avatar Mar 21 '24 07:03 radek-vizlib

For anyone using a context without a package.json, you can do the following:

  1. Enable "prettier.resolveGlobalModules": true in your VSCode settings.json
  2. npm i -g prettier to install latest prettier globally, as of today that is 3.2.5
  3. Ensure parser: angular in your prettier config as stated above.

This gave my .ng.html templates sooooo much better syntax than before.

tomasdev avatar Apr 05 '24 00:04 tomasdev

For anyone using a context without a package.json, you can do the following:

1. Enable `"prettier.resolveGlobalModules": true` in your VSCode settings.json

2. `npm i -g prettier` to install latest prettier globally, as of today that is 3.2.5

3. Ensure `parser: angular` in your prettier config as stated above.

This gave my .ng.html templates sooooo much better syntax than before.

Tried all that, no change.

BojanKogoj avatar Apr 05 '24 12:04 BojanKogoj

For me it turned out I had a reference to old version of prettier in my dev dependencies in package.json I updated it to v3.2.5 and it is working as it should.

gindyo avatar Apr 22 '24 03:04 gindyo

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

github-actions[bot] avatar Jun 22 '24 01:06 github-actions[bot]