2018-02-15 21:35:58 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-01-15 21:56:38 -08:00
|
|
|
const { URL } = require("url");
|
|
|
|
|
2018-02-15 21:35:58 -08:00
|
|
|
module.exports = {
|
|
|
|
"names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
|
|
|
"description": "Rule that reports an error for lines with the letters 'EX'",
|
2019-01-15 21:56:38 -08:00
|
|
|
"information": new URL(
|
|
|
|
"https://github.com/DavidAnson/markdownlint" +
|
2020-08-11 22:52:29 -07:00
|
|
|
"/blob/main/test/rules/letters-E-X.js"
|
2019-01-15 21:56:38 -08:00
|
|
|
),
|
2018-02-15 21:35:58 -08:00
|
|
|
"tags": [ "test" ],
|
|
|
|
"function": function rule(params, onError) {
|
|
|
|
params.tokens.filter(function filterToken(token) {
|
|
|
|
return token.type === "inline";
|
|
|
|
}).forEach(function forToken(inline) {
|
|
|
|
inline.children.filter(function filterChild(child) {
|
|
|
|
return child.type === "text";
|
|
|
|
}).forEach(function forChild(text) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const index = text.content.toLowerCase().indexOf("ex");
|
2018-02-15 21:35:58 -08:00
|
|
|
if (index !== -1) {
|
|
|
|
onError({
|
|
|
|
"lineNumber": text.lineNumber,
|
2018-02-27 21:14:02 -08:00
|
|
|
"context": text.content.substr(index - 1, 4)
|
2018-02-15 21:35:58 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|