google / google/go-jsonnet

Auto-replace implicit + with explicit + in jsonnetfmt.

Open
#496 13 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
Go
Stars
1.8k
Forks
263
PR merge metrics
No merged PRs in 30d

Description

Consider following example:
```
❯ cat example.jsonnet
[
{ key1: "something", key2: "something" }
{ key1: "something_else", key2: "something_else" },
]

❯ jsonnet example.jsonnet
[
{
"key1": "something_else",
"key2": "something_else"
}
]
```

In the example above, there is a missing comma which results in the two objects being merged together. Since the objects have the same fields, the first object simply disappears from the output. Errors like this one are very hard to spot.

I'm wondering why is the "plus sign" / "merge operator" optional. Requiring the operator would make it obvious if the programmer wants to merge objects or if they just forgot a comma. Is there a recommended way to avoid errors like this one? Am I missing something?

Follow up question:
Would it make sense to have an option for `jsonnetfmt` that produces Jsonnet code that includes the optional "merge operators"?

PS: Sorry if Github issues are a bad place for questions like this one. Feel free to direct me elsewhere.

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.