May not be a bug depending on what versions of PHP you intend to support. I just learned about this and ran it on my code base. We use PHP 7.1 and I got errors related to PHP's new array destructuring (see a couple sections down here: http://php.net/manual/en/migration71.new-features.php).
Input:
<?php
[ $a, $b ] = [ 1, 2 ];
?>
Output:
[error] test.php: SyntaxError: Parse Error : syntax error, unexpected '=', expecting ';' on line 2
[error] at parser.raiseError (/var/www/prettier/plugin-php/node_modules/php-parser/src/parser.js:261:15)
[error] at parser.error (/var/www/prettier/plugin-php/node_modules/php-parser/src/parser.js:301:15)
[error] at parser.expectEndOfStatement (/var/www/prettier/plugin-php/node_modules/php-parser/src/parser.js:330:10)
[error] at parser.read_statement (/var/www/prettier/plugin-php/node_modules/php-parser/src/parser/statement.js:348:14)
[error] at parser.read_top_statement (/var/www/prettier/plugin-php/node_modules/php-parser/src/parser/statement.js:74:21)
[error] at parser.read_start (/var/www/prettier/plugin-php/node_modules/php-parser/src/parser/main.js:17:19)
[error] at parser.parse (/var/www/prettier/plugin-php/node_modules/php-parser/src/parser.js:243:21)
[error] at engine.parseCode (/var/www/prettier/plugin-php/node_modules/php-parser/src/index.js:168:22)
[error] at Object.parse (/var/www/prettier/plugin-php/src/parser.js:16:17)
[error] at Object.parse (/var/www/prettier/plugin-php/node_modules/prettier/src/main/parser.js:75:19)
[error] at formatWithCursor (/var/www/prettier/plugin-php/node_modules/prettier/index.js:101:25)
[error] at Object.formatWithCursor (/var/www/prettier/plugin-php/node_modules/prettier/index.js:402:12)
[error] at format (/var/www/prettier/plugin-php/node_modules/prettier/src/cli/util.js:157:19)
[error] at eachFilename (/var/www/prettier/plugin-php/node_modules/prettier/src/cli/util.js:380:16)
[error] at filePaths.forEach.filePath (/var/www/prettier/plugin-php/node_modules/prettier/src/cli/util.js:322:7)
[error] at Array.forEach (<anonymous>)
error An unexpected error occurred: "Command failed.
Exit code: 2
Thanks! Let me know if there is anything I can do to help!
@cmancone Thanks for issue, already reported in parser https://github.com/glayzzle/php-parser/issues/121
Thanks, sorry I missed that!
@cmancone let's left open for other users, before we fixed it
I understand now: you opened and issue in your dependency. I'm excited about seeing this issue get fixed. I've got a medium-ish code base (100-150 kLoC) that I really want to run prettier on, and good test coverage to make sure that it doesn't break anything. This appears to be the only issue stopping me from running prettier on my code base.
@cmancone very bad, we would need new issues for fast stable release :+1:
Parser was updated to solve for this - I believe we can check if this is working on our end now, if not probably just needs an update to our printer
@mgrip exactly! Didn't find the time yet, feel free to go for it :wink:
@mgrip, @czosel, the latest version of prettier is now properly processing this for me.