Skip to content

Add Default Prettier Configuration for Angular Templates #30548

Closed

Description

@Mikastark

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

Hello Angular Team,

Since Angular v20, component files no longer use the .component suffix by default. As a result, associated template files (e.g., my-feature.html) are no longer automatically recognized by Prettier as Angular templates. This leads Prettier to fall back to its default HTML parser, which doesn't handle Angular-specific syntax correctly.

Proposed solution

To improve the developer experience and avoid formatting issues, it would be helpful for new Angular projects to include a default Prettier configuration specifying the Angular parser for .html files.

Suggested addition to package.json:

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

This configuration ensures consistent and correct formatting of Angular templates out of the box, without requiring manual setup from the developer. It aligns with Angular’s philosophy of providing strong defaults for common tooling.

Thanks for considering this improvement!

Alternatives considered

Instead of package.json, we could consider having a .prettierrc file to set prettier configuration.

Activity

  1. added
    needs: discussion
    on Jun 17, 2025
  2. vmasek commented on Jun 23, 2025

    @vmasek

    Example of the same control flow formatted by prettier (3.6.0)

    with .component suffix:

    Image

    and without the suffix:

    Image

  3. Mikastark commented on Jun 24, 2025

    @Mikastark
    Author

    Another simple and effective solution would be to set the ngHtml option to true by default for the @schematics/angular:component schematic in angular.json, like so:

    "schematics": {
      "@schematics/angular:component": {
        "ngHtml": true
      }
    }

    This change would suffix all component template files with .ng.html, enabling Prettier to automatically apply its Angular parser.

    The main challenge is that Prettier currently cannot distinguish Angular templates from regular HTML files unless they follow a specific naming convention like .ng.html.

  4. hybrist commented on Jun 24, 2025

    @hybrist
    Contributor

    This change would suffix all component template files with .ng.html, enabling Prettier to automatically apply its Angular parser.

    I only skimmed the prettier code and didn't try anything out but from what I've seen .ng.html has no special handling in prettier today. Or is that setup somewhere else?

  5. removed
    needs: discussion
    on Jun 24, 2025
  6. hybrist commented on Jun 24, 2025

    @hybrist
    Contributor

    We're adding the prettier section to new package.json files starting with the next release of v20. Thanks for bringing this up! This is definitely a sharp edge with the new filenames that we'll take another look at.

  7. robertIsaac commented on Jun 25, 2025

    @robertIsaac

    hi @jkrems
    why it was decided to go with prettier in the package.json instead of prettierrc file?

  8. angular-automatic-lock-bot commented on Jul 26, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions