Skip to content

Commit

Permalink
feat: add std reverse linter (#709)
Browse files Browse the repository at this point in the history
* feat: add std.reverse to linter

* feat: add linter test case

* feat: fix linter golden test data
  • Loading branch information
jaymebrd authored Jun 13, 2023
1 parent 2a7260d commit 5fb0b0b
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 50 deletions.
1 change: 1 addition & 0 deletions linter/internal/types/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func prepareStdlib(g *typeGraph) {
"join": g.newSimpleFuncType(stringOrArray, "sep", "arr"),
"lines": g.newSimpleFuncType(arrayOfString, "arr"),
"flattenArrays": g.newSimpleFuncType(anyArrayType, "arrs"),
"reverse": g.newSimpleFuncType(anyArrayType, "arrs"),
"sort": g.newFuncType(anyArrayType, []ast.Parameter{required("arr"), optional("keyF")}),
"uniq": g.newFuncType(anyArrayType, []ast.Parameter{required("arr"), optional("keyF")}),
"sum": g.newSimpleFuncType(numberType, "arr"),
Expand Down
10 changes: 0 additions & 10 deletions testdata/builtinReverse.linter.golden
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
../testdata/builtinReverse:1:1-12 Indexed object has no field "reverse"

std.reverse([1, 2])


../testdata/builtinReverse:1:1-20 Called value must be a function, but it is assumed to be void

std.reverse([1, 2])


10 changes: 0 additions & 10 deletions testdata/builtinReverse_empty.linter.golden
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
../testdata/builtinReverse_empty:1:1-12 Indexed object has no field "reverse"

std.reverse([])


../testdata/builtinReverse_empty:1:1-16 Called value must be a function, but it is assumed to be void

std.reverse([])


10 changes: 0 additions & 10 deletions testdata/builtinReverse_many.linter.golden
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
../testdata/builtinReverse_many:1:1-12 Indexed object has no field "reverse"

std.reverse(["hello", "my", "name", "is", "tester"])


../testdata/builtinReverse_many:1:1-53 Called value must be a function, but it is assumed to be void

std.reverse(["hello", "my", "name", "is", "tester"])


10 changes: 0 additions & 10 deletions testdata/builtinReverse_not_array.linter.golden
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
../testdata/builtinReverse_not_array:1:1-12 Indexed object has no field "reverse"

std.reverse(false)


../testdata/builtinReverse_not_array:1:1-19 Called value must be a function, but it is assumed to be void

std.reverse(false)


10 changes: 0 additions & 10 deletions testdata/builtinReverse_single.linter.golden
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
../testdata/builtinReverse_single:1:1-12 Indexed object has no field "reverse"

std.reverse(["hello"])


../testdata/builtinReverse_single:1:1-23 Called value must be a function, but it is assumed to be void

std.reverse(["hello"])


4 changes: 4 additions & 0 deletions testdata/stdlib_smoke_test.golden
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
5
],
"repeat": "foofoofoo",
"reverse": [
"a",
"b"
],
"rstripChars": "aaabbbb",
"set": [
[
Expand Down
1 change: 1 addition & 0 deletions testdata/stdlib_smoke_test.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
join: std.join(sep=",", arr=["a", "b", "c"]),
lines: std.lines(arr=["a", "b", "c"]),
flattenArrays: std.flattenArrays([[1], [2, 3], [4, 5, [6, 7]]]),
reverse: std.reverse(["b", "a"]),
sort: [
std.sort([2, 3, 1]),
std.sort(arr=[2, 3, 1], keyF=function(x) -x),
Expand Down

0 comments on commit 5fb0b0b

Please sign in to comment.