&gt; Does dartfmt handle this? If not, do you have ideas on how it might?<p>Yes, it does! Correct indentation based for nested expressions is a vital feature for helping the reader understand the structure of the code.<p>The basic idea is fairly simple. Any place a line break may appear, you mark it with a number representing how deeply nested in the expression it is. So in code like:<p><pre><code>    function(outer(inner(first, second), third));
</code></pre>
You would get chunks whose expression nesting level is like:<p><pre><code>    function(   1
    outer(      2
    inner(      3
    first,      3
    second),    2
    third));
</code></pre>
When you line break, you ensure that its nesting level gets assigned a correct indentation level. Deeper nesting means deeper indentation:<p><pre><code>    function(
        outer(
            inner(
                first,
                second),
            third));
</code></pre>
There are a bunch of interesting edge cases, though. Some times a nesting level doesn&#x27;t happen on a line break, so it doesn&#x27;t need to get an indentation level associated with it:<p><pre><code>    function(outer(inner(
        first,
        second), third));
</code></pre>
Here, levels 1 and 2 don&#x27;t appear in line breaks, so we give the first indentation level to nesting level 3. There are stranger cases where you may assign a deeper level before a shallower one like:<p><pre><code>    function(outer(inner(
            first,
            second),
        third));
</code></pre>
Shaking out all of the bugs requires a lot of work and a really big test suite.<p>&gt; Also, how does it handle invalid input? I may want to reindent my code before it&#x27;s correct.<p>If the code doesn&#x27;t parse, it just exits with an error. Being able to run it on incomplete input would be useful, but I decided it was out of scope.<p>&gt; Also, did you explore constraint solvers instead of a graph traversal?<p>Good question! I have a little experience with them. I think the line between the two is sort of fuzzy. I didn&#x27;t approach it directly like a constraint solving problem, but it does have some features in common.