Skip to content

Commit

Permalink
Merge branch 'main' into cicd-test
Browse files Browse the repository at this point in the history
  • Loading branch information
cantfindname authored Mar 5, 2024
2 parents 0f914af + cec667e commit 5e707e3
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 148 deletions.
150 changes: 79 additions & 71 deletions dist/esm/standalone.mjs

Large diffs are not rendered by default.

206 changes: 203 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28159,6 +28159,203 @@ var require_module = __commonJS2({
};
}
});
var require_common_options = __commonJS2({
"src/common/common-options.js"(exports2, module2) {
"use strict";
var CATEGORY_COMMON = "Common";
module2.exports = {
bracketSpacing: {
since: "0.0.0",
category: CATEGORY_COMMON,
type: "boolean",
default: true,
description: "Print spaces between brackets.",
oppositeDescription: "Do not print spaces between brackets."
},
singleQuote: {
since: "0.0.0",
category: CATEGORY_COMMON,
type: "boolean",
default: false,
description: "Use single quotes instead of double quotes."
},
proseWrap: {
since: "1.8.2",
category: CATEGORY_COMMON,
type: "choice",
default: [{
since: "1.8.2",
value: true
}, {
since: "1.9.0",
value: "preserve"
}],
description: "How to wrap prose.",
choices: [{
since: "1.9.0",
value: "always",
description: "Wrap prose if it exceeds the print width."
}, {
since: "1.9.0",
value: "never",
description: "Do not wrap prose."
}, {
since: "1.9.0",
value: "preserve",
description: "Wrap prose as-is."
}]
},
bracketSameLine: {
since: "2.4.0",
category: CATEGORY_COMMON,
type: "boolean",
default: false,
description: "Put > of opening tags on the last line instead of on a new line."
},
singleAttributePerLine: {
since: "2.6.0",
category: CATEGORY_COMMON,
type: "boolean",
default: false,
description: "Enforce single attribute per line in HTML, Vue and JSX."
}
};
}
});
var require_options2 = __commonJS2({
"src/language-js/options.js"(exports2, module2) {
"use strict";
var commonOptions = require_common_options();
var CATEGORY_JAVASCRIPT = "JavaScript";
module2.exports = {
forceObjectBreak: {
since: "1.0.0",
category: CATEGORY_JAVASCRIPT,
type: "choice",
default: "preserve",
description: "Controls line breaks in object literals",
choices: [{
value: "preserve",
description: "Prettier's original behavior, which chooses between one-line and multi-line based on the presense of a new line after the opening '{'."
}, {
value: "forceSingleLine",
description: "Objects literals will always be formated to a single line."
}, {
value: "forceMultiLine",
description: "Object literals will always be formatted to multiple lines, where possible."
}]
},
allmanStyle: {
since: "1.0.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
default: false,
description: "Puts the '{' on a new line."
},
arrowParens: {
since: "1.9.0",
category: CATEGORY_JAVASCRIPT,
type: "choice",
default: [{
since: "1.9.0",
value: "avoid"
}, {
since: "2.0.0",
value: "always"
}],
description: "Include parentheses around a sole arrow function parameter.",
choices: [{
value: "always",
description: "Always include parens. Example: `(x) => x`"
}, {
value: "avoid",
description: "Omit parens when possible. Example: `x => x`"
}]
},
bracketSameLine: commonOptions.bracketSameLine,
bracketSpacing: commonOptions.bracketSpacing,
elseStatementNewLine: {
since: "0.0.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
description: "puts else statement on a new line instead of on the same line as if statement right bracket."
},
multiEmptyLine: {
since: "0.0.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
description: "allow empty multi-line at the start and the end of blocks."
},
jsxBracketSameLine: {
since: "0.17.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
description: "Put > on the last line instead of at a new line.",
deprecated: "2.4.0"
},
semi: {
since: "1.0.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
default: true,
description: "Print semicolons.",
oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
},
singleQuote: commonOptions.singleQuote,
jsxSingleQuote: {
since: "1.15.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
default: false,
description: "Use single quotes in JSX."
},
quoteProps: {
since: "1.17.0",
category: CATEGORY_JAVASCRIPT,
type: "choice",
default: "as-needed",
description: "Change when properties in objects are quoted.",
choices: [{
value: "as-needed",
description: "Only add quotes around object properties where required."
}, {
value: "consistent",
description: "If at least one property in an object requires quotes, quote all properties."
}, {
value: "preserve",
description: "Respect the input use of quotes in object properties."
}]
},
trailingComma: {
since: "0.0.0",
category: CATEGORY_JAVASCRIPT,
type: "choice",
default: [{
since: "0.0.0",
value: false
}, {
since: "0.19.0",
value: "none"
}, {
since: "2.0.0",
value: "es5"
}],
description: "Print trailing commas wherever possible when multi-line.",
choices: [{
value: "es5",
description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
}, {
value: "none",
description: "No trailing commas."
}, {
value: "all",
description: "Trailing commas wherever possible (including function arguments)."
}]
},
singleAttributePerLine: commonOptions.singleAttributePerLine
};
}
});
var require_object = __commonJS2({
"src/language-js/print/object.js"(exports2, module2) {
"use strict";
Expand Down Expand Up @@ -28205,6 +28402,9 @@ var require_object = __commonJS2({
var {
printHardlineAfterHeritage
} = require_class();
var {
forceObjectBreak
} = require_options2();
function printObject(path, options, print) {
const semi = options.semi ? ";" : "";
const node = path.getValue();
Expand All @@ -28224,7 +28424,7 @@ var require_object = __commonJS2({
const firstProperty = fields.map((field) => node[field][0]).sort((a, b) => locStart(a) - locStart(b))[0];
const parent = path.getParentNode(0);
const isFlowInterfaceLikeBody = isTypeAnnotation && parent && (parent.type === "InterfaceDeclaration" || parent.type === "DeclareInterface" || parent.type === "DeclareClass") && path.getName() === "body";
const shouldBreak = node.type === "TSInterfaceBody" || isFlowInterfaceLikeBody || node.type === "ObjectPattern" && parent.type !== "FunctionDeclaration" && parent.type !== "FunctionExpression" && parent.type !== "ArrowFunctionExpression" && parent.type !== "ObjectMethod" && parent.type !== "ClassMethod" && parent.type !== "ClassPrivateMethod" && parent.type !== "AssignmentPattern" && parent.type !== "CatchClause" && node.properties.some((property) => property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern")) || node.type !== "ObjectPattern" && firstProperty && hasNewlineInRange(options.originalText, locStart(node), locStart(firstProperty));
const shouldBreak = options.forceObjectBreak === "forceMultiLine" ? true : options.forceObjectBreak === "forceSingleLine" ? false : node.type === "TSInterfaceBody" || isFlowInterfaceLikeBody || node.type === "ObjectPattern" && parent.type !== "FunctionDeclaration" && parent.type !== "FunctionExpression" && parent.type !== "ArrowFunctionExpression" && parent.type !== "ObjectMethod" && parent.type !== "ClassMethod" && parent.type !== "ClassPrivateMethod" && parent.type !== "AssignmentPattern" && parent.type !== "CatchClause" && node.properties.some((property) => property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern")) || node.type !== "ObjectPattern" && firstProperty && hasNewlineInRange(options.originalText, locStart(node), locStart(firstProperty));
const separator = isFlowInterfaceLikeBody ? ";" : node.type === "TSInterfaceBody" || node.type === "TSTypeLiteral" ? ifBreak(semi, ";") : ",";
const leftBrace = node.type === "RecordExpression" ? "#{" : node.exact ? "{|" : "{";
const rightBrace = node.exact ? "|}" : "}";
Expand Down Expand Up @@ -28951,7 +29151,7 @@ var require_block = __commonJS2({
if (isNonEmptyArray(node.body) && options.multiEmptyLine) {
const blockStartingLine = node.loc.start.line;
const statementStartingLine = node.body[0].loc.start.line;
if (hasComment(node.body[0])) {
if (hasComment(node.body[0]) && node.body[0].comments[0].loc.start.line < statementStartingLine) {
const commentStartLine = node.body[0].comments[0].loc.start.line;
for (let i = blockStartingLine + 1; i < commentStartLine; i++) {
parts.push(hardline);
Expand All @@ -28977,7 +29177,7 @@ var require_block = __commonJS2({
const bodyCount = node.body.length;
const lastBody = node.body[bodyCount - 1];
const statementEndingLine = lastBody.loc.end.line;
if (hasComment(node.body[bodyCount - 1])) {
if (hasComment(node.body[bodyCount - 1]) && lastBody.comments[lastBody.comments.length - 1].loc.end.line > statementEndingLine) {
const commentCount = lastBody.comments.length;
const commentStartLine = lastBody.comments[commentCount - 1].loc.end.line;
for (let i = commentStartLine + 1; i < blockEndingLine; i++) {
Expand Down
146 changes: 77 additions & 69 deletions dist/standalone.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@
"build": "node ./scripts/build/build.mjs",
"build:website": "node ./scripts/build-website.mjs",
"vendors:bundle": "node ./scripts/vendors/bundle-vendors.mjs",
"build-local": "npm run build && cd .. && shx cp -R prettier/dist/ prettier-vscode/node_modules/prettier/ && cd prettier"
"build-local-win": "npm run build && cd .. && robocopy prettier/dist/ prettier-vscode/node_modules/prettier/ && cd prettier",
"build-local-mac": "npm run build && cd .. && cp -R prettier/dist/ prettier-vscode/node_modules/prettier/ && cd prettier",
"build-local": "npm run build && cd .. && robocopy prettier/dist/ prettier-vscode/node_modules/prettier/ && cd prettier"
},
"browserslist": [
">0.5%",
"not ie 11",
"not safari 5.1",
"not op_mini all"
]
}
}
24 changes: 24 additions & 0 deletions src/language-js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ const CATEGORY_JAVASCRIPT = "JavaScript";

// format based on https://github.com/prettier/prettier/blob/main/src/main/core-options.js
module.exports = {
forceObjectBreak: {
since: "1.0.0",
category: CATEGORY_JAVASCRIPT,
type: "choice",
default: "preserve",
description: "Controls line breaks in object literals",
choices: [
{
value: "preserve",
description:
"Prettier's original behavior, which chooses between one-line and multi-line based on the presense of a new line after the opening '{'.",
},
{
value: "forceSingleLine",
description:
"Objects literals will always be formated to a single line."
},
{
value: "forceMultiLine",
description:
"Object literals will always be formatted to multiple lines, where possible.",
},
],
},
allmanStyle: {
since: "1.0.0",
category: CATEGORY_JAVASCRIPT,
Expand Down
4 changes: 2 additions & 2 deletions src/language-js/print/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function printBlock(path, options, print) {
const blockStartingLine = node.loc.start.line;
const statementStartingLine = node.body[0].loc.start.line;

if (hasComment(node.body[0])){
if (hasComment(node.body[0]) && node.body[0].comments[0].loc.start.line < statementStartingLine){
const commentStartLine = node.body[0].comments[0].loc.start.line;

for (let i = blockStartingLine + 1; i < commentStartLine; i++) {
Expand Down Expand Up @@ -89,7 +89,7 @@ function printBlock(path, options, print) {
const lastBody = node.body[bodyCount - 1];
const statementEndingLine = lastBody.loc.end.line;

if (hasComment(node.body[bodyCount - 1])){
if (hasComment(node.body[bodyCount - 1]) && lastBody.comments[lastBody.comments.length - 1].loc.end.line > statementEndingLine){
const commentCount = lastBody.comments.length;
const commentStartLine = lastBody.comments[commentCount - 1].loc.end.line;
for (let i = commentStartLine + 1; i < blockEndingLine; i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/language-js/print/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const { printOptionalToken, printTypeAnnotation } = require("./misc.js");
const { shouldHugFunctionParameters } = require("./function-parameters.js");
const { shouldHugType } = require("./type-annotation.js");
const { printHardlineAfterHeritage } = require("./class.js");
const { forceObjectBreak } = require("../options.js");

/** @typedef {import("../../document").Doc} Doc */

Expand Down Expand Up @@ -58,7 +59,9 @@ function printObject(path, options, print) {
parent.type === "DeclareInterface" ||
parent.type === "DeclareClass") &&
path.getName() === "body";
const shouldBreak =
const shouldBreak = options.forceObjectBreak === 'forceMultiLine' ? true
: options.forceObjectBreak === 'forceSingleLine' ? false
: // If options.forceObjectBreak is 'preserve', we use the original behavior
node.type === "TSInterfaceBody" ||
isFlowInterfaceLikeBody ||
(node.type === "ObjectPattern" &&
Expand Down

0 comments on commit 5e707e3

Please sign in to comment.