Skip to content

Commit 98e329e

Browse files
Lukasczosel
authored andcommitted
Rename trailingComma to trailingCommaPHP (#1059)
* Rename trailingComma option to trailingCommaPHP #964 * Update README with the new trailingCommaPHP * Add support for comon trailingComma: all option
1 parent 2fc3912 commit 98e329e

5 files changed

Lines changed: 622 additions & 41 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Prettier for PHP supports the following options:
166166
| `tabWidth` | `4` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)) |
167167
| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) |
168168
| `singleQuote` | `false` | If set to `"true"`, strings that use double quotes but do not rely on the features they add, will be reformatted. Example: `"foo" -> 'foo'`, `"foo $bar" -> "foo $bar"`. |
169-
| `trailingComma` | `"none"` | If set to `"all"`, trailing commas will be added wherever possible. <br> If set to `"php7.2"`, trailing commas will be added to multiline arrays, lists and uses. <br> If set to `"php5"`, trailing commas will be added to multiline arrays and lists. <br> if set to `"none"`, no trailing commas. |
169+
| `trailingCommaPHP` | `"none"` | If set to `"all"`, trailing commas will be added wherever possible. <br> If set to `"php7.2"`, trailing commas will be added to multiline arrays, lists and uses. <br> If set to `"php5"`, trailing commas will be added to multiline arrays and lists. <br> if set to `"none"`, no trailing commas. |
170170
| `braceStyle` | `"psr-2"` | If set to `"psr-2"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line. <br> If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. |
171171
| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) |
172172
| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) |

src/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const CATEGORY_PHP = "PHP";
44

55
module.exports = {
6-
trailingComma: {
6+
trailingCommaPHP: {
77
since: "0.0.0",
88
category: CATEGORY_PHP,
99
type: "choice",

src/printer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const {
6262
function shouldPrintComma(options, level) {
6363
level = level || "none";
6464

65-
switch (options.trailingComma) {
65+
switch (options.trailingCommaPHP) {
6666
case "all":
6767
if (level === "all") {
6868
return true;
@@ -79,7 +79,12 @@ function shouldPrintComma(options, level) {
7979
}
8080
// fallthrough
8181
case "none":
82+
return false;
83+
// fallthrough
8284
default:
85+
if (options.trailingComma === "all") {
86+
return true;
87+
}
8388
return false;
8489
}
8590
}

0 commit comments

Comments
 (0)