id | title |
---|---|
filter-rule |
Creating Filter Rule |
Filter rule is same writing convention with linting/fixing rule, but has different context.
Add filter rule name to filters
field.
{
"filters": {
"comments": true
}
}
See configuring.md for details.
{
"filters": {
"<name>": true
}
}
The rule <name>
can be accept following patterns:
textlint-filter-rule-<name>
<name>
@scope/textlint-filter-rule-<name>
@scope/<name>
shouldIgnore()
is core API of FilterRuleContext
.
shouldIgnore(range, { ruleId })
is a method that report reports ignoringrange
( is array like[start, end]
).context.shouldIgnore(node.range);
filter all messagescontext.shouldIgnore(node.range, { ruleId: "rule-id" });
filter messages that are reported"rule-id"
rule.
Syntax.*
is const values of TxtNode type.- e.g.)
context.Syntax.Str
- packages/@textlint/ast-node-types/src/index.ts
- e.g.)
getSource(<node>)
is a method gets the source code for the given node.- e.g.)
context.getSource(node); // => "text"
- e.g.)
getFilePath()
return file path that is linting target.- e.g.)
context.getFilePath(): // => /path/to/file.md or undefined
- e.g.)
Filter all BlockQuote
node.
module.exports = function (context) {
const exports = {};
exports[context.Syntax.BlockQuote] = function (node) {
context.shouldIgnore(node.range);
/* ===
context.shouldIgnore(node.range, {
ruleId: "*"
});
*/
};
return exports;
};
Filter messages which is reported by no-todo
rule.
module.exports = function (context) {
const exports = {};
exports[context.Syntax.Str] = function (node) {
context.shouldIgnore(node.range, {
ruleId: "no-todo"
});
};
return exports;
};
textlint's filter rule should use textlint-filter-rule-
prefix.
For example, filtering by comment rule is textlint-filter-rule-comments
.
textlint user use it by setting following:
{
"filters": {
"comments": true
}
}