prettier / plugin-php

Prettier PHP Plugin
https://loilo.github.io/prettier-php-playground/
MIT License
1.74k stars 126 forks source link

[bug] singleQuote option from API call does not work on latest release #2302

Closed shufo closed 7 months ago

shufo commented 8 months ago

Environment

 $  yarn list | grep prettier
├─ @prettier/plugin-php@0.22.1
...
├─ prettier@3.1.1

Current behaviour

In recent release (at least 0.22.1), prettier.format API call like below does not respect singleQuote option. Other options are respected as like before.

 $  cat test.js
import prettier from "prettier/standalone";
import prettierPluginPhp from "@prettier/plugin-php/standalone";

console.log((await prettier.format(`<?php echo link_to_route("frontend.users.user.show", $users["name"], $users['_id']); ?>`, {
  plugins: [prettierPluginPhp],
  singleQuote: true,
  parser: "php",
})));

It will outputs like below. You can see double quote is still double quote.

 $  node test.js
<?php echo link_to_route(
    "frontend.users.user.show",
    $users["name"],
    $users['_id']
); ?>

Expected behaviour

Respect singleQuote option as like before.

0.19.7 is OK. I think this regression is introduced since v0.20.0

 $  cat package.json
{
  "dependencies": {
    "@prettier/plugin-php": "0.19.7",
    "prettier": "^2.0.0"
  }
}

 $  cat test.mjs
import prettier from "prettier/standalone.js";
import prettierPluginPhp from "@prettier/plugin-php/standalone.js";

console.log((prettier.format(`<?php echo link_to_route("frontend.users.user.show", $users["name"], $users['_id']); ?>`, {
  plugins: [prettierPluginPhp],
  singleQuote: true,
  parser: "php",
})));
 $  node test.mjs
<?php echo link_to_route(
    'frontend.users.user.show',
    $users['name'],
    $users['_id']
); ?>

I tried some fix and found adding default option could solve the issue. I'll create the PR.