@prettier/plugin-php 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -6
- package/package.json +16 -6
- package/src/clean.js +5 -7
- package/src/comments.js +31 -30
- package/src/index.js +36 -30
- package/src/linguist-languages.cjs +4 -0
- package/src/needs-parens.js +17 -25
- package/src/options.js +1 -3
- package/src/parser.js +2 -3
- package/src/pragma.js +3 -8
- package/src/printer.js +140 -189
- package/src/util.js +13 -26
- package/standalone.js +2 -2
- package/src/module.js +0 -2
package/src/util.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { util as prettierUtil, version as prettierVersion } from "prettier";
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
hasNewline,
|
|
@@ -8,9 +8,7 @@ const {
|
|
|
8
8
|
isPreviousLineEmpty: _isPreviousLineEmpty,
|
|
9
9
|
getNextNonSpaceNonCommentCharacterIndex:
|
|
10
10
|
_getNextNonSpaceNonCommentCharacterIndex,
|
|
11
|
-
} =
|
|
12
|
-
|
|
13
|
-
const prettierVersion = require("prettier").version;
|
|
11
|
+
} = prettierUtil;
|
|
14
12
|
|
|
15
13
|
function lookupIfPrettier2(options, prop) {
|
|
16
14
|
return parseInt(prettierVersion[0]) > 1 ? options[prop] : options;
|
|
@@ -190,7 +188,7 @@ function getNodeListProperty(node) {
|
|
|
190
188
|
}
|
|
191
189
|
|
|
192
190
|
function getParentNodeListProperty(path) {
|
|
193
|
-
const parent = path
|
|
191
|
+
const { parent } = path;
|
|
194
192
|
if (!parent) {
|
|
195
193
|
return null;
|
|
196
194
|
}
|
|
@@ -216,12 +214,12 @@ function isLastStatement(path) {
|
|
|
216
214
|
if (!body) {
|
|
217
215
|
return true;
|
|
218
216
|
}
|
|
219
|
-
const node = path
|
|
217
|
+
const { node } = path;
|
|
220
218
|
return body[body.length - 1] === node;
|
|
221
219
|
}
|
|
222
220
|
|
|
223
221
|
function isFirstChildrenInlineNode(path) {
|
|
224
|
-
const node = path
|
|
222
|
+
const { node } = path;
|
|
225
223
|
|
|
226
224
|
if (node.kind === "program") {
|
|
227
225
|
const children = getNodeListProperty(node);
|
|
@@ -377,8 +375,7 @@ function docShouldHaveTrailingNewline(path, recurse = 0) {
|
|
|
377
375
|
}
|
|
378
376
|
|
|
379
377
|
function lineShouldEndWithSemicolon(path) {
|
|
380
|
-
const node = path
|
|
381
|
-
const parentNode = path.getParentNode();
|
|
378
|
+
const { node, parent: parentNode } = path;
|
|
382
379
|
if (!parentNode) {
|
|
383
380
|
return false;
|
|
384
381
|
}
|
|
@@ -407,7 +404,7 @@ function lineShouldEndWithSemicolon(path) {
|
|
|
407
404
|
return true;
|
|
408
405
|
}
|
|
409
406
|
if (node.kind === "method") {
|
|
410
|
-
const parent = path
|
|
407
|
+
const { parent } = path;
|
|
411
408
|
if (parent && parent.kind === "interface") {
|
|
412
409
|
return true;
|
|
413
410
|
}
|
|
@@ -435,7 +432,7 @@ function lineShouldEndWithSemicolon(path) {
|
|
|
435
432
|
}
|
|
436
433
|
|
|
437
434
|
function fileShouldEndWithHardline(path) {
|
|
438
|
-
const node = path
|
|
435
|
+
const { node } = path;
|
|
439
436
|
const isProgramNode = node.kind === "program";
|
|
440
437
|
const lastNode = node.children && getLast(node.children);
|
|
441
438
|
|
|
@@ -477,14 +474,6 @@ function hasDanglingComments(node) {
|
|
|
477
474
|
);
|
|
478
475
|
}
|
|
479
476
|
|
|
480
|
-
function hasLeadingComment(node) {
|
|
481
|
-
return node.comments && node.comments.some((comment) => comment.leading);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
function hasTrailingComment(node) {
|
|
485
|
-
return node.comments && node.comments.some((comment) => comment.trailing);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
477
|
function isLookupNode(node) {
|
|
489
478
|
return (
|
|
490
479
|
node.kind === "propertylookup" ||
|
|
@@ -495,7 +484,7 @@ function isLookupNode(node) {
|
|
|
495
484
|
}
|
|
496
485
|
|
|
497
486
|
function shouldPrintHardLineAfterStartInControlStructure(path) {
|
|
498
|
-
const node = path
|
|
487
|
+
const { node } = path;
|
|
499
488
|
|
|
500
489
|
if (["try", "catch"].includes(node.kind)) {
|
|
501
490
|
return false;
|
|
@@ -505,7 +494,7 @@ function shouldPrintHardLineAfterStartInControlStructure(path) {
|
|
|
505
494
|
}
|
|
506
495
|
|
|
507
496
|
function shouldPrintHardLineBeforeEndInControlStructure(path) {
|
|
508
|
-
const node = path
|
|
497
|
+
const { node } = path;
|
|
509
498
|
|
|
510
499
|
if (["try", "catch"].includes(node.kind)) {
|
|
511
500
|
return true;
|
|
@@ -544,7 +533,7 @@ function getAlignment(text) {
|
|
|
544
533
|
}
|
|
545
534
|
|
|
546
535
|
function getNextNode(path, node) {
|
|
547
|
-
const parent = path
|
|
536
|
+
const { parent } = path;
|
|
548
537
|
const children = getNodeListProperty(parent);
|
|
549
538
|
|
|
550
539
|
if (!children) {
|
|
@@ -606,7 +595,7 @@ function useDoubleQuote(node, options) {
|
|
|
606
595
|
}
|
|
607
596
|
|
|
608
597
|
function hasEmptyBody(path, name = "body") {
|
|
609
|
-
const node = path
|
|
598
|
+
const { node } = path;
|
|
610
599
|
|
|
611
600
|
return (
|
|
612
601
|
node[name] &&
|
|
@@ -692,7 +681,7 @@ function normalizeMagicMethodName(name) {
|
|
|
692
681
|
return name;
|
|
693
682
|
}
|
|
694
683
|
|
|
695
|
-
|
|
684
|
+
export {
|
|
696
685
|
printNumber,
|
|
697
686
|
getPrecedence,
|
|
698
687
|
isBitwiseOperator,
|
|
@@ -708,8 +697,6 @@ module.exports = {
|
|
|
708
697
|
fileShouldEndWithHardline,
|
|
709
698
|
maybeStripLeadingSlashFromUse,
|
|
710
699
|
hasDanglingComments,
|
|
711
|
-
hasLeadingComment,
|
|
712
|
-
hasTrailingComment,
|
|
713
700
|
docShouldHaveTrailingNewline,
|
|
714
701
|
isLookupNode,
|
|
715
702
|
isFirstChildrenInlineNode,
|