56 Commits

Author SHA1 Message Date
Tsuyoshi Hombashi
8afe92f6bc
Merge d9173fc67a9cc433eb38541103fab2a22dc9350b into 10aef6a96ca825c97c87df137a837e39f5df174c 2025-06-23 11:43:32 +02:00
Rudo Thomas
1c79f577ba fix: Fix error messages when a comprehension iterates over a non-array.
Problems:
 - When iterating over an empty string in a list comprehension, the
   result is an empty string. This is a bug, it should be an error.
 - When iterating over a non-empty string in a list comprehension, the
   expected and unexpected types in the error message are swapped.
 - Error messages mention "std.flatMap" when object/list comprehensions
   would iterate over a value that is neither array nor string.

```
$ jsonnet --version
Jsonnet commandline interpreter (Go implementation) v0.21.0-rc2
$ jsonnet -e '[a for a in ""]'
""
$ jsonnet -e '[a for a in "b"]'
RUNTIME ERROR: Unexpected type array, expected string
	<cmdline>:1:1-17
	During evaluation
$ jsonnet -e '{[a]: 1 for a in 2}'
RUNTIME ERROR: std.flatMap second param must be array / string, got number
	<cmdline>:1:1-20
	<cmdline>:1:1-20
	During evaluation
$ jsonnet -e '[a for a in 1]'
RUNTIME ERROR: std.flatMap second param must be array / string, got number
	<cmdline>:1:1-15
	During evaluation
```

FWIW, the C++ implementation does not have any of these problems. It
gives:
```
RUNTIME ERROR: In comprehension, can only iterate over array.
```

In the Go implementation comprehensions are desugared to a call to
std.flatMap which does accept a string in the "arr" parameter.

