google / google/go-jsonnet

std.prune prunes hidden fields

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

Description

NOTE: This isn't go-specific.

`std.prune()` prunes hidden fields from objects. Is this intentional? I'm not familiar with any history here...

At the least we should document this, but it feels more like a bug. `std.prune()` removes whole objects that have `std.length() == 0`, where the length does not include hidden fields but that seems reasonable. But then, for the objects it does keep which have at least 1 non-hidden field, the hidden members are removed.

Currently in `stdast.go`:

```
"\n",
" prune(a)::\n",
" local isContent(b) =\n",
" if b == null then\n",
" false\n",
" else if std.isArray(b) then\n",
" std.length(b) > 0\n",
" else if std.isObject(b) then\n",
" std.length(b) > 0\n",
" else\n",
" true;\n",
" if std.isArray(a) then\n",
" [std.prune(x) for x in a if isContent($.prune(x))]\n",
" else if std.isObject(a) then {\n",
" [x]: $.prune(a[x])\n",
" for x in std.objectFields(a)\n",
" if isContent(std.prune(a[x]))\n",
" } else\n",
" a,\n",
"\n",
```

IMO that last bit should be `for x in std.objectFieldsAll(a)\n`.

Is a patch welcome? :)

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.