mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Change "header" to "heading" across the library
This should be backward compatible, as all "header" aliases are still available, though documented as discouraged for future use.
This commit is contained in:
parent
e938f421a9
commit
45424cf459
148 changed files with 861 additions and 699 deletions
|
|
@ -5,9 +5,9 @@
|
|||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD001", "header-increment" ],
|
||||
"description": "Header levels should only increment by one level at a time",
|
||||
"tags": [ "headers" ],
|
||||
"names": [ "MD001", "heading-increment", "header-increment" ],
|
||||
"description": "Heading levels should only increment by one level at a time",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD001(params, onError) {
|
||||
var prevLevel = 0;
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD002", "first-header-h1" ],
|
||||
"description": "First header should be a top level header",
|
||||
"tags": [ "headers" ],
|
||||
"names": [ "MD002", "first-heading-h1", "first-header-h1" ],
|
||||
"description": "First heading should be a top level heading",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD002(params, onError) {
|
||||
var level = params.config.level || 1;
|
||||
var tag = "h" + level;
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD003", "header-style" ],
|
||||
"description": "Header style",
|
||||
"tags": [ "headers" ],
|
||||
"names": [ "MD003", "heading-style", "header-style" ],
|
||||
"description": "Heading style",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD003(params, onError) {
|
||||
var style = params.config.style || "consistent";
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
|
|
|
|||
15
lib/md013.js
15
lib/md013.js
|
|
@ -16,12 +16,15 @@ module.exports = {
|
|||
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) {
|
||||
var headings = params.config.headings;
|
||||
if (headings === undefined) {
|
||||
headings = params.config.headers;
|
||||
}
|
||||
var includeHeadings = (headings === undefined) ? true : !!headings;
|
||||
var headingLineNumbers = [];
|
||||
if (!includeHeadings) {
|
||||
shared.forEachHeading(params, function forHeading(heading) {
|
||||
headerLineNumbers.push(heading.lineNumber);
|
||||
headingLineNumbers.push(heading.lineNumber);
|
||||
});
|
||||
}
|
||||
var tokenTypeMap = {
|
||||
|
|
@ -51,7 +54,7 @@ module.exports = {
|
|||
var lineNumber = lineIndex + 1;
|
||||
if ((includeCodeBlocks || !inCode) &&
|
||||
(includeTables || !inTable) &&
|
||||
(includeHeaders || (headerLineNumbers.indexOf(lineNumber)) < 0) &&
|
||||
(includeHeadings || (headingLineNumbers.indexOf(lineNumber)) < 0) &&
|
||||
(linkOnlyLineNumbers.indexOf(lineNumber) < 0) &&
|
||||
longLineRe.test(line) &&
|
||||
!labelRe.test(line)) {
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ var shared = require("./shared");
|
|||
|
||||
module.exports = {
|
||||
"names": [ "MD018", "no-missing-space-atx" ],
|
||||
"description": "No space after hash on atx style header",
|
||||
"tags": [ "headers", "atx", "spaces" ],
|
||||
"description": "No space after hash on atx style heading",
|
||||
"tags": [ "headings", "headers", "atx", "spaces" ],
|
||||
"function": function MD018(params, onError) {
|
||||
shared.forEachLine(function forLine(line, lineIndex, inCode) {
|
||||
if (!inCode && /^#+[^#\s]/.test(line) && !/#$/.test(line)) {
|
||||
shared.addErrorContext(onError, lineIndex + 1, line.trim(), null,
|
||||
null, shared.rangeFromRegExp(line, shared.atxHeaderSpaceRe));
|
||||
null, shared.rangeFromRegExp(line, shared.atxHeadingSpaceRe));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ var shared = require("./shared");
|
|||
|
||||
module.exports = {
|
||||
"names": [ "MD019", "no-multiple-space-atx" ],
|
||||
"description": "Multiple spaces after hash on atx style header",
|
||||
"tags": [ "headers", "atx", "spaces" ],
|
||||
"description": "Multiple spaces after hash on atx style heading",
|
||||
"tags": [ "headings", "headers", "atx", "spaces" ],
|
||||
"function": function MD019(params, onError) {
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
if ((shared.headingStyleFor(token) === "atx") &&
|
||||
/^#+\s\s/.test(token.line)) {
|
||||
shared.addErrorContext(onError, token.lineNumber, token.line.trim(),
|
||||
null, null,
|
||||
shared.rangeFromRegExp(token.line, shared.atxHeaderSpaceRe));
|
||||
shared.rangeFromRegExp(token.line, shared.atxHeadingSpaceRe));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
var shared = require("./shared");
|
||||
|
||||
var atxClosedHeaderNoSpaceRe = /(?:^#+[^#\s])|(?:[^#\s]#+\s*$)/;
|
||||
var atxClosedHeadingNoSpaceRe = /(?:^#+[^#\s])|(?:[^#\s]#+\s*$)/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD020", "no-missing-space-closed-atx" ],
|
||||
"description": "No space inside hashes on closed atx style header",
|
||||
"tags": [ "headers", "atx_closed", "spaces" ],
|
||||
"description": "No space inside hashes on closed atx style heading",
|
||||
"tags": [ "headings", "headers", "atx_closed", "spaces" ],
|
||||
"function": function MD020(params, onError) {
|
||||
shared.forEachLine(function forLine(line, lineIndex, inCode) {
|
||||
if (!inCode && /^#+[^#]*[^\\]#+$/.test(line)) {
|
||||
|
|
@ -17,7 +17,7 @@ module.exports = {
|
|||
var right = /[^#\s]#+$/.test(line);
|
||||
if (left || right) {
|
||||
shared.addErrorContext(onError, lineIndex + 1, line.trim(), left,
|
||||
right, shared.rangeFromRegExp(line, atxClosedHeaderNoSpaceRe));
|
||||
right, shared.rangeFromRegExp(line, atxClosedHeadingNoSpaceRe));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
var shared = require("./shared");
|
||||
|
||||
var atxClosedHeaderSpaceRe = /(?:^#+\s\s+?\S)|(?:\S\s\s+?#+\s*$)/;
|
||||
var atxClosedHeadingSpaceRe = /(?:^#+\s\s+?\S)|(?:\S\s\s+?#+\s*$)/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD021", "no-multiple-space-closed-atx" ],
|
||||
"description": "Multiple spaces inside hashes on closed atx style header",
|
||||
"tags": [ "headers", "atx_closed", "spaces" ],
|
||||
"description": "Multiple spaces inside hashes on closed atx style heading",
|
||||
"tags": [ "headings", "headers", "atx_closed", "spaces" ],
|
||||
"function": function MD021(params, onError) {
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (shared.headingStyleFor(token) === "atx_closed") {
|
||||
|
|
@ -18,7 +18,7 @@ module.exports = {
|
|||
if (left || right) {
|
||||
shared.addErrorContext(onError, token.lineNumber, token.line.trim(),
|
||||
left, right,
|
||||
shared.rangeFromRegExp(token.line, atxClosedHeaderSpaceRe));
|
||||
shared.rangeFromRegExp(token.line, atxClosedHeadingSpaceRe));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD022", "blanks-around-headers" ],
|
||||
"description": "Headers should be surrounded by blank lines",
|
||||
"tags": [ "headers", "blank_lines" ],
|
||||
"names": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
|
||||
"description": "Headings should be surrounded by blank lines",
|
||||
"tags": [ "headings", "headers", "blank_lines" ],
|
||||
"function": function MD022(params, onError) {
|
||||
var prevHeadingLineNumber = 0;
|
||||
var prevMaxLineIndex = -1;
|
||||
|
|
|
|||
12
lib/md023.js
12
lib/md023.js
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
var shared = require("./shared");
|
||||
|
||||
var spaceBeforeHeaderRe = /^\s+\S/;
|
||||
var spaceBeforeHeadingRe = /^\s+\S/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD023", "header-start-left" ],
|
||||
"description": "Headers must start at the beginning of the line",
|
||||
"tags": [ "headers", "spaces" ],
|
||||
"names": [ "MD023", "heading-start-left", "header-start-left" ],
|
||||
"description": "Headings must start at the beginning of the line",
|
||||
"tags": [ "headings", "headers", "spaces" ],
|
||||
"function": function MD023(params, onError) {
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (spaceBeforeHeaderRe.test(token.line)) {
|
||||
if (spaceBeforeHeadingRe.test(token.line)) {
|
||||
shared.addErrorContext(onError, token.lineNumber, token.line, null,
|
||||
null, shared.rangeFromRegExp(token.line, spaceBeforeHeaderRe));
|
||||
null, shared.rangeFromRegExp(token.line, spaceBeforeHeadingRe));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD024", "no-duplicate-header" ],
|
||||
"description": "Multiple headers with the same content",
|
||||
"tags": [ "headers" ],
|
||||
"names": [ "MD024", "no-duplicate-heading", "no-duplicate-header" ],
|
||||
"description": "Multiple headings with the same content",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD024(params, onError) {
|
||||
var knownContent = [];
|
||||
shared.forEachHeading(params, function forHeading(heading, content) {
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ var shared = require("./shared");
|
|||
|
||||
module.exports = {
|
||||
"names": [ "MD025", "single-h1" ],
|
||||
"description": "Multiple top level headers in the same document",
|
||||
"tags": [ "headers" ],
|
||||
"description": "Multiple top level headings in the same document",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD025(params, onError) {
|
||||
var level = params.config.level || 1;
|
||||
var tag = "h" + level;
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ var shared = require("./shared");
|
|||
|
||||
module.exports = {
|
||||
"names": [ "MD026", "no-trailing-punctuation" ],
|
||||
"description": "Trailing punctuation in header",
|
||||
"tags": [ "headers" ],
|
||||
"description": "Trailing punctuation in heading",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD026(params, onError) {
|
||||
var punctuation = params.config.punctuation || ".,;:!?";
|
||||
var trailingPunctuationRe = new RegExp("[" + punctuation + "]$");
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD036", "no-emphasis-as-header" ],
|
||||
"description": "Emphasis used instead of a header",
|
||||
"tags": [ "headers", "emphasis" ],
|
||||
"names": [ "MD036", "no-emphasis-as-heading", "no-emphasis-as-header" ],
|
||||
"description": "Emphasis used instead of a heading",
|
||||
"tags": [ "headings", "headers", "emphasis" ],
|
||||
"function": function MD036(params, onError) {
|
||||
var punctuation = params.config.punctuation || ".,;:!?";
|
||||
var re = new RegExp("[" + punctuation + "]$");
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ var shared = require("./shared");
|
|||
|
||||
module.exports = {
|
||||
"names": [ "MD041", "first-line-h1" ],
|
||||
"description": "First line in file should be a top level header",
|
||||
"tags": [ "headers" ],
|
||||
"description": "First line in file should be a top level heading",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD041(params, onError) {
|
||||
var level = params.config.level || 1;
|
||||
var frontMatterTitle = params.config.front_matter_title;
|
||||
|
|
|
|||
16
lib/md043.js
16
lib/md043.js
|
|
@ -5,12 +5,12 @@
|
|||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD043", "required-headers" ],
|
||||
"description": "Required header structure",
|
||||
"tags": [ "headers" ],
|
||||
"names": [ "MD043", "required-headings", "required-headers" ],
|
||||
"description": "Required heading structure",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD043(params, onError) {
|
||||
var requiredHeaders = params.config.headers;
|
||||
if (requiredHeaders) {
|
||||
var requiredHeadings = params.config.headings || params.config.headers;
|
||||
if (requiredHeadings) {
|
||||
var levels = {};
|
||||
[ 1, 2, 3, 4, 5, 6 ].forEach(function forLevel(level) {
|
||||
levels["h" + level] = "######".substr(-level);
|
||||
|
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
shared.forEachHeading(params, function forHeading(heading, content) {
|
||||
if (!errorCount) {
|
||||
var actual = levels[heading.tag] + " " + content;
|
||||
var expected = requiredHeaders[i++] || "[None]";
|
||||
var expected = requiredHeadings[i++] || "[None]";
|
||||
if (expected === "*") {
|
||||
optional = true;
|
||||
} else if (expected.toLowerCase() === actual.toLowerCase()) {
|
||||
|
|
@ -35,9 +35,9 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
});
|
||||
if ((i < requiredHeaders.length) && !errorCount) {
|
||||
if ((i < requiredHeadings.length) && !errorCount) {
|
||||
shared.addErrorContext(onError, params.lines.length,
|
||||
requiredHeaders[i]);
|
||||
requiredHeadings[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ var inlineCommentRe =
|
|||
module.exports.inlineCommentRe = inlineCommentRe;
|
||||
|
||||
// Regular expressions for range matching
|
||||
module.exports.atxHeaderSpaceRe = /^#+\s*\S/;
|
||||
module.exports.atxHeadingSpaceRe = /^#+\s*\S/;
|
||||
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s]*/i;
|
||||
module.exports.listItemMarkerRe = /^[\s>]*(?:[*+-]|\d+\.)\s+/;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue