DEV Community

Discussion on: βœ”||🀒 Commit or Vomit | code style

Collapse
 
faraazahmad profile image
Syed Faraaz Ahmad • Edited

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.

<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>
Enter fullscreen mode Exit fullscreen mode

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.

Collapse
 
jmdejager profile image
🐀πŸ₯‡ Jasper de Jager • Edited

And the difference between

[title]="'test'"
Enter fullscreen mode Exit fullscreen mode

and

subtitle="test div"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
annervisser profile image
Anner Visser

I am on board with @faraazahmad 's example.
For properties I'd go with the non-bracketed subtitle="test" for simple strings

Thread Thread
 
jmdejager profile image
🐀πŸ₯‡ Jasper de Jager

Same!! 😊

Collapse
 
theowlsden profile image
Shaquil Maria

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 .

Thread Thread
 
jmdejager profile image
🐀πŸ₯‡ Jasper de Jager

Yes forgot to tell, it's an angular example 😊

Collapse
 
sargalias profile image
Spyros Argalias

I agree with this + using brackets when appropriate.