Skip to content

Commit 74b3a1b

Browse files
committed
[Linter] Support std.member and std.repeat.
1 parent eeca44c commit 74b3a1b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

linter/internal/types/stdlib.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ func prepareStdlib(g *typeGraph) {
114114

115115
"makeArray": g.newSimpleFuncType(anyArrayType, "sz", "func"),
116116
"count": g.newSimpleFuncType(numberType, "arr", "x"),
117+
"member": g.newSimpleFuncType(numberType, "arr", "x"),
117118
"find": g.newSimpleFuncType(arrayOfNumber, "value", "arr"),
118119
"map": g.newSimpleFuncType(anyArrayType, "func", "arr"),
119120
"mapWithIndex": g.newSimpleFuncType(anyArrayType, "func", "arr"),
120121
"filterMap": g.newSimpleFuncType(anyArrayType, "filter_func", "map_func", "arr"),
122+
"flatMap": g.newSimpleFuncType(anyArrayType, "func", "arr"),
121123
"filter": g.newSimpleFuncType(anyArrayType, "func", "arr"),
122124
"foldl": g.newSimpleFuncType(anyType, "func", "arr", "init"),
123125
"foldr": g.newSimpleFuncType(anyType, "func", "arr", "init"),
126+
"repeat": g.newSimpleFuncType(anyArrayType, "what", "count"),
127+
"slice": g.newSimpleFuncType(arrayOfString, "indexable", "index", "end", "step"),
124128
"range": g.newSimpleFuncType(arrayOfNumber, "from", "to"),
125129
"join": g.newSimpleFuncType(stringOrArray, "sep", "arr"),
126130
"lines": g.newSimpleFuncType(arrayOfString, "arr"),
@@ -155,9 +159,7 @@ func prepareStdlib(g *typeGraph) {
155159
"manifestJson": g.newSimpleFuncType(stringType, "value"),
156160
"objectHasEx": g.newSimpleFuncType(boolType, "obj", "fname", "hidden"),
157161
"objectFieldsEx": g.newSimpleFuncType(arrayOfString, "obj", "hidden"),
158-
"flatMap": g.newSimpleFuncType(anyArrayType, "func", "arr"),
159162
"modulo": g.newSimpleFuncType(numberType, "x", "y"),
160-
"slice": g.newSimpleFuncType(arrayOfString, "indexable", "index", "end", "step"),
161163
"primitiveEquals": g.newSimpleFuncType(boolType, "x", "y"),
162164
"mod": g.newSimpleFuncType(stringOrNumber, "a", "b"),
163165
"native": g.newSimpleFuncType(anyFunctionType, "x"),

testdata/stdlib_smoke_test.golden

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
0,
5454
5
5555
],
56+
"flatMap": [
57+
2,
58+
3,
59+
4,
60+
6,
61+
6,
62+
9
63+
],
5664
"flattenArrays": [
5765
1,
5866
2,
@@ -118,6 +126,7 @@
118126
},
119127
"max": 3,
120128
"md5": "1bc29b36f623ba82aaf6724fd3b16718",
129+
"member": true,
121130
"mergePatch": { },
122131
"min": 2,
123132
"objectFields": [ ],
@@ -145,6 +154,7 @@
145154
4,
146155
5
147156
],
157+
"repeat": "foofoofoo",
148158
"set": [
149159
[
150160
1,
@@ -197,6 +207,7 @@
197207
],
198208
"sign": 1,
199209
"sin": -0.95892427466313845,
210+
"slice": "o",
200211
"sort": [
201212
[
202213
1,

testdata/stdlib_smoke_test.jsonnet

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@
101101
makeArray: std.makeArray(sz=5, func=function(i) i),
102102
count: std.count(arr=["a", "b", "c", "c"], x="b"),
103103
find: std.find(value=42, arr=[1, 2, 42, 3, 42]),
104+
member: std.member(arr=[1, 2, 3], x=2),
104105
map: std.map(func=function(x) -x, arr=[1, 2, 3]),
105106
mapWithIndex: std.mapWithIndex(func=function(i, x) i + x, arr=[3, 2, 1]),
106107
filterMap: std.filterMap(filter_func=function(x) x % 2 == 0, map_func=function(x) x * 2, arr=[1, 2, 3, 4]),
108+
flatMap: std.flatMap(func=function(x) [x*2, x*3], arr=[1,2,3]),
107109
filter: std.filter(func=function(x) x % 2 == 0, arr=[1, 2, 3, 4]),
108110
foldl: std.foldl(func=function(x, y) x + y, arr=[[1], [2], [3]], init=[0]),
109111
foldr: std.foldr(func=function(x, y) x + y, arr=[[1], [2], [3]], init=[4]),
112+
repeat: std.repeat(what="foo", count=3),
113+
slice: std.slice(indexable="foobar", index=1, end=2, step=1),
110114
range: std.range(from=1, to=5),
111115
join: std.join(sep=",", arr=["a", "b", "c"]),
112116
lines: std.lines(arr=["a", "b", "c"]),

0 commit comments

Comments
 (0)