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
AngularJS HTML formatting incorrect #5449
Comments
There's a Show options on the bottom left, you have to specify the playgroundPrettier 1.15.2 --parser angular Input: <div class="row">
<div class="col-xs-4 col-md-2">
<b>{{'statisticsSendReportName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnit}}</b>
<p>{{dataStatisticsMap.get(timeUnit).reportsCount}}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b>{{'statisticsSendReportName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnitSecondary}}</b>
<p>{{dataStatisticsMap.get(timeUnitSecondary).reportsCount}}</p>
</div>
<div class="col-xs-4 col-md-2">
<b>{{"statisticsTimeFor" | i18n}} {{"statisticsLatest" | i18n}} {{"statisticsSendReportName" | i18n}}</b>
<p>{{dataStatisticsMap.get(timeUnit).latestReportTime}}</p>
</div>
<div class="col-xs-4 col-md-2">
<b>{{'statisticsEventName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnit}}</b>
<p>{{dataStatisticsMap.get(timeUnit).eventsCount}}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b>{{'statisticsEventName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnitSecondary}}</b>
<p>{{dataStatisticsMap.get(timeUnitSecondary).eventsCount}}</p>
</div>
<div class="col-xs-4 col-md-2">
<b>{{'statisticsPollName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnit}}</b>
<p>{{dataStatisticsMap.get(timeUnit).pollsCount}}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b>{{'statisticsPollName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnitSecondary}}</b>
<p>{{dataStatisticsMap.get(timeUnitSecondary).pollsCount}}</p>
</div>
<div class="col-xs-4 col-md-2">
<b>{{'statisticsPollStatusName' | i18n}} <span class="glyphicon glyphicon-info-sign" uib-tooltip="{{'statisticsPollStatusTooltip' | i18n }}" tooltip-placement="right"></span></b>
<p>{{dataStatisticsMap.get(timeUnit).pollIntervalStatusOk ? 'yes' : 'no' | i18n }}</p>
</div>
<div class="col-xs-4 col-md-2">
<b>{{'statisticsValidationErrorName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnit}}</b>
<p>{{dataStatisticsMap.get(timeUnit).validationErrorsCount}}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b>{{'statisticsValidationErrorName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnitSecondary}}</b>
<p>{{dataStatisticsMap.get(timeUnitSecondary).validationErrorsCount}}</p>
</div>
</div> Output: <div class="row">
<div class="col-xs-4 col-md-2">
<b
>{{ "statisticsSendReportName" | i18n }} {{ "statisticsLatest" | i18n }}
{{ timeUnit }}</b
>
<p>{{ dataStatisticsMap.get(timeUnit).reportsCount }}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b
>{{ "statisticsSendReportName" | i18n }} {{ "statisticsLatest" | i18n }}
{{ timeUnitSecondary }}</b
>
<p>{{ dataStatisticsMap.get(timeUnitSecondary).reportsCount }}</p>
</div>
<div class="col-xs-4 col-md-2">
<b
>{{ "statisticsTimeFor" | i18n }} {{ "statisticsLatest" | i18n }}
{{ "statisticsSendReportName" | i18n }}</b
>
<p>{{ dataStatisticsMap.get(timeUnit).latestReportTime }}</p>
</div>
<div class="col-xs-4 col-md-2">
<b
>{{ "statisticsEventName" | i18n }} {{ "statisticsLatest" | i18n }}
{{ timeUnit }}</b
>
<p>{{ dataStatisticsMap.get(timeUnit).eventsCount }}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b
>{{ "statisticsEventName" | i18n }} {{ "statisticsLatest" | i18n }}
{{ timeUnitSecondary }}</b
>
<p>{{ dataStatisticsMap.get(timeUnitSecondary).eventsCount }}</p>
</div>
<div class="col-xs-4 col-md-2">
<b
>{{ "statisticsPollName" | i18n }} {{ "statisticsLatest" | i18n }}
{{ timeUnit }}</b
>
<p>{{ dataStatisticsMap.get(timeUnit).pollsCount }}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b
>{{ "statisticsPollName" | i18n }} {{ "statisticsLatest" | i18n }}
{{ timeUnitSecondary }}</b
>
<p>{{ dataStatisticsMap.get(timeUnitSecondary).pollsCount }}</p>
</div>
<div class="col-xs-4 col-md-2">
<b
>{{ "statisticsPollStatusName" | i18n }}
<span
class="glyphicon glyphicon-info-sign"
uib-tooltip="{{'statisticsPollStatusTooltip' | i18n }}"
tooltip-placement="right"
></span
></b>
<p>
{{
dataStatisticsMap.get(timeUnit).pollIntervalStatusOk
? "yes"
: ("no" | i18n)
}}
</p>
</div>
<div class="col-xs-4 col-md-2">
<b
>{{ "statisticsValidationErrorName" | i18n }}
{{ "statisticsLatest" | i18n }} {{ timeUnit }}</b
>
<p>{{ dataStatisticsMap.get(timeUnit).validationErrorsCount }}</p>
</div>
<div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b
>{{ "statisticsValidationErrorName" | i18n }}
{{ "statisticsLatest" | i18n }} {{ timeUnitSecondary }}</b
>
<p>{{ dataStatisticsMap.get(timeUnitSecondary).validationErrorsCount }}</p>
</div>
</div>
What did you mean "mess up"? what's your expected behavior? |
Ok great! When using parser = angular, the playground got the same result as VS Code plugin. But what I mean by "mess up". This is the way it formats the <b
>{{ "statisticsEventName" | i18n }} {{ "statisticsLatest" | i18n }}
{{ timeUnit }}</b
> |
What's your expected output? |
I would expect it not to break the html tags in multiple lines. That only makes sense if there are multiple attributes?!? I would expect something like this: <div class="col-xs-4 col-md-2">
<b>
{{"statisticsTimeFor" | i18n}}
{{"statisticsLatest" | i18n}}
{{"statisticsSendReportName" | i18n}}
</b>
<p>{{dataStatisticsMap.get(timeUnit).latestReportTime}}</p>
</div> Hope I'm not coming off too critical. I really think Prettier is an awesome tool, and it's great that you have included HTML in it's arsenal. But in this particular case, the formatting seems a bit off. :) |
You may want to take a look at whitespace-sensitive formatting, that's why we cannot add whitespaces there as it'll break your code, but if you don't care about those whitespaces, just use (There're actually some ignorable whitespaces we didn't take into account, which is tracked in #5439.) playground with
|
The BTW should we document on https://prettier.io/blog/2018/11/07/1.15.0.html that AngularJS template should be parsed with |
I did mention it in the blog post, the issue here is probably same as #5462 (comment), where Angular did strip whitespaces (insensitive) in some cases. Unrelated: @JLHwung Would you mind to take look at #5368 (the regression there seems caused by upgrading cjk-regex from v1 to v2)? I did a quick fix in #5402 but I'm not quite sure if it's the proper fix given that I'm not too familiar with unicode. Thanks! |
By stressing @ikatyang On the fix in #5402, you did a great job! I have reviewed the code change and do find some rare cases and it should be addressed in #5480. |
I don't know anything about the implementation details, and the 1000 issues that you probably have to face to support every edge case. But as a user, I would rather prefer that For example, that this: <div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b>{{'statisticsSendReportName'|i18n}} {{"statisticsLatest" | i18n}} {{timeUnitSecondary}}</b>
<p>{{dataStatisticsMap.get(timeUnitSecondary).reportsCount}}</p>
</div> Would become: <div class="col-xs-4 col-md-2" ng-show="overviewSelected">
<b>
{{'statisticsSendReportName' | i18n}} {{'statisticsLatest' | i18n}} {{timeUnitSecondary}}
</b>
<p>{{dataStatisticsMap.get(timeUnitSecondary).reportsCount}}</p>
</div> |
I don't see anything that needs discussion or fixing in this issue. |
I'm testing out the new HTML formatting on a AngularJS project at work. But unfortunately it messes up the code. I'm running the latest version of the VSCode plugin.
I'll attach a GIF and the problematic markup for testing:
Imgur
Code:
When running the code on prettier.io > Try it out, I'm getting:
The text was updated successfully, but these errors were encountered: