2.1.0
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;