feat: newline and space utils to shared (#5049)

master
Evilebot Tnawi 2018-09-04 23:08:37 +03:00 committed by GitHub
parent 50c9115632
commit 7fd346ffa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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");