textlint-rule-helper

  • Version 2.3.1
  • Published
  • 40.5 kB
  • 3 dependencies
  • MIT license

Install

npm i textlint-rule-helper
yarn add textlint-rule-helper
pnpm add textlint-rule-helper

Overview

A helper library for textlint rule.

Index

Functions

function wrapReportHandler

wrapReportHandler: <
T extends TextlintRuleContext,
R extends TextlintRuleReportHandler
>(
context: T,
options: wrapReportHandlerOptions,
handler: (report: (node: AnyTxtNode, ruleError: TextlintRuleError) => void) => R
) => R;
  • Parameter context

    Parameter options

    Parameter handler

Classes

class IgnoreNodeManager

class IgnoreNodeManager {}
  • Ignore node manager that manager ignored ranges.

constructor

constructor();

    property ignoredRanges

    readonly ignoredRanges: TxtNodeRange[];
    • Returns

      {(number)[][]}

    method ignore

    ignore: (node: TxtNode | TxtParentNode) => void;
    • add node to ignore range list

      Parameter node

    method ignoreChildrenByTypes

    ignoreChildrenByTypes: (
    targetNode: TxtNode | TxtParentNode,
    ignoredNodeTypes: TxtNodeType[]
    ) => void;
    • ignore children node of node, if the children node has the type that is included in ignoredNodeTypes.

      Parameter targetNode

      Parameter ignoredNodeTypes

    method ignoreRange

    ignoreRange: (range: TxtNodeRange) => void;
    • add range to ignore range list

      Parameter range

    method isIgnored

    isIgnored: (node: TxtNode | TxtParentNode) => boolean;
    • Parameter node

      Returns

      {boolean}

    method isIgnoredIndex

    isIgnoredIndex: (index: number) => boolean;
    • |.......| ^ ^ Ignored Range

      |........| ^ index

      Parameter index

      Returns

      {boolean}

    method isIgnoredRange

    isIgnoredRange: (aRange: TxtNodeRange) => boolean;
    • Parameter aRange

      Returns

      {boolean}

      Deprecated

      This method will be removed

    class RuleHelper

    class RuleHelper {}
    • RuleHelper is helper class for textlint. RuleHelper

    constructor

    constructor(ruleContext: TextlintRuleContext);
    • Initialize RuleHelper with RuleContext object.

      Parameter ruleContext

      the ruleContext is context object of the rule.

    method getParents

    getParents: (
    node: TxtNode
    ) => import('@textlint/ast-node-types').TxtParentNode[];
    • Get parents of node. The parent nodes are returned in order from the closest parent to the outer ones. node is not contained in the results.

      Parameter node

      the node is start point.

    method isChildNode

    isChildNode: (node: TxtNode, types: string[]) => boolean;
    • Return true if node is wrapped any one of node types.

      Parameter node

      is target node

      Parameter types

      are wrapped target node

      Returns

      {boolean}

    method isPlainStrNode

    isPlainStrNode: (node: TxtNode) => 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.

      Parameter node

      Example 1

      Return true

      --- str str str - list text ---

      Return false

      ---- # Header ![alt text](https://example.com) [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

    Package Files (4)

    Dependencies (3)

    Dev Dependencies (10)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/textlint-rule-helper.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/textlint-rule-helper)
    • HTML
      <a href="https://www.jsdocs.io/package/textlint-rule-helper"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>