dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Issue #586 follow-up: Too little indentation if named arguments come after a newline

Open danielzuncke opened this issue 2 years ago • 0 comments

From what I can tell this was the problem: (inside newline() function) When setting the new indentLevel, named function arguments didn't have their own case defined in the if-else section when a token pair "identifier", ":" is encountered. In the example from the issue thread this selected a case where indentLevel gets set to the same as the line with the previous { token.

Fix: named func args now have their own case which works the same as struct initializer: get indentLevel from previous tok!"(" and add 1.

Added a helper function to keep the if-condition a bit shorter and lazy. While it can return an out of bounds index, we are inside an if block which guarantees us, that it won't.
The helper function is repurposed from peekImplementation.

Updated existing tests, added test with --keep_line_breaks true to match the provided code in issue thread.

danielzuncke avatar Feb 03 '24 22:02 danielzuncke