mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-24 09:50:13 +01:00
Move each rule implementation into its own file (fixes #83).
This commit is contained in:
parent
49e36f817c
commit
9ba143555d
42 changed files with 1289 additions and 1028 deletions
63
lib/md013.js
Normal file
63
lib/md013.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
|
||||
var labelRe = /^\s*\[.*[^\\]]:/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD013", "line-length" ],
|
||||
"description": "Line length",
|
||||
"tags": [ "line_length" ],
|
||||
"function": function MD013(params, onError) {
|
||||
var lineLength = params.config.line_length || 80;
|
||||
var codeBlocks = params.config.code_blocks;
|
||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
var tables = params.config.tables;
|
||||
var includeTables = (tables === undefined) ? true : !!tables;
|
||||
var headers = params.config.headers;
|
||||
var includeHeaders = (headers === undefined) ? true : !!headers;
|
||||
var headerLineNumbers = [];
|
||||
if (!includeHeaders) {
|
||||
shared.forEachHeading(params, function forHeading(heading) {
|
||||
headerLineNumbers.push(heading.lineNumber);
|
||||
});
|
||||
}
|
||||
var tokenTypeMap = {
|
||||
"em_open": "e",
|
||||
"em_close": "E",
|
||||
"link_open": "l",
|
||||
"link_close": "L",
|
||||
"strong_open": "s",
|
||||
"strong_close": "S",
|
||||
"text": "T"
|
||||
};
|
||||
var linkOnlyLineNumbers = [];
|
||||
shared.filterTokens(params, "inline", function forToken(token) {
|
||||
var childTokenTypes = "";
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type !== "text" || child.content !== "") {
|
||||
childTokenTypes += tokenTypeMap[child.type] || "x";
|
||||
}
|
||||
});
|
||||
if (/^[es]*lT?L[ES]*$/.test(childTokenTypes)) {
|
||||
linkOnlyLineNumbers.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
var longLineRe = new RegExp("^(.{" + lineLength + "})(.*\\s.*)$");
|
||||
shared.forEachLine(params,
|
||||
function forLine(line, lineIndex, inCode, onFence, inTable) {
|
||||
var lineNumber = lineIndex + 1;
|
||||
if ((includeCodeBlocks || !inCode) &&
|
||||
(includeTables || !inTable) &&
|
||||
(includeHeaders || (headerLineNumbers.indexOf(lineNumber)) < 0) &&
|
||||
(linkOnlyLineNumbers.indexOf(lineNumber) < 0) &&
|
||||
longLineRe.test(line) &&
|
||||
!labelRe.test(line)) {
|
||||
shared.addErrorDetailIf(onError, lineNumber, lineLength,
|
||||
line.length, null, shared.rangeFromRegExp(line, longLineRe));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue