Skip to content

Commit fa49977

Browse files
committed
run jsonnetfmt on std.jsonnet
1 parent 23b1cdd commit fa49977

File tree

1 file changed

+50
-36
lines changed

1 file changed

+50
-36
lines changed

stdlib/std.jsonnet

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ limitations under the License.
125125
local aux(idx, ret, val) =
126126
if idx >= strLen then
127127
ret + [val]
128-
else if str[idx : idx + cLen : 1] == c &&
128+
else if str[idx:idx + cLen:1] == c &&
129129
(maxsplits == -1 || std.length(ret) < maxsplits) then
130130
aux(idx + cLen, ret + [val], '')
131131
else
@@ -891,7 +891,7 @@ limitations under the License.
891891
local
892892
escapeStringToml = std.escapeStringJson,
893893
escapeKeyToml(key) =
894-
local bare_allowed = std.set(std.stringChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"));
894+
local bare_allowed = std.set(std.stringChars('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'));
895895
if std.setUnion(std.set(std.stringChars(key)), bare_allowed) == bare_allowed then key else escapeStringToml(key),
896896
isTableArray(v) = std.isArray(v) && std.length(v) > 0 && std.all(std.map(std.isObject, v)),
897897
isSection(v) = std.isObject(v) || isTableArray(v),
@@ -917,19 +917,19 @@ limitations under the License.
917917
local separator = if inline then ' ' else '\n';
918918
local lines = ['[' + separator]
919919
+ std.join([',' + separator],
920-
[
921-
[new_indent + renderValue(v[i], indexedPath + [i], true, '')]
922-
for i in range
923-
])
920+
[
921+
[new_indent + renderValue(v[i], indexedPath + [i], true, '')]
922+
for i in range
923+
])
924924
+ [separator + (if inline then '' else cindent) + ']'];
925925
std.join('', lines)
926926
else if std.isObject(v) then
927927
local lines = ['{ ']
928928
+ std.join([', '],
929-
[
930-
[escapeKeyToml(k) + ' = ' + renderValue(v[k], indexedPath + [k], true, '')]
931-
for k in std.objectFields(v)
932-
])
929+
[
930+
[escapeKeyToml(k) + ' = ' + renderValue(v[k], indexedPath + [k], true, '')]
931+
for k in std.objectFields(v)
932+
])
933933
+ [' }'];
934934
std.join('', lines),
935935
renderTableInternal(v, path, indexedPath, cindent) =
@@ -939,10 +939,11 @@ limitations under the License.
939939
if !isSection(v[k])
940940
]);
941941
local sections = [std.join('\n', kvp)] + [
942-
(if std.isObject(v[k]) then
943-
renderTable(v[k], path + [k], indexedPath + [k], cindent)
944-
else
945-
renderTableArray(v[k], path + [k], indexedPath + [k], cindent)
942+
(
943+
if std.isObject(v[k]) then
944+
renderTable(v[k], path + [k], indexedPath + [k], cindent)
945+
else
946+
renderTableArray(v[k], path + [k], indexedPath + [k], cindent)
946947
)
947948
for k in std.objectFields(v)
948949
if isSection(v[k])
@@ -956,8 +957,8 @@ limitations under the License.
956957
local range = std.range(0, std.length(v) - 1);
957958
local sections = [
958959
(cindent + '[[' + std.join('.', std.map(escapeKeyToml, path)) + ']]'
959-
+ (if v[i] == {} then '' else '\n')
960-
+ renderTableInternal(v[i], path, indexedPath + [i], cindent + indent))
960+
+ (if v[i] == {} then '' else '\n')
961+
+ renderTableInternal(v[i], path, indexedPath + [i], cindent + indent))
961962
for i in range
962963
];
963964
std.join('\n\n', sections);
@@ -1076,11 +1077,24 @@ limitations under the License.
10761077
// the risk of missing a permutation.
10771078
local reserved = [
10781079
// Boolean types taken from https://yaml.org/type/bool.html
1079-
'true', 'false', 'yes', 'no', 'on', 'off', 'y', 'n',
1080+
'true',
1081+
'false',
1082+
'yes',
1083+
'no',
1084+
'on',
1085+
'off',
1086+
'y',
1087+
'n',
10801088
// Numerical words taken from https://yaml.org/type/float.html
1081-
'.nan', '-.inf', '+.inf', '.inf', 'null',
1089+
'.nan',
1090+
'-.inf',
1091+
'+.inf',
1092+
'.inf',
1093+
'null',
10821094
// Invalid keys that contain no invalid characters
1083-
'-', '---', '',
1095+
'-',
1096+
'---',
1097+
'',
10841098
];
10851099
local bad = [word for word in reserved if word == std.asciiLower(key)];
10861100
if std.length(bad) > 0 then
@@ -1120,7 +1134,7 @@ limitations under the License.
11201134
local keySet = std.set(keyChars);
11211135
local keySetLc = std.set(std.stringChars(keyLc));
11221136
// Check for unsafe characters
1123-
if ! onlyChars(safeChars, keySet) then
1137+
if !onlyChars(safeChars, keySet) then
11241138
false
11251139
// Check for reserved words
11261140
else if isReserved(key) then
@@ -1132,16 +1146,16 @@ limitations under the License.
11321146
- has exactly 2 dashes
11331147
are considered dates.
11341148
*/
1135-
else if onlyChars(dateChars, keySet)
1136-
&& std.length(std.findSubstr('-', key)) == 2 then
1149+
else if onlyChars(dateChars, keySet)
1150+
&& std.length(std.findSubstr('-', key)) == 2 then
11371151
false
11381152
/* Check for integers. Keys that meet all of the following:
11391153
- all characters match [0-9_\-]
11401154
- has at most 1 dash
11411155
are considered integers.
11421156
*/
11431157
else if onlyChars(intChars, keySetLc)
1144-
&& std.length(std.findSubstr('-', key)) < 2 then
1158+
&& std.length(std.findSubstr('-', key)) < 2 then
11451159
false
11461160
/* Check for binary integers. Keys that meet all of the following:
11471161
- all characters match [0-9b_\-]
@@ -1150,8 +1164,8 @@ limitations under the License.
11501164
are considered binary integers.
11511165
*/
11521166
else if onlyChars(binChars, keySetLc)
1153-
&& std.length(key) > 2
1154-
&& typeMatch(key, '0b') then
1167+
&& std.length(key) > 2
1168+
&& typeMatch(key, '0b') then
11551169
false
11561170
/* Check for floats. Keys that meet all of the following:
11571171
- all characters match [0-9e._\-]
@@ -1161,9 +1175,9 @@ limitations under the License.
11611175
are considered floats.
11621176
*/
11631177
else if onlyChars(floatChars, keySetLc)
1164-
&& std.length(std.findSubstr('.', key)) == 1
1165-
&& std.length(std.findSubstr('-', key)) < 3
1166-
&& std.length(std.findSubstr('e', keyLc)) < 2 then
1178+
&& std.length(std.findSubstr('.', key)) == 1
1179+
&& std.length(std.findSubstr('-', key)) < 3
1180+
&& std.length(std.findSubstr('e', keyLc)) < 2 then
11671181
false
11681182
/* Check for hexadecimals. Keys that meet all of the following:
11691183
- all characters match [0-9a-fx_\-]
@@ -1172,10 +1186,10 @@ limitations under the License.
11721186
- starts with (-)0x
11731187
are considered hexadecimals.
11741188
*/
1175-
else if onlyChars(hexChars, keySetLc)
1176-
&& std.length(std.findSubstr('-', key)) < 2
1177-
&& std.length(keyChars) > 2
1178-
&& typeMatch(key, '0x') then
1189+
else if onlyChars(hexChars, keySetLc)
1190+
&& std.length(std.findSubstr('-', key)) < 2
1191+
&& std.length(keyChars) > 2
1192+
&& typeMatch(key, '0x') then
11791193
false
11801194
// All checks pass. Key is safe for emission without quotes.
11811195
else true;
@@ -1518,7 +1532,7 @@ limitations under the License.
15181532
else
15191533
patch,
15201534

1521-
get(o, f, default = null, inc_hidden = true)::
1535+
get(o, f, default=null, inc_hidden=true)::
15221536
if std.objectHasEx(o, f, inc_hidden) then o[f] else default,
15231537

15241538
objectFields(o)::
@@ -1687,11 +1701,11 @@ limitations under the License.
16871701
__array_less_or_equal(arr1, arr2):: std.__compare_array(arr1, arr2) <= 0,
16881702
__array_greater_or_equal(arr1, arr2):: std.__compare_array(arr1, arr2) >= 0,
16891703

1690-
sum(arr):: std.foldl(function(a,b)a+b,arr,0),
1704+
sum(arr):: std.foldl(function(a, b) a + b, arr, 0),
16911705

1692-
xor(x, y):: x!=y,
1706+
xor(x, y):: x != y,
16931707

1694-
xnor(x, y):: x==y,
1708+
xnor(x, y):: x == y,
16951709

16961710
isEmpty(str):: std.length(str) == 0,
16971711
}

0 commit comments

Comments
 (0)