From 44538a33e1855afc5b31deddcb487430a914636d Mon Sep 17 00:00:00 2001 From: Jonathan Regehr <10343188+jregehr@users.noreply.github.com> Date: Thu, 25 May 2023 08:09:56 -0500 Subject: [PATCH] Adds std.any and std.all to jsonnet-lint (#695) Co-authored-by: Dave Cunningham --- linter/internal/types/graph.go | 7 +++++++ linter/internal/types/placeholder.go | 1 + linter/internal/types/stdlib.go | 3 +++ 3 files changed, 11 insertions(+) diff --git a/linter/internal/types/graph.go b/linter/internal/types/graph.go index 90a2c28..b48dc48 100644 --- a/linter/internal/types/graph.go +++ b/linter/internal/types/graph.go @@ -139,6 +139,13 @@ func newTypeGraph(importFunc ImportFunc) *typeGraph { }, }) + g.newPlaceholder() + g._placeholders[boolArrayType] = concreteTP(TypeDesc{ + ArrayDesc: &arrayDesc{ + furtherContain: []placeholderID{boolType}, + }, + }) + g.newPlaceholder() g._placeholders[anyObjectType] = concreteTP(TypeDesc{ ObjectDesc: anyObjectDesc, diff --git a/linter/internal/types/placeholder.go b/linter/internal/types/placeholder.go index f5fa906..c4c2f2f 100644 --- a/linter/internal/types/placeholder.go +++ b/linter/internal/types/placeholder.go @@ -14,6 +14,7 @@ const ( nullType anyArrayType numberArrayType + boolArrayType anyObjectType anyFunctionType stdlibType diff --git a/linter/internal/types/stdlib.go b/linter/internal/types/stdlib.go index 0e3c5e8..01c4ebb 100644 --- a/linter/internal/types/stdlib.go +++ b/linter/internal/types/stdlib.go @@ -144,6 +144,9 @@ func prepareStdlib(g *typeGraph) { "minArray": g.newFuncType(anyArrayType, []ast.Parameter{required("arr"), optional("keyF")}), "maxArray": g.newFuncType(anyArrayType, []ast.Parameter{required("arr"), optional("keyF")}), "contains": g.newSimpleFuncType(boolType, "arr", "elem"), + // TODO these need test cases written by someone who understands how to make them + "all": g.newSimpleFuncType(boolArrayType, "arr"), + "any": g.newSimpleFuncType(boolArrayType, "arr"), "remove": g.newSimpleFuncType(anyArrayType, "arr", "elem"), "removeAt": g.newSimpleFuncType(anyArrayType, "arr", "i"),