feat: more shared utils for plugins (#5254)
parent
4cc0363b40
commit
023a8b78df
|
@ -220,8 +220,17 @@ 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
|
||||
getMaxContinuousCount(str: string, target: string): number;
|
||||
getStringWidth(text: string): number;
|
||||
getAlignmentSize(value: string, tabWidth: number, startIndex: number): number;
|
||||
getIndentSize(value: string, tabWidth: number): number;
|
||||
skip(chars: string|RegExp): number;
|
||||
skipWhitespace(text: string, index: number, options: object): number;
|
||||
skipSpaces(text: string, index: number, options: object): number;
|
||||
skipToLineEnd(text: string, index: number, options: object): number;
|
||||
skipEverythingButNewLine(text: string, index: number, options: object): number;
|
||||
skipInlineComment(text: string, index: number): number;
|
||||
skipTrailingComment(text: string, index: number): 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;
|
||||
|
|
|
@ -20,9 +20,18 @@ function getNextNonSpaceNonCommentCharacterIndex(text, node, options) {
|
|||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -667,8 +667,13 @@ module.exports = {
|
|||
getLast,
|
||||
getNextNonSpaceNonCommentCharacterIndex,
|
||||
getNextNonSpaceNonCommentCharacter,
|
||||
skip,
|
||||
skipWhitespace,
|
||||
skipSpaces,
|
||||
skipToLineEnd,
|
||||
skipEverythingButNewLine,
|
||||
skipInlineComment,
|
||||
skipTrailingComment,
|
||||
skipNewline,
|
||||
isNextLineEmptyAfterIndex,
|
||||
isNextLineEmpty,
|
||||
|
|
|
@ -3,8 +3,17 @@
|
|||
const sharedUtil = require("../../src/common/util-shared");
|
||||
|
||||
test("shared util has correct structure", () => {
|
||||
expect(typeof sharedUtil.getMaxContinuousCount).toEqual("function");
|
||||
expect(typeof sharedUtil.getStringWidth).toEqual("function");
|
||||
expect(typeof sharedUtil.getAlignmentSize).toEqual("function");
|
||||
expect(typeof sharedUtil.getIndentSize).toEqual("function");
|
||||
expect(typeof sharedUtil.skip).toEqual("function");
|
||||
expect(typeof sharedUtil.skipWhitespace).toEqual("function");
|
||||
expect(typeof sharedUtil.skipSpaces).toEqual("function");
|
||||
expect(typeof sharedUtil.skipToLineEnd).toEqual("function");
|
||||
expect(typeof sharedUtil.skipEverythingButNewLine).toEqual("function");
|
||||
expect(typeof sharedUtil.skipInlineComment).toEqual("function");
|
||||
expect(typeof sharedUtil.skipTrailingComment).toEqual("function");
|
||||
expect(typeof sharedUtil.skipNewline).toEqual("function");
|
||||
expect(typeof sharedUtil.hasNewline).toEqual("function");
|
||||
expect(typeof sharedUtil.hasNewlineInRange).toEqual("function");
|
||||
|
|
Loading…
Reference in New Issue