Move each rule implementation into its own file (fixes #83).

This commit is contained in:
David Anson 2018-01-21 21:44:25 -08:00
parent 49e36f817c
commit 9ba143555d
42 changed files with 1289 additions and 1028 deletions

34
lib/md038.js Normal file
View file

@ -0,0 +1,34 @@
// @ts-check
"use strict";
var shared = require("./shared");
var inlineCodeSpansRe = /(?:^|[^\\])((`+)((?:.*?[^`])|)\2(?!`))/g;
module.exports = {
"names": [ "MD038", "no-space-in-code" ],
"description": "Spaces inside code span elements",
"tags": [ "whitespace", "code" ],
"function": function MD038(params, onError) {
shared.forEachInlineChild(params, "code_inline",
function forToken(token) {
var line = params.lines[token.lineNumber - 1];
var match = null;
while ((match = inlineCodeSpansRe.exec(line)) !== null) {
var inlineCodeSpan = match[1];
var content = match[3];
var length = inlineCodeSpan.length;
var column = match.index + 1 + (match[0].length - length);
var range = [ column, length ];
if (/^\s([^`]|$)/.test(content)) {
shared.addErrorContext(onError, token.lineNumber,
inlineCodeSpan, true, false, range);
} else if (/[^`]\s$/.test(content)) {
shared.addErrorContext(onError, token.lineNumber,
inlineCodeSpan, false, true, range);
}
}
});
}
};