The fix: Desugar comprehensions to a call to a new hidden builtin which
only accepts arrays.
2025-03-21 16:37:59 +00:00
John Bartholomew
9a89560b0d feat: support onEmpty optional parameter on std.minArray,std.maxArray 2025-03-11 00:33:41 +00:00
Thomas Neidhart
e0c6a9ed6f
Fix linter: using a local in an assertion. (#723) 2024-06-10 21:28:17 +01:00
guoguangwu
04f3751f08
chore: remove refs to deprecated io/ioutil (#716) 2024-06-10 21:27:07 +01:00
Brad Ison
3d9a2bfbd0
Add optional parameters to manifestYamlStream in linter (#732) 2024-06-10 21:26:36 +01:00
itchyny
fa70aa4711
feat: implement std.splitLimitR (#745) 2024-06-09 19:25:22 +01:00
zephyros-dev
fed90cd9cd
fix: add std.objectKeysValues to jsonnet-lint (#706) 2023-06-26 20:40:39 +01:00
Sean Gillespie
9639773cf0
Teach jsonnet-lint about optional parameters of std.manifestYamlDoc (#705)
manifestYamlDoc takes two optional parameters, `indent_array_in_object` and `quote_keys`. This commit teaches jsonnet-lint about them so that it doesn't raise errors when you use them.

There are other stdlib library functions with this problem; the true solution is probably to auto-generate this from the stdlib AST, but this at least gets the linter happy with this particular function.
2023-06-13 21:18:35 +01:00
Jayme Bird
5fb0b0b578
feat: add std reverse linter (#709)
* feat: add std.reverse to linter

* feat: add linter test case

* feat: fix linter golden test data
2023-06-13 20:15:23 +01:00
Rohit Jangid
2a7260d60c
feat: Add more math functions (#702)
Co-authored-by: Dave Cunningham <sparkprime@gmail.com>
2023-06-13 20:14:26 +01:00
Deep Goel
572c054137
feat: implement std.avg (#700)
* feat: implement std.avg
2023-06-13 17:42:05 +01:00
Rohit Jangid
aece6e9b90
feat: add more crypto functions (#699)
* feat: add more crypto functions
2023-06-13 17:18:02 +01:00
Tejesh Raut
fae841124f
Implement std.trim for string (#684)
* Implement std.trim for string
2023-06-13 13:05:28 +01:00
Jonathan Regehr
44538a33e1
Adds std.any and std.all to jsonnet-lint (#695)
Co-authored-by: Dave Cunningham <sparkprime@gmail.com>
2023-05-25 14:09:56 +01:00
Deep Goel
7edd5d373b
feat: implement std.maxArray (#696) 2023-05-25 13:45:24 +01:00
Rohit Jangid
4bb6e388b7
feat: implement std.equalsIgnoreCase (#692) 2023-05-25 13:32:39 +01:00
Rohit Jangid
25d3372c98
feat: implement std.remove and std.removeAt (#689)
* feat: implement std.remove and std.removeAt

* Update builtins.go

---------

Co-authored-by: Dave Cunningham <sparkprime@gmail.com>
2023-05-25 13:32:21 +01:00
Rohit Jangid
3c7c0cbac8
feat: implement objectRemoveKey (#686) 2023-05-25 12:55:30 +01:00
Deep Goel
9c0b362ba7
feat: implement std.minArray (#685)
* feat: implement std.minArray
2023-05-03 19:13:56 +01:00
Rohit Jangid
76e4fc2221
feat: implement std.contains (#691) 2023-05-03 19:06:07 +01:00
Rohit Jangid
18377e6f9f
Add std.round function in standard library. (#683)
Co-authored-by: Dave Cunningham <sparkprime@gmail.com>
2023-04-13 15:32:54 +01:00
Tejesh Raut
c63eb61eb3
Implement std.isEmpty for string (#678)
* Implement std.isEmpty for string
2023-04-13 15:24:47 +01:00
Saloni Juneja
91ebf4b09e Add std.xor for 2 booleans 2023-04-13 15:14:10 +01:00
Saloni Juneja
4c83cff898 Fixed test cases 2023-03-28 17:13:31 +01:00
Saloni Juneja
67c8bf4a53 Implement std.xor for booleans 2023-03-28 17:13:31 +01:00
Rohit Jangid
83b9f8341f feat: implement std.sum 2023-02-17 13:19:50 +00:00
Angus Lees
e33730a31e Fix jsonnet-lint bazel build
Update BUILD.bazel files so `bazel build //cmd/jsonnet-lint` works
again.
2022-10-26 13:02:57 +01:00
jaymebrd
635d04f264
feat: add support linter std get (#627)
* feat: add missing linter metadata for std.get

* feat: add tests cases for std.get linter with default and optional parameters
2022-10-19 06:19:49 +01:00
Jayme Bird
a5ddc1c5a4 feat: add support to the jsonnet linter for std.manifestJsonMinified 2022-08-18 22:23:43 +01:00
Jayme Bird
f0a060e259 feat: Add missing linter metadata for std.manifestTomlEx function 2022-03-18 02:05:38 +00:00
Angus Lees
f699b0ea42 Add numberArrayType linter type
Add `numberArrayType` specialised type for cases where we know we have
an array of numbers.  Use in some stdlib functions and `importbin`.
2022-03-03 22:49:02 +00:00
Angus Lees
856bd58872 Add 'importbin' statement
Add `importbin` statement.  Similar to `importstr` but the result is
an array of numbers (all integers 0-255).
2022-03-03 22:49:02 +00:00
Stanisław Barzowski
b00b56c335 Avoid depending on stdlib variable for desugaring.
The fix is easy – we just use "$std" which the user cannot access,
because it's not a valid identifier.
2021-08-09 19:25:33 +01:00
Tsuyoshi Hombashi
d9173fc67a Fix a test case 2021-07-11 15:35:25 +09:00
Tsuyoshi Hombashi
1d393de437 Fix jsonnet-lint erorr when linting importing files and imported files at the same time: #544 2021-07-11 15:18:18 +09:00
Tsuyoshi Hombashi
51daeb3229
Modify jsonnet-lint to accept multiple input files (#545)
Modify jsonnet-lint to accept multiple input files
2021-07-01 13:10:51 +02:00
Stanisław Barzowski
46d1fceb9c [Linter] Fix super index type and handle "object or string" indexing correctly. 2021-06-06 21:13:19 +02:00
Lucas Servén Marín
12bd29d164 linter: correct the return type for member
This commit corrects return type of the `member` function from the
standard library.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
2021-05-26 13:52:39 +02:00
Greg Roodt
e6a9581713
Adds std.parseYaml (#339)
Add support for std.parseYaml.

Co-authored-by: Stanisław Barzowski <stanislaw.barzowski@gmail.com>
2021-05-20 14:16:23 +02:00
Stanisław Barzowski
5899996502 Make go linter happy again. 2021-05-19 15:10:49 +02:00
Yiannis
ce76155e09
Fix strip definition
Co-authored-by: Tom Fenech <tomjwfenech@gmail.com>
2021-05-19 13:57:47 +02:00
Yiannis
bead95bfa6
Add linter support for std.strip and friends 2021-05-14 17:01:21 +02:00
Stanisław Barzowski
74b3a1b669 [Linter] Support std.member and std.repeat. 2021-03-25 18:35:13 +01:00
Stanisław Barzowski
7d81091149
Linter README – replace unicode asterisks
I think they were an artifact of copying from a LaTeX-generated PDF.
2021-02-21 20:59:24 +01:00
Stanisław Barzowski
31d71aaccd Add missing linter metadata for stdlib.
Fixes #483.
2021-01-01 19:17:40 +01:00
Stanisław Barzowski
6140a2f75a Better stacktrace for manifestation, +: and object assertions.
Fixes #282
2021-01-01 19:17:27 +01:00
Stanisław Barzowski
8fcbda5b50 Linter 2020-08-13 21:06:34 +02:00
Stanisław Barzowski
9ada769ce4 Make golangci-lint happy
Some of the suggestions are minor bug fixes (missing error handling).
2020-03-05 14:54:27 +01:00
Dave Cunningham
0e67cc3c68 Refactor to allow interleaving optional and positional params 2020-03-05 09:33:21 +01:00