@anchan828/textlint-rule-decorators

> TODO: description

Usage no npm install needed!

<script type="module">
  import anchan828TextlintRuleDecorators from 'https://cdn.skypack.dev/@anchan828/textlint-rule-decorators';
</script>

README

@anchan828/textlint-rule-decorators

Install

npm i @anchan828/textlint-rule-decorators reflect-metadata

Usage

import { createReportModule, TextlintRule, TextlintASTNodeType } from "@anchan828/textlint-rule-decorators";

@TextlintRule()
class MyRule {
  constructor(private context: Readonly<TextlintRuleContext>) {}

  @TextlintASTNodeType(ASTNodeTypes.Str)
  async strReporter(node: TypeofTxtNode<ASTNodeTypes.Str>): Promise<void> {
    if (node.value === "error") {
      const ruleError = new this.context.RuleError(`error`, {
        fix: this.context.fixer.replaceText(node, "valid"),
      });

      this.context.report(node, ruleError);
    }
  }
}

export = createReportModule([MyRule]);