diff --git a/changelog_unreleased/api/pr-6993.md b/changelog_unreleased/api/pr-6993.md new file mode 100644 index 000000000..4ba110982 --- /dev/null +++ b/changelog_unreleased/api/pr-6993.md @@ -0,0 +1,21 @@ +#### Remove deprecated api ([#6993](https://github.com/prettier/prettier/pull/6993) by [@fisker](https://github.com/fisker)) + +- Parser `typescript-eslint` is removed. + + Use `typescript` instead. + +- `prettier.util.mapDoc` is removed + + Use `prettier.doc.utils.mapDoc` instead. + +- `prettier.util.isNextLineEmpty` is updated + + Use `isNextLineEmpty(text, node, locEnd)` instead of `isNextLineEmpty(text, node, options)`. + +- `prettier.util.isPreviousLineEmpty` is updated + + Use `isPreviousLineEmpty(text, node, locStart)` instead of `isNextLineEmpty(text, node, options)`. + +- `prettier.util.getNextNonSpaceNonCommentCharacterIndex` is updated + + Use `getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)` instead of `getNextNonSpaceNonCommentCharacterIndex(text, node, options)`. diff --git a/docs/plugins.md b/docs/plugins.md index c6ef2471f..5743e884a 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -249,7 +249,6 @@ function getNextNonSpaceNonCommentCharacterIndex(text: string, node: N, locEn function isNextLineEmptyAfterIndex(text: string, index: number): boolean; function isNextLineEmpty(text: string, node: N, locEnd: (node: N) => number): boolean; function isPreviousLineEmpty(text: string, node: N, locStart: (node: N) => number): boolean; -function mapDoc(doc: object, callback: function): void; ``` ### Tutorials diff --git a/src/common/internal-plugins.js b/src/common/internal-plugins.js index 85bd20a20..3f4920656 100644 --- a/src/common/internal-plugins.js +++ b/src/common/internal-plugins.js @@ -59,13 +59,6 @@ module.exports = [ return eval("require")("../language-js/parser-typescript").parsers .typescript; }, - /** - * TODO: Remove this old alias in a major version - */ - get "typescript-eslint"() { - return eval("require")("../language-js/parser-typescript").parsers - .typescript; - }, // JS - Angular Action get __ng_action() { return eval("require")("../language-js/parser-angular").parsers @@ -136,7 +129,6 @@ module.exports = [ return eval("require")("../language-markdown/parser-markdown").parsers .remark; }, - // TODO: Delete this in 2.0 get markdown() { return eval("require")("../language-markdown/parser-markdown").parsers .remark; diff --git a/src/common/util-shared.js b/src/common/util-shared.js index a7581c08e..2c252e0c1 100644 --- a/src/common/util-shared.js +++ b/src/common/util-shared.js @@ -1,47 +1,53 @@ "use strict"; -const util = require("./util"); -const { mapDoc } = require("../document").utils; - -function isNextLineEmpty(text, node, options) { - return util.isNextLineEmpty(text, node, options.locEnd); -} - -function isPreviousLineEmpty(text, node, options) { - return util.isPreviousLineEmpty(text, node, options.locStart); -} - -function getNextNonSpaceNonCommentCharacterIndex(text, node, options) { - return util.getNextNonSpaceNonCommentCharacterIndex( - text, - node, - options.locEnd - ); -} - -module.exports = { - getMaxContinuousCount: util.getMaxContinuousCount, - getStringWidth: util.getStringWidth, - getAlignmentSize: util.getAlignmentSize, - getIndentSize: util.getIndentSize, - skip: util.skip, - skipWhitespace: util.skipWhitespace, - skipSpaces: util.skipSpaces, - skipNewline: util.skipNewline, - skipToLineEnd: util.skipToLineEnd, - skipEverythingButNewLine: util.skipEverythingButNewLine, - skipInlineComment: util.skipInlineComment, - skipTrailingComment: util.skipTrailingComment, - hasNewline: util.hasNewline, - hasNewlineInRange: util.hasNewlineInRange, - hasSpaces: util.hasSpaces, +const { + getMaxContinuousCount, + getStringWidth, + getAlignmentSize, + getIndentSize, + skip, + skipWhitespace, + skipSpaces, + skipNewline, + skipToLineEnd, + skipEverythingButNewLine, + skipInlineComment, + skipTrailingComment, + hasNewline, + hasNewlineInRange, + hasSpaces, isNextLineEmpty, - isNextLineEmptyAfterIndex: util.isNextLineEmptyAfterIndex, + isNextLineEmptyAfterIndex, isPreviousLineEmpty, getNextNonSpaceNonCommentCharacterIndex, - mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils - makeString: util.makeString, - addLeadingComment: util.addLeadingComment, - addDanglingComment: util.addDanglingComment, - addTrailingComment: util.addTrailingComment + makeString, + addLeadingComment, + addDanglingComment, + addTrailingComment +} = require("./util"); + +module.exports = { + getMaxContinuousCount, + getStringWidth, + getAlignmentSize, + getIndentSize, + skip, + skipWhitespace, + skipSpaces, + skipNewline, + skipToLineEnd, + skipEverythingButNewLine, + skipInlineComment, + skipTrailingComment, + hasNewline, + hasNewlineInRange, + hasSpaces, + isNextLineEmpty, + isNextLineEmptyAfterIndex, + isPreviousLineEmpty, + getNextNonSpaceNonCommentCharacterIndex, + makeString, + addLeadingComment, + addDanglingComment, + addTrailingComment }; diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index 716a237d5..2bd21f79c 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -893,7 +893,7 @@ function printNodeSequence(path, options, print) { isNextLineEmpty( options.originalText, pathChild.getValue(), - options + options.locEnd ) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml" diff --git a/src/language-graphql/printer-graphql.js b/src/language-graphql/printer-graphql.js index 658636001..37c705ed0 100644 --- a/src/language-graphql/printer-graphql.js +++ b/src/language-graphql/printer-graphql.js @@ -32,7 +32,11 @@ function genericPrint(path, options, print) { if (index !== n.definitions.length - 1) { parts.push(hardline); if ( - isNextLineEmpty(options.originalText, pathChild.getValue(), options) + isNextLineEmpty( + options.originalText, + pathChild.getValue(), + options.locEnd + ) ) { parts.push(hardline); } @@ -629,7 +633,7 @@ function printSequence(sequencePath, options, print) { const printed = print(path); if ( - isNextLineEmpty(options.originalText, path.getValue(), options) && + isNextLineEmpty(options.originalText, path.getValue(), options.locEnd) && i < count - 1 ) { return concat([printed, hardline]); diff --git a/src/language-js/comments.js b/src/language-js/comments.js index 2b63db2dd..e619d04af 100644 --- a/src/language-js/comments.js +++ b/src/language-js/comments.js @@ -535,7 +535,11 @@ function handleCommentAfterArrowParams(text, enclosingNode, comment, options) { return false; } - const index = getNextNonSpaceNonCommentCharacterIndex(text, comment, options); + const index = getNextNonSpaceNonCommentCharacterIndex( + text, + comment, + options.locEnd + ); if (text.slice(index, index + 2) === "=>") { addDanglingComment(enclosingNode, comment); return true; diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 39f6de7dd..33c197049 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -480,7 +480,11 @@ function printPathNoParens(path, options, print, args) { path.each(childPath => { parts.push(print(childPath), semi, hardline); if ( - isNextLineEmpty(options.originalText, childPath.getValue(), options) + isNextLineEmpty( + options.originalText, + childPath.getValue(), + options.locEnd + ) ) { parts.push(hardline); } @@ -834,7 +838,7 @@ function printPathNoParens(path, options, print, args) { const nextCharacter = getNextNonSpaceNonCommentCharacterIndex( options.originalText, comment, - options + options.locEnd ); return ( options.originalText.slice(nextCharacter, nextCharacter + 2) === @@ -1117,7 +1121,11 @@ function printPathNoParens(path, options, print, args) { path.each(childPath => { parts.push(indent(concat([hardline, print(childPath), semi]))); if ( - isNextLineEmpty(options.originalText, childPath.getValue(), options) + isNextLineEmpty( + options.originalText, + childPath.getValue(), + options.locEnd + ) ) { parts.push(hardline); } @@ -1352,7 +1360,9 @@ function printPathNoParens(path, options, print, args) { ) { separatorParts.shift(); } - if (isNextLineEmpty(options.originalText, prop.node, options)) { + if ( + isNextLineEmpty(options.originalText, prop.node, options.locEnd) + ) { separatorParts.push(hardline); } return result; @@ -2037,7 +2047,11 @@ function printPathNoParens(path, options, print, args) { return concat([ casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && - isNextLineEmpty(options.originalText, caseNode, options) + isNextLineEmpty( + options.originalText, + caseNode, + options.locEnd + ) ? hardline : "" ]); @@ -3556,7 +3570,7 @@ function printPathNoParens(path, options, print, args) { case "InterpreterDirective": parts.push("#!", n.value, hardline); - if (isNextLineEmpty(options.originalText, n, options)) { + if (isNextLineEmpty(options.originalText, n, options.locEnd)) { parts.push(hardline); } @@ -3723,7 +3737,10 @@ function printStatementSequence(path, options, print) { } } - if (isNextLineEmpty(text, stmt, options) && !isLastStatement(stmtPath)) { + if ( + isNextLineEmpty(text, stmt, options.locEnd) && + !isLastStatement(stmtPath) + ) { parts.push(hardline); } @@ -4057,7 +4074,7 @@ function printArgumentsList(path, options, print) { if (index === lastArgIndex) { // do nothing - } else if (isNextLineEmpty(options.originalText, arg, options)) { + } else if (isNextLineEmpty(options.originalText, arg, options.locEnd)) { if (index === 0) { hasEmptyLineFollowingFirstArg = true; } @@ -4260,7 +4277,7 @@ function printFunctionParams(path, print, options, expandArg, printTypeParams) { shouldExpandParameters ) { parts.push(", "); - } else if (isNextLineEmpty(options.originalText, param, options)) { + } else if (isNextLineEmpty(options.originalText, param, options.locEnd)) { parts.push(",", hardline, hardline); } else { parts.push(",", line); @@ -4832,7 +4849,7 @@ function printMemberChain(path, options, print) { const nextCharIndex = getNextNonSpaceNonCommentCharacterIndex( originalText, node, - options + options.locEnd ); const nextChar = originalText.charAt(nextCharIndex); @@ -4842,11 +4859,11 @@ function printMemberChain(path, options, print) { return isNextLineEmptyAfterIndex( originalText, nextCharIndex + 1, - options + options.locEnd ); } - return isNextLineEmpty(originalText, node, options); + return isNextLineEmpty(originalText, node, options.locEnd); } function rec(path) { @@ -5950,7 +5967,11 @@ function printArrayItems(path, options, printPath, print) { separatorParts = [",", line]; if ( childPath.getValue() && - isNextLineEmpty(options.originalText, childPath.getValue(), options) + isNextLineEmpty( + options.originalText, + childPath.getValue(), + options.locEnd + ) ) { separatorParts.push(softline); } diff --git a/src/language-markdown/parser-markdown.js b/src/language-markdown/parser-markdown.js index ed3fff029..65d4fce99 100644 --- a/src/language-markdown/parser-markdown.js +++ b/src/language-markdown/parser-markdown.js @@ -109,7 +109,6 @@ const mdxParser = { ...baseParser, parse: createParse({ isMDX: true }) }; module.exports = { parsers: { remark: markdownParser, - // TODO: Delete this in 2.0 markdown: markdownParser, mdx: mdxParser } diff --git a/tests_integration/__tests__/util-shared.js b/tests_integration/__tests__/util-shared.js index 15ea6f0d8..c8b6dd780 100644 --- a/tests_integration/__tests__/util-shared.js +++ b/tests_integration/__tests__/util-shared.js @@ -24,7 +24,6 @@ test("shared util has correct structure", () => { expect(typeof sharedUtil.getNextNonSpaceNonCommentCharacterIndex).toEqual( "function" ); - expect(typeof sharedUtil.mapDoc).toEqual("function"); expect(typeof sharedUtil.makeString).toEqual("function"); });