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
Change HTML/JSX formatting to have one attribute/prop per line #5501
Comments
While I agree that I'd like to see this being default behavior, I would suggest the following steps:
|
@lydell This probably also should have |
This comment has been minimized.
This comment has been minimized.
It looks neat only on simple examples. Consider this fragment: <h2 slot="header">What is your income?</h2>
<template v-if="employmentType === 'Entrepreneur'">
<ui-currency v-model="income.business.incomePrevYear" :minInclusive="0" required key="incomePrevYear">Last year income</ui-currency>
<ui-currency v-model="income.business.income" :minInclusive="0" required key="income">Current income</ui-currency>
<ui-date v-model="income.business.incomeToDate" :minDate="minDate" max-date="today" required>Income to date</ui-date>
<ui-currency v-model="income.business.taxableIncome" :minInclusive="0" required key="taxableIncome">Last year tax assessment base</ui-currency>
<ui-currency v-model="income.business.incomeTax" :minInclusive="0" required key="incomeTax">Tax value</ui-currency>
</template>
<template v-else>
<label class="field text salary">
<span class="label">Net income for last 3 months *</span>
<span>
<ui-currency v-model="income.personal.salaries[0].value" :minInclusive="0" required key="fMonth" placeholder="1. month*"></ui-currency>
<ui-currency v-model="income.personal.salaries[1].value" :minInclusive="0" required key="sMonth" placeholder="2. month *"></ui-currency>
<ui-currency v-model="income.personal.salaries[2].value" :minInclusive="0" required key="tMonth" placeholder="3. month *"></ui-currency>
</span>
</label>
<ui-currency v-model="income.personal.otherIncome" :minInclusive="0" key="otherIncome">Sum of other incomes</ui-currency>
</template>
<ui-select v-if="contract.calculatedProduct.class === 'ConsumerCredit'" v-model="income.personal.nonCashIncome" :options="decisions" :optionName="opt => opt ? 'Yes' : 'No'" required>Income sent to bank account</ui-select> The structure of the template is obvious, so is the data-binding. The other, less important information (validation, l10n,...) comes next. The point I am trying to make is that the vertical space matters. Wasting it (too much) has negative impact on code manageability. I would suggest to stick with object-literal-like formatting, which has two forms, either: const a = { prop1, prop1 }; or const a = {
prop1,
prop2,
}; From the two, the first one is currently missing (in HTML formatting). |
On the other hand, many diff tools are line-based. So by putting each attribute on it's own line, we reduce the number of conflicts a team has to solve. From the example above consider - <ui-currency v-model="income.business.incomePrevYear" :minInclusive="0" required key="incomePrevYear">Last year income</ui-currency>
+ <ui-currency v-model="income.business.incomePrevYear" :minInclusive="1" required key="incomePrevYear">Last year income</ui-currency> vs. <ui-currency
v-model="income.business.incomePrevYear"
- :minInclusive="0"
+ :minInclusive="1"
required
key="incomePrevYear"
>Last year income</ui-currency> |
Sure, if the division of labor has a form that results in many conflicts, then yes, it can help. Or if the formatting does not result in a "punch tape". |
I like the idea in concept, and to not have an option for this, however - I agree with @marosivanco's idea above of keeping it more like how objects are formatted today, and add what @scrimothy wrote here:
I think this should satisfy, or at least be acceptable, for most people - we both have no new option(s) yet still format the input, allowing both putting as many attributes/props as fit in the same line, or break each one to its own line (if the first attribute/prop is put in the line below the open tag). |
Any support for something like this would be great. At the moment, prettier only seems to collapse jsx attributes to be on a single line - of all of the proposed options, (for me) that's the least desirable. |
This would be very good to have |
Still no solution at this day ? |
Having that option would at least allow people to opt in. Is this something too time-consuming to implement? |
@webberwang See our (slightly outdated) option philosophy. |
I will say that since posting in this issue, I have adopted prettier across my projects, and I am absolutely never going back. The productivity increase far outweighs my old preferences for syntax formatting. 🎉 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@mbifulco While I agree buying into the Prettier opinions of syntactic styling allows for developers to focus on less trivial matters, I'd argue that this specific issue is more important than a strictly syntactic issue such as using tabs vs spaces (though I'm still very appreciative that Prettier allows tabs, even though that issue is one I would have "bought in" to). Here is why I see this as more than just "preferred syntax":
Disabling recommendations of major frameworks is one approach, but if Prettier defines one standard and doesn't adapt as the leading edge of development adapts, it will ultimately be left behind and replaced with something that does. That's my opinion, and of course reasonable people can disagree 🙂 |
/cc @vjeux Want you feedback. It is really hard to read when we have multiple properties in one lines |
This comment has been minimized.
This comment has been minimized.
Yes, I have read it and still think it is an elegant solution to the problem. At this point I would like to note that the last sentence of the yellow box points to the real problem. When I shorten or remove an attribute, the whole element collapses back to one line.
Edit: @lydell I am aware that this argument has already been discussed in detail. What I would like to say is: I guess there is no need for more reasons and there is no discussion. There will never be an option because of the philosophy. In my opinion, the formatting of multiline attributes in HTML (etc.) would have to follow the same principle as for Object Literals and others. Consistency is key. If not, as @sanmai-NL already asked in December - quite rightly - it would be time to remove the label and close this Issue. |
It's dismaying that the prettier team has dug their heels in on this based on philosophical grounds. The fact of the matter is that formatting rules for Javascript don't universally apply to JSX and vice versa. Attempts to do so result in undesirable output. Single line JSX props are preferred by the industry for 2+ props. ESLint does a fine job of linting and formatting. It takes some more configuration initially, but once that's done it's done. Switch over and save yourself the frustrations of talking to a brick wall. |
Shouldn't a good formatting tool provide options rather than force its own standard? Good luck with enforcing your "standards" |
@peacechen I think your "dug their heels in" captures the essence of it. Perhaps it is time to reconsider that logic based on the reasoning in this thread (and the similar one for #2550). No better solution to the original multi-line problem has been found for some time. In my opinion, now would be the right moment to consequently apply the workaround to other areas as well. @lydell Would you kindly get in touch with the rest of the Prettier team to advance this issue? Thank you very much. 🙂 |
year 2021. somebody fix this please for HTML 🥲 |
Being so close minded just amazes me |
I don't want to use prettier if this is the only option. I want to be able to have
instead of
The first one is obviously way better |
Nah I would drop review comment 😴. 2nd is easy to read. |
Is that a joke? Also what does drop review comment mean |
@samgermain haha just kidding man. Everyone has different choices 😀. I would prefer to keep precommit hooks to prettify using common config for same settings acrosss team workspace. Even if someone doesn't follow, atleast code in repo would be in same config for all |
Merged #6644 and I hope this will make life better for many |
Ailabouuu ❤️😘 |
@alexander-akait Sorry if this is an awkward question but when will this option make it to the Prettier VS Code extension? |
@AradAral I don't think that this change has been released yet. |
Now 3 months since last release, is there a todo before a new version can be released? 🤔 |
For VSCode users who find this single-line-per-prop rule as obnoxious as I do, create a {
"[javascriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.tabSize": 2 // other options as needed
},
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.tabSize": 2
}
} to disable prettier on you JSX files, or add the same content to your global settings.json file |
Thank you so much for this, this has solved it for the moment 👍 |
Similar to what was done for #3847 I think it best to break some of the discussion from #3101 into a new issue that people can 👍 or 👎.
I'm proposing that for HTML and JSX to have Prettier always have one attribute/prop per line (and thus not respect the developer's original preference). Code would then be formatted as shown below. This is in contrast to the current behaviour where we fit as much as possible with the print-width.
Expected behavior:
This suggestion for one attribute/prop per line was proposed several times in the discussion of #3101 but I think it is clearer if this is pulled into it's own proposal. The original proposal in #3101 is that Prettier would add an option to preserve original formatting which, while I agree with the author with the style that they want, I don't think a) an option, nor b) preserving original formatting follows the aims for Prettier (see also #2068). Instead I think the aims of #3101 are better served by this proposal to ignore the print-width and always place attributes/props on new lines (assuming that there is more than one).
This style appears to be the most common formatting for Angular, Vue and React from what I can tell. It style appears to be the style enforced by the rules:
The text was updated successfully, but these errors were encountered: