New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

prettier-plugin-angular

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-angular

Prettier plugin for Angular HTML attribute alignment and sorting

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
267
-44.61%
Maintainers
1
Weekly downloads
 
Created
Source

prettier-plugin-angular

A Prettier plugin for Angular HTML templates that formats, aligns, and sorts element attributes.

What it does

Attribute alignment

Attributes are formatted using the minimum number of lines needed:

  • Single line — if everything fits within printWidth:

    <input type="text" [value]="v" />
    
  • Aligned — first attribute inline with the tag, rest aligned to the same column:

    <p-select [options]="companiesForSelector()"
              [attr.aria-invalid]="form.controls.companyId.invalid"
              id="companyId"
              class="w-full"
              filter
              showClear />
    
  • Fallback — if the tag itself is too long to inline the first attribute, each attribute on its own line indented by tabWidth:

    <my-very-long-component-name
      [options]="items"
      (change)="onChange($event)"
      class="w-full" />
    

Attribute sorting

Attributes are sorted by category in this order:

CategoryExamples
ref#myRef
structural*ngIf, *ngFor
twoWay[(ngModel)]
input[value], [disabled], [attr.aria-label]
output(click), (ngModelChange)
animation[@fadeIn]
staticid="x", class="foo", formControlName="x"
booleandisabled, required, showIcon

Multi-line attribute values preserved

Developer-written multi-line values (e.g. ternary expressions) are preserved and re-indented to match the attribute's column:

<p-select [options]="items"
          [attr.aria-describedby]="
            form.controls.companyId.invalid && form.controls.companyId.touched
              ? 'companyId-error'
              : null
          "
          id="companyId" />

Angular control flow formatted

Elements inside @if, @for, @switch, @defer and other Angular control flow blocks are fully formatted — not emitted verbatim:

@if (form.controls.companyId.invalid && form.controls.companyId.touched) {
  <small id="companyId-error" class="p-error block mt-1" role="alert">
    {{ 'validation.required' | translate }}
  </small>
}

Install

npm install -D prettier-plugin-angular

Configure

In .prettierrc:

{
  "plugins": ["prettier-plugin-angular"],
  "overrides": [
    {
      "files": "*.html",
      "options": {
        "parser": "angular-attributes",
        "angularAttributeSort": true
      }
    }
  ]
}

Options

OptionTypeDefaultDescription
angularAttributeSortbooleantrueSort attributes by category
angularAttributeOrderstring[]["ref","structural","twoWay","input","output","animation","static","boolean"]Category order (any subset, in your preferred order)

Full example

Input:

<p-select class="w-full" (change)="onChange($event)" [options]="items" inputId="x" #sel showIcon />

Output:

<p-select [options]="items"
          (change)="onChange($event)"
          inputId="x"
          class="w-full"
          #sel
          showIcon />

Keywords

prettier

FAQs

Package last updated on 13 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts