Replace trim{Left,Right} with trim{Start,End} (#6994)

This commit is contained in:
fisker Cheung authored and Simon Lydell committed 2019-11-18 21:22:24 +01:00
1 parent 791996df7b
commit 596f55e324
7 files changed
+16 -15

No files matched your search

+1 -1
View File
@@ -653,7 +653,7 @@ function canAttachComment(node) {
function printComment(commentPath) {
const comment = commentPath.getValue();
if (comment.kind === "Comment") {
return "#" + comment.value.trimRight();
return "#" + comment.value.trimEnd();
}
throw new Error("Not a comment: " + JSON.stringify(comment));
+6 -6
View File
@@ -241,7 +241,7 @@ function genericPrint(path, options, printPath, args) {
const node = path.getValue();
if (hasFlowShorthandAnnotationComment(node)) {
parts.push(" /*");
parts.push(node.trailingComments[0].value.trimLeft());
parts.push(node.trailingComments[0].value.trimStart());
parts.push("*/");
node.trailingComments[0].printed = true;
}
@@ -3560,7 +3560,7 @@ function printPathNoParens(path, options, print, args) {
path.call(print, "node"),
!n.node.comments || n.node.comments.length === 0
? []
: concat([" //", n.node.comments[0].value.trimRight()])
: concat([" //", n.node.comments[0].value.trimEnd()])
)
);
case "NGChainedExpression":
@@ -6005,9 +6005,9 @@ function printComment(commentPath, options) {
if (
options.originalText.slice(options.locStart(comment)).startsWith("#!")
) {
return "#!" + comment.value.trimRight();
return "#!" + comment.value.trimEnd();
}
return "//" + comment.value.trimRight();
return "//" + comment.value.trimEnd();
default:
throw new Error("Not a comment: " + JSON.stringify(comment));
}
@@ -6031,8 +6031,8 @@ function printIndentableBlockComment(comment) {
hardline,
lines.map((line, index) =>
index === 0
? line.trimRight()
: " " + (index < lines.length - 1 ? line.trim() : line.trimLeft())
? line.trimEnd()
: " " + (index < lines.length - 1 ? line.trim() : line.trimStart())
)
),
"*/"
+2 -1
View File
@@ -19,7 +19,8 @@ function startWithPragma(text) {
module.exports = {
startWithPragma,
hasPragma: text => startWithPragma(parseFrontMatter(text).content.trimLeft()),
hasPragma: text =>
startWithPragma(parseFrontMatter(text).content.trimStart()),
insertPragma: text => {
const extracted = parseFrontMatter(text);
const pragma = `<!-- @${pragmas[0]} -->`;
+2 -2
View File
@@ -120,10 +120,10 @@ function splitTextIntoSentences(ast, options) {
if (parentNode.type === "paragraph") {
if (index === 0) {
value = value.trimLeft();
value = value.trimStart();
}
if (index === parentNode.children.length - 1) {
value = value.trimRight();
value = value.trimEnd();
}
}
+1 -1
View File
@@ -230,7 +230,7 @@ function genericPrint(path, options, print) {
const value =
parentNode.type === "root" &&
privateUtil.getLast(parentNode.children) === node
? node.value.trimRight()
? node.value.trimEnd()
: node.value;
const isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
return concat(
+2 -2
View File
@@ -198,8 +198,8 @@ function getFlowScalarLineContents(nodeType, content, options) {
: index !== 0 && index !== lineContents.length - 1
? lineContent.trim()
: index === 0
? lineContent.trimRight()
: lineContent.trimLeft()
? lineContent.trimEnd()
: lineContent.trimStart()
);
if (options.proseWrap === "preserve") {
+2 -2
View File
@@ -60,7 +60,7 @@ function attachComments(text, ast, opts) {
comments.attach(astComments, ast, text, opts);
}
ast.tokens = [];
opts.originalText = opts.parser === "yaml" ? text : text.trimRight();
opts.originalText = opts.parser === "yaml" ? text : text.trimEnd();
return astComments;
}
@@ -221,7 +221,7 @@ function formatRange(text, opts) {
// Since the range contracts to avoid trailing whitespace,
// we need to remove the newline that was inserted by the `format` call.
const rangeTrimmed = rangeResult.formatted.trimRight();
const rangeTrimmed = rangeResult.formatted.trimEnd();
const rangeLeft = text.slice(0, rangeStart);
const rangeRight = text.slice(rangeEnd);