How to auto-format with consistent indentation on similar assignments

36 Views Asked by At

When using auto-formatters of any kind, they seem to make certain parts of the code always look worse. The biggest one of these problems would be, that I cannot seem to consistently make it put indents on similar assignments. One example for this would be having multiple variables using UUIDs, such as:

#usual auto-formatting
short_name_UUID = "a47ac10b-58cc-4372-a567-0e02b2c3d479"
longer_name_UUID = "b47ac10b-58cc-4372-a567-0e02b2c3d479"
even_longer_name_UUID = "c47ac10b-58cc-4372-a567-0e02b2c3d479"

#ideal auto-formatting v1
short_name_UUID =       "a47ac10b-58cc-4372-a567-0e02b2c3d479"
longer_name_UUID =      "b47ac10b-58cc-4372-a567-0e02b2c3d479"
even_longer_name_UUID = "c47ac10b-58cc-4372-a567-0e02b2c3d479"

#ideal auto-formatting v2
short_name_UUID       = "a47ac10b-58cc-4372-a567-0e02b2c3d479"
longer_name_UUID      = "b47ac10b-58cc-4372-a567-0e02b2c3d479"
even_longer_name_UUID = "c47ac10b-58cc-4372-a567-0e02b2c3d479"

#ideal auto-formatting v2 (some variability in good formula formats)
short_name_formula   = (short_a  + 15)  ** 2   / b
longest_name_formula = (longer_a + 150) ** 100 / b

As you can see, v1 and v2 are more readable than usual auto-formatting due to similar data being aligned. I can imagine this being difficult to impossible in auto-formatting due to unrelated data being marked as related etc., although the data might be "related" by being assignments in neighbouring lines.

If there might be a slightly different looking way, that would still indent the data, this would also be a fine solution.

As of now, I've decided to completely abandon auto-format, or come up with same length variable names, that are intuitive enough to not compromise the time taken to remember the names.

So, the question is: Is there any conceptual way in auto-formatting in general, that would do this, and what implementation for at least one specific auto-formatter is there that does this?

0

There are 0 best solutions below