Hacker News new | past | comments | ask | show | jobs | submit login

I'm not sure you understood my example. Let's say we have:

    while (first && second) {
        third
    }
We might assign nesting levels like this:

    while(    1
    first &&  2
    second)   2
    third     2
which could lead to this line breaking:

    while (first &&
        second) {
        third
    }
This is bad because 'second' and 'third' are visually aligned, and so one might think that 'second' is in the loop body instead of the condition. We want to indent 'second' more than 'third', even though it has the same nesting level:

   while (first &&
          second) {
       third
   }
This is what I meant by "context dependent:" here we have two chunks at the same indentation level but that want different numbers of spaces. Does dartfmt attempt to handle this?



Ah, the style rules address this case. Bodies are indented +2 and wrapped expressions are +4. That means you will always get:

    while (first &&
        second) {
      third // <--
    }
So the body is indented less than the wrapped condition. Expression nesting is considered different from block nesting.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: