Skip to content

[Angular] Do not force lowercase for any attribute #5547

@YarnSphere

Description

@YarnSphere

I ran into this in an existing Angular project where I have an Input named itemType in an Angular directive. Prettier transforms my itemType attribute into itemtype since I'm applying it to a div element and itemtype is a known global attribute. However, this breaks the binding with the Angular Input in the directive.

This type of transformation is likely always unsafe in the Angular world, even if there is no noticeable directive being applied to the element, since I can have a directive with a generic selector such as div and custom Inputs on it.

For now I'm using Angular's square bracket notation: [itemType]="'x'". This might even be the best option (since it avoids conflicts with the native itemtype attribute). However, Prettier should probably not break user-code, so I'd qualify this as a bug.

Prettier 1.15.2
Playground link

--parser angular

Input:

<div someDirective itemType="x"></div>

Output:

<div someDirective itemtype="x"></div>

Expected behavior (unchanged):

<div someDirective itemType="x"></div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:angularIssues affecting Angular template (not general JS/TS issues used for Angular)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions