google / google/jsonnet

jsonnetfmt chooses weird hanging indent

Open
#1,009 1 comment 0 reactions 0 assignees View on GitHub
enhancement formatter
Dominant language
Jsonnet
Stars
7.6k
Forks
475
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.