textlint-rule-helper
Version:
A helper library for textlint rule.
69 lines (68 loc) • 2.1 kB
TypeScript
import type { TextlintRuleContext } from "@textlint/types";
import { TxtNode } from "@textlint/ast-node-types";
/**
* RuleHelper is helper class for textlint.
* @class RuleHelper
*/
export default class RuleHelper {
private _ruleContext;
/**
* Initialize RuleHelper with RuleContext object.
* @param ruleContext the ruleContext is context object of the rule.
*/
constructor(ruleContext: Readonly<TextlintRuleContext>);
/**
* Get parents of node.
* The parent nodes are returned in order from the closest parent to the outer ones.
* {@link node} is not contained in the results.
* @param {TxtNode} node the node is start point.
*/
getParents(node: TxtNode): import("@textlint/ast-node-types").TxtParentNode[];
/**
* Return true if `node` is wrapped any one of node {@link types}.
* @param {TxtNode} node is target node
* @param {string[]} types are wrapped target node
* @returns {boolean}
*/
isChildNode(node: TxtNode, types: string[]): boolean;
/**
* Return true if the node is Str node and fill following conditions
*
* - the node is Str node
* - the node is under the Paragraph node
* - the node is not under the BlockQuote
*
* This function is useful for common use-case.
* If you want to lint Str node, but you not want to lint styled node, this function is useful.
* styled node is Link, Strong, BlockQuote, Header etc...
* Opposite of it, plain str node is just under the Paragraph node.
*
* @example
*
* Return true
*
* ---
* str str str
* - list text
* ---
*
* Return false
*
* ----
* # Header
* 
* [link title](https://example.com)
* > BlockQuote
* **Strong**
* [^footnote]: text text
* ----
*
* Summary:
*
* Return true if the node is plain text.
* In other words, return false if the node is styled
*
* @param node
*/
isPlainStrNode(node: TxtNode): boolean;
}