Photo by Oskar Yildiz on Unsplash
<some-component class="complicated div"
[title]="'test'"
subtitle="test div"
[color]="divColor"
>
<ul>
<li *ngFor="let item of list"
class="list-item"
>
<span i18n>list item</span>
{{item}}
</li>
</ul>
</some-component>
What do you think of the presented code style?
โค: Commit (something I could commit)
๐ท: Vomit (I'd never commit this)
๐ฆ: I like your post please continue this series!
Let's vote! ๐
Top comments (14)
I think its good to have attributes on multiple lines if they're too many, but if you're gonna have it on multiple lines, have all of them on multiple lines for a tag. This is what I would go for.
If some tag doesn't have that many attributes, maybe let them all be in a single line. If available, I'll definitely use a formatter for this so no one would have to worry about it individually and the styles would be consistent, because we all know if you give devs too much choice they'll spend weeks arguing about each one. Btw, I really like this post series.
And the difference between
and
Coming from Angular, honestly, I'd use brackets to pass data no matter what. This will allow you to pass a variable assigned in your TS file and remove static strings inside of your HTML. (I don't know if this makes sense to you). Otherwise, I agree with @faraazahmad .
Yes forgot to tell, it's an angular example ๐
I am on board with @faraazahmad 's example.
For properties I'd go with the non-bracketed
subtitle="test"
for simple stringsSame!! ๐
I agree with this + using brackets when appropriate.
Oh definitely separate lines for all attributes. If you only have one or two then all on the same line. Never split randomly in an impossible to read manner.
Anyway, I thought these days we all just have to do whatever the prettier overloads have deemed "the way"?
<li class="list-item">
๐Edit to add: I do like this "commit or vomit" format though, it's a very cool idea :D
To be clear: This is just an example, I'd also never add the class list-item to a li like this. ๐
I'd also like to see your preferred HTML code style in this matter!
This code doesn't seem to have run through the auto-formatter. So PR rejected, run prettier first :P
Yea this isn't even an issue really. What prettier wants, prettier gets.
I'm fine with it.