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

Angular Control Syntax issues #15833

Closed
rickvandermeij-aanzee opened this issue Dec 19, 2023 · 8 comments
Closed

Angular Control Syntax issues #15833

rickvandermeij-aanzee opened this issue Dec 19, 2023 · 8 comments

Comments

@rickvandermeij-aanzee
Copy link

After using the new Angular Control Syntax, prettier does not always indent correctly.

sometimes it works, sometimes it doesnt, but i cannot pinpoint why.

@if (mealType !== 'lodging' && !package) {
<span class="mx-0.5 text-base font-normal sm:text-lg"> + </span>
@switch (mealType.toLowerCase()) { @case ('breakfast') {
<svg-icon
	class="h-6 w-6 grow-0 text-dark-primary"
	data-test-id="breakfast-icon"
	src="assets/icons/icon-coffee-cup.svg"
/>
} @case ('halfboard') {
<svg-icon
	class="h-6 w-6 grow-0 text-dark-primary"
	data-test-id="halfboard-icon"
	src="assets/icons/icon-fork-knife.svg"
/>
} @default {
<svg-icon
	class="h-6 w-6 grow-0 text-dark-primary"
	data-test-id="fullboard-allin-icon"
	src="assets/icons/icon-checklist.svg"
/>
} } }

i think it has something to do when control statements are on a single line, then indentation doesnt work anymore

} @for (mealType of mealTypeKeys; track mealType) { @if (mealType) {

@fisker
Copy link
Member

fisker commented Dec 19, 2023

Can't reproduce

Prettier 3.1.1
Playground link

--parser angular

Input:

@if (mealType !== 'lodging' && !package) {
<span class="mx-0.5 text-base font-normal sm:text-lg"> + </span>
@switch (mealType.toLowerCase()) { @case ('breakfast') {
<svg-icon
	class="h-6 w-6 grow-0 text-dark-primary"
	data-test-id="breakfast-icon"
	src="assets/icons/icon-coffee-cup.svg"
/>
} @case ('halfboard') {
<svg-icon
	class="h-6 w-6 grow-0 text-dark-primary"
	data-test-id="halfboard-icon"
	src="assets/icons/icon-fork-knife.svg"
/>
} @default {
<svg-icon
	class="h-6 w-6 grow-0 text-dark-primary"
	data-test-id="fullboard-allin-icon"
	src="assets/icons/icon-checklist.svg"
/>
} } }

Output:

@if (mealType !== "lodging" && !package) {
  <span class="mx-0.5 text-base font-normal sm:text-lg"> + </span>
  @switch (mealType.toLowerCase()) {
    @case ("breakfast") {
      <svg-icon
        class="h-6 w-6 grow-0 text-dark-primary"
        data-test-id="breakfast-icon"
        src="assets/icons/icon-coffee-cup.svg"
      />
    }
    @case ("halfboard") {
      <svg-icon
        class="h-6 w-6 grow-0 text-dark-primary"
        data-test-id="halfboard-icon"
        src="assets/icons/icon-fork-knife.svg"
      />
    }
    @default {
      <svg-icon
        class="h-6 w-6 grow-0 text-dark-primary"
        data-test-id="fullboard-allin-icon"
        src="assets/icons/icon-checklist.svg"
      />
    }
  }
}

Next time please follow the issue template.

@fisker fisker added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Dec 19, 2023
@rickvandermeij-aanzee
Copy link
Author

thanks, i have to use parser angular instead of the default html when using the control syntax. will close the issue

@github-actions github-actions bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Dec 19, 2023
@msoler95
Copy link

msoler95 commented Feb 6, 2024

Thanks @fisker. If someone has this issue, in your .prettierrc add this to use the angular parser:

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

@jonelleamio
Copy link

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 ?

@emlim23
Copy link

emlim23 commented May 7, 2024

I have the same issue. I'm on prettier 3.2.5 and I've added that overrides in the .prettierrc, however the tab format for Angular 17 flow controls still doesn't work. Here's my .prettierrc file:

{ "printWidth": 120, "singleQuote": true, "useTabs": false, "tabWidth": 2, "semi": true, "bracketSpacing": true, "arrowParens": "always", "trailingComma": "none", "bracketSameLine": true, "overrides": [{ "files": "*.html", "options": { "parser": "angular" } }] }

Can somebody help?

@mvermand22
Copy link

mvermand22 commented May 17, 2024

I'm also on prettier 3.2.5 and no success with .prettierrc in project root:

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

@emlimlf
Copy link

emlimlf commented May 17, 2024

@mvermand22 I was able to figure it out. When I ran:
npx prettier --version
The version I was getting was 2.8~, maybe try checking there. What I did was force update the prettier version to 3.2^

@mvermand22
Copy link

@mvermand22 I was able to figure it out. When I ran: npx prettier --version The version I was getting was 2.8~, maybe try checking there. What I did was force update the prettier version to 3.2^

Hi, i'm already on v3.2.5, so that won't fix it for me. Thanks for the reply though.

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