Replace concat in src/document/ with array (#10185)

This commit is contained in:
fisker Cheung authored and GitHub committed 2021-02-08 09:48:25 +08:00
1 parent bf3cabd2bb
commit ba3930d63e
5 files changed
+8 -12

No files matched your search

-3
View File
@@ -120,9 +120,6 @@ overrides:
prettier-internal-rules/prefer-fast-path-each: error
prettier-internal-rules/prefer-indent-if-break: error
prettier-internal-rules/prefer-is-non-empty-array: error
- files: src/document/*.js
rules:
prettier-internal-rules/no-doc-builder-concat: off
- files:
- src/language-*/**/*.js
rules:
+1 -1
View File
@@ -150,7 +150,7 @@
"lint:eslint": "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly",
"lint:changelog": "node ./scripts/lint-changelog.js",
"lint:prettier": "prettier . \"!test*\" --check",
"lint:dist": "eslint --no-eslintrc --no-ignore --env=es6,browser --parser-options=ecmaVersion:2018 \"dist/!(bin-prettier|index|third-party).js\"",
"lint:dist": "eslint --no-eslintrc --no-ignore --no-inline-config --env=es6,browser --parser-options=ecmaVersion:2018 \"dist/!(bin-prettier|index|third-party).js\"",
"lint:spellcheck": "cspell \"**/*\" \".github/**/*\"",
"lint:deps": "node ./scripts/check-deps.js",
"fix": "run-s fix:eslint fix:prettier",
+3
View File
@@ -211,7 +211,9 @@ const literallineWithoutBreakParent = {
const line = { type: "line" };
const softline = { type: "line", soft: true };
// eslint-disable-next-line prettier-internal-rules/no-doc-builder-concat
const hardline = concat([hardlineWithoutBreakParent, breakParent]);
// eslint-disable-next-line prettier-internal-rules/no-doc-builder-concat
const literalline = concat([literallineWithoutBreakParent, breakParent]);
const cursor = { type: "cursor", placeholder: Symbol("cursor") };
@@ -232,6 +234,7 @@ function join(sep, arr) {
res.push(arr[i]);
}
// eslint-disable-next-line prettier-internal-rules/no-doc-builder-concat
return concat(res);
}
+2 -2
View File
@@ -2,7 +2,7 @@
const { getStringWidth } = require("../common/util");
const { convertEndOfLineToChars } = require("../common/end-of-line");
const { concat, fill, cursor, indent } = require("./doc-builders");
const { fill, cursor, indent } = require("./doc-builders");
const { isConcat, getDocParts } = require("./doc-utils");
/** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
@@ -452,7 +452,7 @@ function printDocToString(doc, options) {
const firstAndSecondContentFlatCmd = [
ind,
MODE_FLAT,
concat([content, whitespace, secondContent]),
[content, whitespace, secondContent],
];
const firstAndSecondContentFits = fits(
firstAndSecondContentFlatCmd,
+2 -6
View File
@@ -1,6 +1,6 @@
"use strict";
const { literalline, concat } = require("./doc-builders");
const { literalline } = require("./doc-builders");
const isConcat = (doc) => Array.isArray(doc) || (doc && doc.type === "concat");
const getDocParts = (doc) => {
@@ -371,11 +371,7 @@ function normalizeDoc(doc) {
function replaceNewlinesWithLiterallines(doc) {
return mapDoc(doc, (currentDoc) =>
typeof currentDoc === "string" && currentDoc.includes("\n")
? concat(
currentDoc
.split(/(\n)/g)
.map((v, i) => (i % 2 === 0 ? v : literalline))
)
? currentDoc.split(/(\n)/g).map((v, i) => (i % 2 === 0 ? v : literalline))
: currentDoc
);
}