Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
radek-vizlib opened this issue Mar 8, 2024 · 7 comments

Comments

@radek-vizlib
Copy link

I've set .prettierrc with:

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

as suggested in prettier/prettier#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.

@akostmOR
Copy link

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

@Tucaen
Copy link

Tucaen commented Mar 18, 2024

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.

@jonelleamio
Copy link

jonelleamio commented Mar 20, 2024

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 ?

@radek-vizlib
Copy link
Author

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 prettier@3.2.5 -D
Then it will works as expected.

@tomasdev
Copy link

tomasdev commented Apr 5, 2024

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.

@BojanKogoj
Copy link

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.

@gindyo
Copy link

gindyo commented Apr 22, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants