From 31d71aaccda6d98135ecc02acae823ef6e78270c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Barzowski?= Date: Sun, 20 Dec 2020 21:17:29 +0100 Subject: [PATCH] Add missing linter metadata for stdlib. Fixes #483. --- linter/internal/types/stdlib.go | 10 ++++++++++ linter/testdata/stdlib_return_type_test.jsonnet | 1 + linter/testdata/stdlib_return_type_test.linter.golden | 0 testdata/stdlib_smoke_test.golden | 9 +++++++++ testdata/stdlib_smoke_test.jsonnet | 11 +++++++++++ 5 files changed, 31 insertions(+) create mode 100644 linter/testdata/stdlib_return_type_test.jsonnet create mode 100644 linter/testdata/stdlib_return_type_test.linter.golden diff --git a/linter/internal/types/stdlib.go b/linter/internal/types/stdlib.go index 9abf264..9b050db 100644 --- a/linter/internal/types/stdlib.go +++ b/linter/internal/types/stdlib.go @@ -31,11 +31,21 @@ func prepareStdlib(g *typeGraph) { "length": g.newSimpleFuncType(numberType, "x"), "objectHas": g.newSimpleFuncType(boolType, "o", "f"), "objectFields": g.newSimpleFuncType(arrayOfString, "o"), + "objectValues": g.newSimpleFuncType(anyArrayType, "o"), "objectHasAll": g.newSimpleFuncType(boolType, "o", "f"), "objectFieldsAll": g.newSimpleFuncType(arrayOfString, "o"), + "objectValuesAll": g.newSimpleFuncType(anyArrayType, "o"), "prune": g.newSimpleFuncType(anyObjectType, "a"), "mapWithKey": g.newSimpleFuncType(anyObjectType, "func", "obj"), + // isSomething + "isArray": g.newSimpleFuncType(boolType, "v"), + "isBoolean": g.newSimpleFuncType(boolType, "v"), + "isFunction": g.newSimpleFuncType(boolType, "v"), + "isNumber": g.newSimpleFuncType(boolType, "v"), + "isObject": g.newSimpleFuncType(boolType, "v"), + "isString": g.newSimpleFuncType(boolType, "v"), + // Mathematical utilities "abs": g.newSimpleFuncType(numberType, "n"), "sign": g.newSimpleFuncType(numberType, "n"), diff --git a/linter/testdata/stdlib_return_type_test.jsonnet b/linter/testdata/stdlib_return_type_test.jsonnet new file mode 100644 index 0000000..9358d04 --- /dev/null +++ b/linter/testdata/stdlib_return_type_test.jsonnet @@ -0,0 +1 @@ +!std.setMember([1, 2, 3], 1) \ No newline at end of file diff --git a/linter/testdata/stdlib_return_type_test.linter.golden b/linter/testdata/stdlib_return_type_test.linter.golden new file mode 100644 index 0000000..e69de29 diff --git a/testdata/stdlib_smoke_test.golden b/testdata/stdlib_smoke_test.golden index a488596..63df599 100644 --- a/testdata/stdlib_smoke_test.golden +++ b/testdata/stdlib_smoke_test.golden @@ -78,6 +78,12 @@ 4 ], "format": "test blah 42", + "isArray": true, + "isBoolean": true, + "isFunction": true, + "isNumber": true, + "isObject": true, + "isString": true, "join": "a,b,c", "length": 0, "lines": "a\nb\nc\n", @@ -115,8 +121,11 @@ "mergePatch": { }, "min": 2, "objectFields": [ ], + "objectFieldsAll": [ ], "objectHas": false, "objectHasAll": false, + "objectValues": [ ], + "objectValuesAll": [ ], "parseHex": 3735928559, "parseInt": 42, "parseJson": { diff --git a/testdata/stdlib_smoke_test.jsonnet b/testdata/stdlib_smoke_test.jsonnet index 50bea20..23f251d 100644 --- a/testdata/stdlib_smoke_test.jsonnet +++ b/testdata/stdlib_smoke_test.jsonnet @@ -15,10 +15,21 @@ length: std.length(x=[]), objectHas: std.objectHas(o={}, f="fieldname"), objectFields: std.objectFields(o={}), + objectValues: std.objectValues(o={}), objectHasAll: std.objectHasAll(o={}, f="fieldname"), + objectFieldsAll: std.objectFieldsAll(o={}), + objectValuesAll: std.objectValuesAll(o={}), prune: std.prune(a={x: null, y: [null, "42"]}), mapWithKey: std.mapWithKey(func=function(key, value) 42, obj={a: 17}), + // isSomething + isArray: std.isArray(v=[]), + isBoolean: std.isBoolean(v=true), + isFunction: std.isFunction(v=function() 42), + isNumber: std.isNumber(v=42), + isObject: std.isObject(v={}), + isString: std.isString(v=""), + // Mathematical utilities abs: std.abs(n=-42), sign: std.sign(n=17),