Skip to content

Commit 4ab5a9d

Browse files
authored
feat: convert list to short syntax automatically (#1351)
1 parent c922b29 commit 4ab5a9d

9 files changed

Lines changed: 452 additions & 51 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"linguist-languages": "^7.5.1",
1515
"mem": "^6.0.1",
16-
"php-parser": "glayzzle/php-parser#5a0e2e1bf12517bd1c544c0f4e68482d0362a7b5"
16+
"php-parser": "3.0.2"
1717
},
1818
"devDependencies": {
1919
"@babel/preset-env": "^7.7.5",

src/clean.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function clean(node, newObj) {
3434
delete newObj.isDoubleQuote;
3535
}
3636

37-
if (node.kind === "array") {
37+
if (["array", "list"].includes(node.kind)) {
3838
// TODO if options are available in this method, assign instead of delete
3939
delete newObj.shortForm;
4040
}

src/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
since: "0.13.0",
88
category: CATEGORY_PHP,
99
type: "choice",
10-
default: "5.4",
10+
default: "7.0",
1111
description: "Minimum target PHP version.",
1212
choices: [
1313
{ value: "5.0" },

src/printer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,8 @@ function printNode(path, options, print) {
24592459
case "array": {
24602460
const useShortForm =
24612461
(node.kind === "array" && isMinVersion(options.phpVersion, "5.4")) ||
2462-
(node.kind === "list" && node.shortForm);
2462+
(node.kind === "list" &&
2463+
(node.shortForm || isMinVersion(options.phpVersion, "7.1")));
24632464
const open = useShortForm ? "[" : concat([node.kind, "("]);
24642465
const close = useShortForm ? "]" : ")";
24652466

tests/array/__snapshots__/jsfmt.spec.js.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,21 +1555,21 @@ $arr = array(
15551555
->allOrderBy('nome')
15561556
->pluck('nome', 'id'),
15571557
);
1558-
[array($id1, $name1)] = $data;
1559-
[array($id1), array($id2), array($id)] = $data;
1558+
[[$id1, $name1]] = $data;
1559+
[[$id1], [$id2], [$id]] = $data;
15601560
[
1561-
array(
1561+
[
15621562
$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongValue,
15631563
$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongOtherValue,
1564-
),
1564+
],
15651565
] = $data;
15661566
["id" => $id1, "name" => $name1] = $data;
1567-
[array("id" => $id1, "name" => $name1)] = $data;
1567+
[["id" => $id1, "name" => $name1]] = $data;
15681568
[
1569-
array(
1569+
[
15701570
"veryVeryVeryVeryLongKey" => $veryVeryVeryVeryLongValue,
15711571
"veryVeryVeryVeryLongOtherKey" => $veryVeryVeryVeryLongValue,
1572-
),
1572+
],
15731573
] = $data;
15741574
$arr = array(
15751575
'niveisFederativos' => function () {

0 commit comments

Comments
 (0)