jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

jsonnetfmt chooses weird hanging indent

Open fedya-at-db opened this issue 3 years ago • 1 comments

Perhaps this is working as intended, but I found it quite surprising and it took some trial and error to see what exactly the fmt is focusing on. Both of the below snippets are how jsonnetfmt with no flag overrides chooses to format the code:

local A = {
  foo: true,
} + {
  bar: true,
};
local B = {
            foo: true,
          } +
          {
            bar: true,
          };

true

The key difference is whether we join the two objects with } + { or insert a newline before the {. This can produce some massive horizontal indentation in some nested object definitions as it tries to align everything on the first opening {.

I guess the positive is that you can control this yourself by keeping the { on the same line but it still feels like not a very useful formatted output.

fedya-at-db avatar Jul 19 '22 04:07 fedya-at-db

Another weird consequence of this is that comments are hard to place and often get aligned with the start brace even when other expressions don't.

local E = {
  foo: true,
} + {
  bar: true,
}
          // TODO: add more stuff
;

true

You can get around the above by moving the comment to be on the line with } but this seems like fighting your formatter and not working with it.

fedya-at-db avatar Jul 19 '22 06:07 fedya-at-db