Skip to content

2.1.0

Compare
Choose a tag to compare
@azu azu released this 03 Jan 05:57
· 31 commits to master since this release

Bug Fixes

Features

  • wrap: add wrapReportHandler(context, options, handler): TextlintRuleReportHandler function (c8fb78b)

wrapReportHandler is high-level and declarative API for ignore nodes.
We have designed that wrapReportHandler is easy to use.

If you want to ignore some Node's type, we recommended to use wrapReportHandler.

import { wrapReportHandler } from "textlint-rule-helper";
const reporter = function (context) {
   const { Syntax, getSource } = context;
   return wrapReportHandler(context, {
       ignoreNodeTypes: [Syntax.BlockQuote, Syntax.Code]
   },report => { // <= wrap version of context.report
       // handler should return a rule handler object
       return {
           [Syntax.Paragraph](node) {
               const text = getSource(node);
               const index = text.search("code");
               /*
                * Following text is matched, but it will not reported.
                * ----
                * This is `code`.
                * > code
                * ----
                */
                if(index === -1){
                    return;
                }
                report(node, new context.RuleError(item.name, {
                   index
                }));
           }
       }
   });
};
module.exports = reporter;