feat: newline and space utils to shared (#5049)
parent
50c9115632
commit
7fd346ffa1
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue