mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Add support for using custom rules.
This commit is contained in:
parent
4619a8c824
commit
f24f98e146
11 changed files with 497 additions and 71 deletions
22
test/rules/blockquote.js
Normal file
22
test/rules/blockquote.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"names": [ "blockquote" ],
|
||||
"description": "Rule that reports an error for blockquotes",
|
||||
"tags": [ "test" ],
|
||||
"function": function rule(params, onError) {
|
||||
params.tokens.filter(function filterToken(token) {
|
||||
return token.type === "blockquote_open";
|
||||
}).forEach(function forToken(blockquote) {
|
||||
var lines = blockquote.map[1] - blockquote.map[0];
|
||||
onError({
|
||||
"lineNumber": blockquote.lineNumber,
|
||||
"detail": "Blockquote spans " + lines + " line(s).",
|
||||
"context": blockquote.line.substr(0, 7),
|
||||
"range": null
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
23
test/rules/every-n-lines.js
Normal file
23
test/rules/every-n-lines.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"names": [ "every-n-lines" ],
|
||||
"description": "Rule that reports an error every N lines",
|
||||
"tags": [ "test" ],
|
||||
"function": function rule(params, onError) {
|
||||
var n = params.config.n || 2;
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
var lineNumber = lineIndex + 1;
|
||||
if ((lineNumber % n) === 0) {
|
||||
onError({
|
||||
"lineNumber": lineNumber,
|
||||
"detail": "Line number " + lineNumber,
|
||||
"context": null,
|
||||
"range": null
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
28
test/rules/letters-E-X.js
Normal file
28
test/rules/letters-E-X.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
||||
"description": "Rule that reports an error for lines with the letters 'EX'",
|
||||
"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) {
|
||||
var index = text.content.toLowerCase().indexOf("ex");
|
||||
if (index !== -1) {
|
||||
onError({
|
||||
"lineNumber": text.lineNumber,
|
||||
"detail": null,
|
||||
"context": text.content.substr(index - 1, 4),
|
||||
"range": null
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
13
test/rules/package.json
Normal file
13
test/rules/package.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "markdownlint-rules-test",
|
||||
"version": "0.0.1",
|
||||
"description": "Package of markdownlint custom rules used for testing",
|
||||
"main": "rules.js",
|
||||
"author": "David Anson (https://dlaa.me/)",
|
||||
"homepage": "https://github.com/DavidAnson/markdownlint",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"markdownlint-rules"
|
||||
],
|
||||
"private": true
|
||||
}
|
||||
18
test/rules/rules.js
Normal file
18
test/rules/rules.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
var blockquote = require("./blockquote");
|
||||
module.exports.blockquote = blockquote;
|
||||
|
||||
var everyNLines = require("./every-n-lines");
|
||||
module.exports.everyNLines = everyNLines;
|
||||
|
||||
var lettersEX = require("./letters-E-X");
|
||||
module.exports.lettersEX = lettersEX;
|
||||
|
||||
module.exports.all = [
|
||||
blockquote,
|
||||
everyNLines,
|
||||
lettersEX
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue