From 7fd346ffa1ef887b2c8e9b07d2a6c33494dc1fa5 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Tue, 4 Sep 2018 23:08:37 +0300 Subject: [PATCH] feat: newline and space utils to shared (#5049) --- docs/plugins.md | 6 ++++++ src/common/util-shared.js | 6 ++++++ tests_integration/__tests__/util-shared.js | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/docs/plugins.md b/docs/plugins.md index 0e522c971..f168a384c 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -220,6 +220,12 @@ defaultOptions: { A `util` module from Prettier core is considered a private API and is not meant to be consumed by plugins. Instead, the `util-shared` module provides the following limited set of utility functions for plugins: ```ts +skipWhitespace(text: string, index: number, options: object): number; +skipSpaces(text: string, index: number, options: object): number; +skipNewline(text: string, index: number, options: object): number; +hasNewline(text: string, index: number, options: object): boolean; +hasNewlineInRange(text: string, start: number, start: number): boolean; +hasSpaces(text: string, index: number, options: object): number; makeString(rawContent: string, enclosingQuote: string, unescapeUnnecessarEscapes: boolean): string; getNextNonSpaceNonCommentCharacterIndex(text: string, node: object, options: object): number; isNextLineEmptyAfterIndex(text: string, index: number): boolean; diff --git a/src/common/util-shared.js b/src/common/util-shared.js index cd34fe0b0..732a06510 100644 --- a/src/common/util-shared.js +++ b/src/common/util-shared.js @@ -20,6 +20,12 @@ function getNextNonSpaceNonCommentCharacterIndex(text, node, options) { } module.exports = { + skipWhitespace: util.skipWhitespace, + skipSpaces: util.skipSpaces, + skipNewline: util.skipNewline, + hasNewline: util.hasNewline, + hasNewlineInRange: util.hasNewlineInRange, + hasSpaces: util.hasSpaces, isNextLineEmpty, isNextLineEmptyAfterIndex: util.isNextLineEmptyAfterIndex, isPreviousLineEmpty, diff --git a/tests_integration/__tests__/util-shared.js b/tests_integration/__tests__/util-shared.js index 7c050593c..6fc4a81e0 100644 --- a/tests_integration/__tests__/util-shared.js +++ b/tests_integration/__tests__/util-shared.js @@ -3,6 +3,12 @@ const sharedUtil = require("../../src/common/util-shared"); test("shared util has correct structure", () => { + expect(typeof sharedUtil.skipWhitespace).toEqual("function"); + expect(typeof sharedUtil.skipSpaces).toEqual("function"); + expect(typeof sharedUtil.skipNewline).toEqual("function"); + expect(typeof sharedUtil.hasNewline).toEqual("function"); + expect(typeof sharedUtil.hasNewlineInRange).toEqual("function"); + expect(typeof sharedUtil.hasSpaces).toEqual("function"); expect(typeof sharedUtil.isNextLineEmpty).toEqual("function"); expect(typeof sharedUtil.isNextLineEmptyAfterIndex).toEqual("function"); expect(typeof sharedUtil.isPreviousLineEmpty).toEqual("function");