-
-
Notifications
You must be signed in to change notification settings - Fork 139
Update php-parser, fix unary snapshot tests, and make multiple fixes for attribute formatting. #2502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
acharron-hl
wants to merge
3
commits into
prettier:main
Choose a base branch
from
acharron-hl:fix/unary-parsing-enum-attributes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update php-parser, fix unary snapshot tests, and make multiple fixes for attribute formatting. #2502
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||
| { | ||||||
| "name": "@prettier/plugin-php", | ||||||
| "version": "0.25.0", | ||||||
| "name": "@vanilla/prettier-plugin-php", | ||||||
| "version": "0.26.0", | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| "description": "Prettier PHP Plugin", | ||||||
| "repository": "prettier/prettier-php", | ||||||
| "author": "Lucas Azzola <@azz>", | ||||||
|
|
@@ -27,7 +27,7 @@ | |||||
| ], | ||||||
| "dependencies": { | ||||||
| "linguist-languages": "^8.0.0", | ||||||
| "php-parser": "^3.4.0" | ||||||
| "php-parser": "^3.7.0" | ||||||
| }, | ||||||
| "devDependencies": { | ||||||
| "@babel/preset-env": "^7.27.2", | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1199,31 +1199,16 @@ function printAttrs(path, options, print, { inline = false } = {}) { | |
| if (!path.node.attrGroups) { | ||
| return []; | ||
| } | ||
| path.each(() => { | ||
| const attrGroup = ["#["]; | ||
| path.each((attrGroupPath) => { | ||
| if (!inline && allAttrs.length > 0) { | ||
| allAttrs.push(hardline); | ||
| } | ||
| attrGroup.push(softline); | ||
| path.each(() => { | ||
| const attrNode = path.node; | ||
| if (attrGroup.length > 2) { | ||
| attrGroup.push(",", line); | ||
| } | ||
| const attrStmt = [attrNode.name]; | ||
| if (attrNode.args.length > 0) { | ||
| attrStmt.push(printArgumentsList(path, options, print, "args")); | ||
| } | ||
| attrGroup.push(group(attrStmt)); | ||
| }, "attrs"); | ||
| allAttrs.push( | ||
| group([ | ||
| indent(attrGroup), | ||
| ifBreak(shouldPrintComma(options, 8.0) ? "," : ""), | ||
| softline, | ||
| "]", | ||
| inline ? ifBreak(softline, " ") : "", | ||
| ]) | ||
| printAllComments( | ||
| attrGroupPath, | ||
| () => printAttrGroup(attrGroupPath, options, print, { inline }), | ||
| options | ||
| ) | ||
| ); | ||
| }, "attrGroups"); | ||
| if (allAttrs.length === 0) { | ||
|
|
@@ -1232,6 +1217,134 @@ function printAttrs(path, options, print, { inline = false } = {}) { | |
| return [...allAttrs, inline ? "" : hardline]; | ||
| } | ||
|
|
||
| function printAttrGroup(path, options, print, { inline = false } = {}) { | ||
| const attrGroup = ["#["]; | ||
| attrGroup.push(softline); | ||
| path.each(() => { | ||
| const attrNode = path.node; | ||
| if (attrGroup.length > 2) { | ||
| attrGroup.push(",", line); | ||
| } | ||
| const attrStmt = [attrNode.name]; | ||
| if (attrNode.args.length > 0) { | ||
| attrStmt.push(printArgumentsList(path, options, print, "args")); | ||
| } | ||
| attrGroup.push(group(attrStmt)); | ||
| }, "attrs"); | ||
| return group([ | ||
| indent(attrGroup), | ||
| ifBreak(shouldPrintComma(options, 8.0) ? "," : ""), | ||
| softline, | ||
| "]", | ||
| inline ? ifBreak(softline, " ") : "", | ||
| ]); | ||
| } | ||
|
|
||
| function printFunction(path, options, print) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you move this function? It's harder to compare the git diff with it |
||
| const { node } = path; | ||
| const declAttrs = printAttrs(path, options, print, { | ||
| inline: node.kind === "closure", | ||
| }); | ||
| const declaration = []; | ||
|
|
||
| if (node.isFinal) { | ||
| declaration.push("final "); | ||
| } | ||
|
|
||
| if (node.isAbstract) { | ||
| declaration.push("abstract "); | ||
| } | ||
|
|
||
| if (node.visibility) { | ||
| declaration.push(node.visibility, " "); | ||
| } | ||
|
|
||
| if (node.isStatic) { | ||
| declaration.push("static "); | ||
| } | ||
|
|
||
| declaration.push("function "); | ||
|
|
||
| if (node.byref) { | ||
| declaration.push("&"); | ||
| } | ||
|
|
||
| if (node.name) { | ||
| declaration.push(print("name")); | ||
| } | ||
|
|
||
| declaration.push(printArgumentsList(path, options, print)); | ||
|
|
||
| if (node.uses && node.uses.length > 0) { | ||
| declaration.push( | ||
| group([" use ", printArgumentsList(path, options, print, "uses")]) | ||
| ); | ||
| } | ||
|
|
||
| if (node.type) { | ||
| declaration.push([ | ||
| ": ", | ||
| hasDanglingComments(node.type) | ||
| ? [ | ||
| path.call(() => printDanglingComments(path, options, true), "type"), | ||
| " ", | ||
| ] | ||
| : "", | ||
| node.nullable ? "?" : "", | ||
| print("type"), | ||
| ]); | ||
| } | ||
|
|
||
| const printedDeclaration = declaration; | ||
|
|
||
| if (!node.body) { | ||
| return [...declAttrs, printedDeclaration]; | ||
| } | ||
|
|
||
| const printedBody = [ | ||
| "{", | ||
| indent([hasEmptyBody(path) ? "" : hardline, print("body")]), | ||
| hasEmptyBody(path) ? "" : hardline, | ||
| "}", | ||
| ]; | ||
|
|
||
| const isClosure = node.kind === "closure"; | ||
| if (isClosure) { | ||
| return [...declAttrs, printedDeclaration, " ", printedBody]; | ||
| } | ||
|
|
||
| if (node.arguments.length === 0) { | ||
| return [ | ||
| ...declAttrs, | ||
| printedDeclaration, | ||
| shouldPrintHardlineForOpenBrace(options) && !hasEmptyBody(path) | ||
| ? hardline | ||
| : " ", | ||
| printedBody, | ||
| ]; | ||
| } | ||
|
|
||
| const willBreakDeclaration = declaration.some(willBreak); | ||
|
|
||
| if (willBreakDeclaration) { | ||
| return [...declAttrs, printedDeclaration, " ", printedBody]; | ||
| } | ||
|
|
||
| return [ | ||
| ...declAttrs, | ||
| conditionalGroup([ | ||
| [ | ||
| printedDeclaration, | ||
| shouldPrintHardlineForOpenBrace(options) && !hasEmptyBody(path) | ||
| ? hardline | ||
| : " ", | ||
| printedBody, | ||
| ], | ||
| [printedDeclaration, " ", printedBody], | ||
| ]), | ||
| ]; | ||
| } | ||
|
|
||
| function printClass(path, options, print) { | ||
| const { node } = path; | ||
| const isAnonymousClass = node.kind === "class" && node.isAnonymous; | ||
|
|
@@ -1353,111 +1466,6 @@ function printClass(path, options, print) { | |
| return [printedDeclaration, printedBody]; | ||
| } | ||
|
|
||
| function printFunction(path, options, print) { | ||
| const { node } = path; | ||
| const declAttrs = printAttrs(path, options, print, { | ||
| inline: node.kind === "closure", | ||
| }); | ||
| const declaration = []; | ||
|
|
||
| if (node.isFinal) { | ||
| declaration.push("final "); | ||
| } | ||
|
|
||
| if (node.isAbstract) { | ||
| declaration.push("abstract "); | ||
| } | ||
|
|
||
| if (node.visibility) { | ||
| declaration.push(node.visibility, " "); | ||
| } | ||
|
|
||
| if (node.isStatic) { | ||
| declaration.push("static "); | ||
| } | ||
|
|
||
| declaration.push("function "); | ||
|
|
||
| if (node.byref) { | ||
| declaration.push("&"); | ||
| } | ||
|
|
||
| if (node.name) { | ||
| declaration.push(print("name")); | ||
| } | ||
|
|
||
| declaration.push(printArgumentsList(path, options, print)); | ||
|
|
||
| if (node.uses && node.uses.length > 0) { | ||
| declaration.push( | ||
| group([" use ", printArgumentsList(path, options, print, "uses")]) | ||
| ); | ||
| } | ||
|
|
||
| if (node.type) { | ||
| declaration.push([ | ||
| ": ", | ||
| hasDanglingComments(node.type) | ||
| ? [ | ||
| path.call(() => printDanglingComments(path, options, true), "type"), | ||
| " ", | ||
| ] | ||
| : "", | ||
| node.nullable ? "?" : "", | ||
| print("type"), | ||
| ]); | ||
| } | ||
|
|
||
| const printedDeclaration = declaration; | ||
|
|
||
| if (!node.body) { | ||
| return [...declAttrs, printedDeclaration]; | ||
| } | ||
|
|
||
| const printedBody = [ | ||
| "{", | ||
| indent([hasEmptyBody(path) ? "" : hardline, print("body")]), | ||
| hasEmptyBody(path) ? "" : hardline, | ||
| "}", | ||
| ]; | ||
|
|
||
| const isClosure = node.kind === "closure"; | ||
| if (isClosure) { | ||
| return [...declAttrs, printedDeclaration, " ", printedBody]; | ||
| } | ||
|
|
||
| if (node.arguments.length === 0) { | ||
| return [ | ||
| ...declAttrs, | ||
| printedDeclaration, | ||
| shouldPrintHardlineForOpenBrace(options) && !hasEmptyBody(path) | ||
| ? hardline | ||
| : " ", | ||
| printedBody, | ||
| ]; | ||
| } | ||
|
|
||
| const willBreakDeclaration = declaration.some(willBreak); | ||
|
|
||
| if (willBreakDeclaration) { | ||
| return [...declAttrs, printedDeclaration, " ", printedBody]; | ||
| } | ||
|
|
||
| return [ | ||
| ...declAttrs, | ||
| conditionalGroup([ | ||
| [ | ||
| printedDeclaration, | ||
| shouldPrintHardlineForOpenBrace(options) && !hasEmptyBody(path) | ||
| ? hardline | ||
| : " ", | ||
| printedBody, | ||
| ], | ||
| [printedDeclaration, " ", printedBody], | ||
| ]), | ||
| ]; | ||
| } | ||
|
|
||
| function printBodyControlStructure( | ||
| path, | ||
| options, | ||
|
|
@@ -2909,6 +2917,7 @@ function printNode(path, options, print) { | |
|
|
||
| case "enumcase": | ||
| return group([ | ||
| ...printAttrs(path, options, print), | ||
| "case ", | ||
| print("name"), | ||
| node.value | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?