Skip to content

Commit

Permalink
feat(phpstan): support nested array types
Browse files Browse the repository at this point in the history
This only adds support for "list" array types, though. We can add support for
more variations as requests come in.

Ref: pulsar-edit/pulsar#876 (comment)
  • Loading branch information
claytonrcarter committed Jan 20, 2024
1 parent 915a527 commit 24feb93
Show file tree
Hide file tree
Showing 5 changed files with 11,218 additions and 11,090 deletions.
18 changes: 18 additions & 0 deletions corpus/psalm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ Psalm style array types
value: (named_type (name))))
(variable_name (name))))

=====================
PHPStan style nested array types
=====================
/** @var array<array<array<int>>> $foo */
---
(document
(tag
(tag_name)
(type_list
(array_type
array: (primitive_type)
value: (array_type
array: (primitive_type)
value: (array_type
array: (primitive_type)
value: (primitive_type)))))
(variable_name (name))))

=====================
Psalm scalar class-string type
=====================
Expand Down
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ module.exports = grammar({
_psalm_list_array_types: $ => seq(
field('array', choice(alias("list", $.primitive_type), $._regular_types)),
"<",
field('value', $._regular_types),
field('value', $._types),
">"
),

Expand Down
2 changes: 1 addition & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_regular_types"
"name": "_types"
}
},
{
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"multiple": false,
"required": false,
"types": [
{
"type": "array_type",
"named": true
},
{
"type": "named_type",
"named": true
Expand Down
Loading

0 comments on commit 24feb93

Please sign in to comment.