From 5fb0b0b578d76078b6cea8f2c8114f58259c2333 Mon Sep 17 00:00:00 2001 From: Jayme Bird Date: Tue, 13 Jun 2023 20:15:23 +0100 Subject: [PATCH] feat: add std reverse linter (#709) * feat: add std.reverse to linter * feat: add linter test case * feat: fix linter golden test data --- linter/internal/types/stdlib.go | 1 + testdata/builtinReverse.linter.golden | 10 ---------- testdata/builtinReverse_empty.linter.golden | 10 ---------- testdata/builtinReverse_many.linter.golden | 10 ---------- testdata/builtinReverse_not_array.linter.golden | 10 ---------- testdata/builtinReverse_single.linter.golden | 10 ---------- testdata/stdlib_smoke_test.golden | 4 ++++ testdata/stdlib_smoke_test.jsonnet | 1 + 8 files changed, 6 insertions(+), 50 deletions(-) diff --git a/linter/internal/types/stdlib.go b/linter/internal/types/stdlib.go index 062d00858..6548fb21a 100644 --- a/linter/internal/types/stdlib.go +++ b/linter/internal/types/stdlib.go @@ -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"), diff --git a/testdata/builtinReverse.linter.golden b/testdata/builtinReverse.linter.golden index a272b65dd..e69de29bb 100644 --- a/testdata/builtinReverse.linter.golden +++ b/testdata/builtinReverse.linter.golden @@ -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]) - - diff --git a/testdata/builtinReverse_empty.linter.golden b/testdata/builtinReverse_empty.linter.golden index ccd6f6b05..e69de29bb 100644 --- a/testdata/builtinReverse_empty.linter.golden +++ b/testdata/builtinReverse_empty.linter.golden @@ -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([]) - - diff --git a/testdata/builtinReverse_many.linter.golden b/testdata/builtinReverse_many.linter.golden index c6528d52a..e69de29bb 100644 --- a/testdata/builtinReverse_many.linter.golden +++ b/testdata/builtinReverse_many.linter.golden @@ -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"]) - - diff --git a/testdata/builtinReverse_not_array.linter.golden b/testdata/builtinReverse_not_array.linter.golden index d12c1aa18..e69de29bb 100644 --- a/testdata/builtinReverse_not_array.linter.golden +++ b/testdata/builtinReverse_not_array.linter.golden @@ -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) - - diff --git a/testdata/builtinReverse_single.linter.golden b/testdata/builtinReverse_single.linter.golden index 2bd8dd7b0..e69de29bb 100644 --- a/testdata/builtinReverse_single.linter.golden +++ b/testdata/builtinReverse_single.linter.golden @@ -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"]) - - diff --git a/testdata/stdlib_smoke_test.golden b/testdata/stdlib_smoke_test.golden index 972ba97e7..7bc0b6616 100644 --- a/testdata/stdlib_smoke_test.golden +++ b/testdata/stdlib_smoke_test.golden @@ -162,6 +162,10 @@ 5 ], "repeat": "foofoofoo", + "reverse": [ + "a", + "b" + ], "rstripChars": "aaabbbb", "set": [ [ diff --git a/testdata/stdlib_smoke_test.jsonnet b/testdata/stdlib_smoke_test.jsonnet index de98c35f6..8272a5fd4 100644 --- a/testdata/stdlib_smoke_test.jsonnet +++ b/testdata/stdlib_smoke_test.jsonnet @@ -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),