@textlint/kernel
Version:
textlint kernel is core logic by pure JavaScript.
123 lines • 4.97 kB
TypeScript
import { TxtNode } from "@textlint/ast-node-types";
import type { TextlintSourceCodeRange } from "@textlint/types";
/**
* Fix Command object has `range` and `text`.
* `IntermediateFixCommand` has also `isAbsolute` flag value.
*/
export interface IntermediateFixCommand {
text: string;
range: number[];
isAbsolute: boolean;
}
/**
* Creates code fixing commands for rules.
* It create command for fixing texts.
* The `range` arguments of these command is should be **relative** value from reported node.
* See {@link resolveLocation} class for more detail.
* @constructor
*/
export default class RuleFixer {
/**
* Creates a fix command that inserts text after the given node or token.
* The fix is not applied until applyFixes() is called.
* @param {TxtNode} node The node or token to insert after.
* @param {string} text The text to insert.
* @returns {IntermediateFixCommand} The fix command.
*/
insertTextAfter(node: TxtNode, text: string): {
range: readonly [number, number];
text: string;
isAbsolute: boolean;
};
/**
* Creates a fix command that inserts text after the specified range in the source text.
* The fix is not applied until applyFixes() is called.
* @param {number[]} range The range to replace, first item is start of range, second
* is end of range.
* The `range` should be **relative** value from reported node.
* @param {string} text The text to insert.
* @returns {IntermediateFixCommand} The fix command.
*/
insertTextAfterRange(range: TextlintSourceCodeRange, text: string): {
range: number[];
text: string;
isAbsolute: boolean;
};
/**
* Creates a fix command that inserts text before the given node or token.
* The fix is not applied until applyFixes() is called.
* @param {TxtNode} node The node or token to insert before.
* @param {string} text The text to insert.
* @returns {IntermediateFixCommand} The fix command.
*/
insertTextBefore(node: TxtNode, text: string): {
range: readonly [number, number];
text: string;
isAbsolute: boolean;
};
/**
* Creates a fix command that inserts text before the specified range in the source text.
* The fix is not applied until applyFixes() is called.
* @param {number[]} range The range to replace, first item is start of range, second
* is end of range.
* The `range` should be **relative** value from reported node.
* @param {string} text The text to insert.
* @returns {IntermediateFixCommand} The fix command.
*/
insertTextBeforeRange(range: TextlintSourceCodeRange, text: string): {
range: number[];
text: string;
isAbsolute: boolean;
};
/**
* Creates a fix command that replaces text at the node or token.
* The fix is not applied until applyFixes() is called.
* @param {TxtNode} node The node or token to remove.
* @param {string} text The text to insert.
* @returns {IntermediateFixCommand} The fix command.
*/
replaceText(node: TxtNode, text: string): {
range: import("@textlint/ast-node-types").TxtNodeRange;
text: string;
isAbsolute: boolean;
};
/**
* Creates a fix command that replaces text at the specified range in the source text.
* The fix is not applied until applyFixes() is called.
* @param {number[]} range The range to replace, first item is start of range, second
* is end of range.
* The `range` should be **relative** value from reported node.
* @param {string} text The text to insert.
* @returns {IntermediateFixCommand} The fix command.
*/
replaceTextRange(range: TextlintSourceCodeRange, text: string): {
range: TextlintSourceCodeRange;
text: string;
isAbsolute: boolean;
};
/**
* Creates a fix command that removes the node or token from the source.
* The fix is not applied until applyFixes() is called.
* @param {TxtNode} node The node or token to remove.
* @returns {IntermediateFixCommand} The fix command.
*/
remove(node: TxtNode): {
range: import("@textlint/ast-node-types").TxtNodeRange;
text: string;
isAbsolute: boolean;
};
/**
* Creates a fix command that removes the specified range of text from the source.
* The fix is not applied until applyFixes() is called.
* @param {number[]} range The range to remove, first item is start of range, second
* is end of range.
* The `range` should be **relative** value from reported node.
* @returns {IntermediateFixCommand} The fix command.
*/
removeRange(range: TextlintSourceCodeRange): {
range: TextlintSourceCodeRange;
text: string;
isAbsolute: boolean;
};
}
//# sourceMappingURL=rule-fixer.d.ts.map