mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-27 09:26:09 +01:00
Convert var to const/let (except in browser-only code).
This commit is contained in:
parent
78c1af7bfd
commit
213aef4564
56 changed files with 524 additions and 518 deletions
|
|
@ -2,29 +2,29 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var md = require("markdown-it")({ "html": true });
|
||||
var rules = require("./rules");
|
||||
var shared = require("./shared");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const md = require("markdown-it")({ "html": true });
|
||||
const rules = require("./rules");
|
||||
const shared = require("./shared");
|
||||
|
||||
// Validates the list of rules for structure and reuse
|
||||
function validateRuleList(ruleList) {
|
||||
var result = null;
|
||||
let result = null;
|
||||
if (ruleList.length === rules.length) {
|
||||
// No need to validate if only using built-in rules
|
||||
return result;
|
||||
}
|
||||
var allIds = {};
|
||||
const allIds = {};
|
||||
ruleList.forEach(function forRule(rule, index) {
|
||||
var customIndex = index - rules.length;
|
||||
const customIndex = index - rules.length;
|
||||
function newError(property) {
|
||||
return new Error(
|
||||
"Property '" + property + "' of custom rule at index " +
|
||||
customIndex + " is incorrect.");
|
||||
}
|
||||
[ "names", "tags" ].forEach(function forProperty(property) {
|
||||
var value = rule[property];
|
||||
const value = rule[property];
|
||||
if (!result &&
|
||||
(!value || !Array.isArray(value) || (value.length === 0) ||
|
||||
!value.every(shared.isString) || value.some(shared.isEmptyString))) {
|
||||
|
|
@ -35,15 +35,15 @@ function validateRuleList(ruleList) {
|
|||
[ "description", "string" ],
|
||||
[ "function", "function" ]
|
||||
].forEach(function forProperty(propertyInfo) {
|
||||
var property = propertyInfo[0];
|
||||
var value = rule[property];
|
||||
const property = propertyInfo[0];
|
||||
const value = rule[property];
|
||||
if (!result && (!value || (typeof value !== propertyInfo[1]))) {
|
||||
result = newError(property);
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
rule.names.forEach(function forName(name) {
|
||||
var nameUpper = name.toUpperCase();
|
||||
const nameUpper = name.toUpperCase();
|
||||
if (!result && (allIds[nameUpper] !== undefined)) {
|
||||
result = new Error("Name '" + name + "' of custom rule at index " +
|
||||
customIndex + " is already used as a name or tag.");
|
||||
|
|
@ -51,7 +51,7 @@ function validateRuleList(ruleList) {
|
|||
allIds[nameUpper] = true;
|
||||
});
|
||||
rule.tags.forEach(function forTag(tag) {
|
||||
var tagUpper = tag.toUpperCase();
|
||||
const tagUpper = tag.toUpperCase();
|
||||
if (!result && allIds[tagUpper]) {
|
||||
result = new Error("Tag '" + tag + "' of custom rule at index " +
|
||||
customIndex + " is already used as a name.");
|
||||
|
|
@ -67,14 +67,14 @@ function validateRuleList(ruleList) {
|
|||
function newResults(ruleList) {
|
||||
function Results() {}
|
||||
Results.prototype.toString = function resultsToString(useAlias) {
|
||||
var that = this;
|
||||
var ruleNameToRule = null;
|
||||
var results = [];
|
||||
const that = this;
|
||||
let ruleNameToRule = null;
|
||||
const results = [];
|
||||
Object.keys(that).forEach(function forFile(file) {
|
||||
var fileResults = that[file];
|
||||
const fileResults = that[file];
|
||||
if (Array.isArray(fileResults)) {
|
||||
fileResults.forEach(function forResult(result) {
|
||||
var ruleMoniker = result.ruleNames ?
|
||||
const ruleMoniker = result.ruleNames ?
|
||||
result.ruleNames.join("/") :
|
||||
(result.ruleName + "/" + result.ruleAlias);
|
||||
results.push(
|
||||
|
|
@ -93,16 +93,16 @@ function newResults(ruleList) {
|
|||
if (!ruleNameToRule) {
|
||||
ruleNameToRule = {};
|
||||
ruleList.forEach(function forRule(rule) {
|
||||
var ruleName = rule.names[0].toUpperCase();
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
ruleNameToRule[ruleName] = rule;
|
||||
});
|
||||
}
|
||||
Object.keys(fileResults).forEach(function forRule(ruleName) {
|
||||
var rule = ruleNameToRule[ruleName.toUpperCase()];
|
||||
var ruleResults = fileResults[ruleName];
|
||||
const rule = ruleNameToRule[ruleName.toUpperCase()];
|
||||
const ruleResults = fileResults[ruleName];
|
||||
ruleResults.forEach(function forLine(lineNumber) {
|
||||
var nameIndex = Math.min(useAlias ? 1 : 0, rule.names.length - 1);
|
||||
var result =
|
||||
const nameIndex = Math.min(useAlias ? 1 : 0, rule.names.length - 1);
|
||||
const result =
|
||||
file + ": " +
|
||||
lineNumber + ": " +
|
||||
rule.names[nameIndex] + " " +
|
||||
|
|
@ -119,11 +119,11 @@ function newResults(ruleList) {
|
|||
|
||||
// Remove front matter (if present at beginning of content)
|
||||
function removeFrontMatter(content, frontMatter) {
|
||||
var frontMatterLines = [];
|
||||
let frontMatterLines = [];
|
||||
if (frontMatter) {
|
||||
var frontMatterMatch = content.match(frontMatter);
|
||||
const frontMatterMatch = content.match(frontMatter);
|
||||
if (frontMatterMatch && !frontMatterMatch.index) {
|
||||
var contentMatched = frontMatterMatch[0];
|
||||
const contentMatched = frontMatterMatch[0];
|
||||
content = content.slice(contentMatched.length);
|
||||
frontMatterLines = contentMatched.split(shared.newLineRe);
|
||||
if (frontMatterLines.length &&
|
||||
|
|
@ -140,7 +140,7 @@ function removeFrontMatter(content, frontMatter) {
|
|||
|
||||
// Annotate tokens with line/lineNumber
|
||||
function annotateTokens(tokens, lines) {
|
||||
var tbodyMap = null;
|
||||
let tbodyMap = null;
|
||||
tokens.forEach(function forToken(token) {
|
||||
// Handle missing maps for table body
|
||||
if (token.type === "tbody_open") {
|
||||
|
|
@ -162,7 +162,7 @@ function annotateTokens(tokens, lines) {
|
|||
token.map[1]--;
|
||||
}
|
||||
// Annotate children with lineNumber
|
||||
var lineNumber = token.lineNumber;
|
||||
let lineNumber = token.lineNumber;
|
||||
(token.children || []).forEach(function forChild(child) {
|
||||
child.lineNumber = lineNumber;
|
||||
child.line = lines[lineNumber - 1];
|
||||
|
|
@ -176,21 +176,21 @@ function annotateTokens(tokens, lines) {
|
|||
|
||||
// Map rule names/tags to canonical rule name
|
||||
function mapAliasToRuleNames(ruleList) {
|
||||
var aliasToRuleNames = {};
|
||||
// var tagToRuleNames = {};
|
||||
const aliasToRuleNames = {};
|
||||
// const tagToRuleNames = {};
|
||||
ruleList.forEach(function forRule(rule) {
|
||||
var ruleName = rule.names[0].toUpperCase();
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
// The following is useful for updating README.md:
|
||||
// console.log(
|
||||
// "* **[" + ruleName + "](doc/Rules.md#" + ruleName.toLowerCase() +
|
||||
// ")** *" + rule.names.slice(1).join("/") + "* - " + rule.description);
|
||||
rule.names.forEach(function forName(name) {
|
||||
var nameUpper = name.toUpperCase();
|
||||
const nameUpper = name.toUpperCase();
|
||||
aliasToRuleNames[nameUpper] = [ ruleName ];
|
||||
});
|
||||
rule.tags.forEach(function forTag(tag) {
|
||||
var tagUpper = tag.toUpperCase();
|
||||
var ruleNames = aliasToRuleNames[tagUpper] || [];
|
||||
const tagUpper = tag.toUpperCase();
|
||||
const ruleNames = aliasToRuleNames[tagUpper] || [];
|
||||
ruleNames.push(ruleName);
|
||||
aliasToRuleNames[tagUpper] = ruleNames;
|
||||
// tagToRuleNames[tag] = ruleName;
|
||||
|
|
@ -206,17 +206,17 @@ function mapAliasToRuleNames(ruleList) {
|
|||
|
||||
// Apply (and normalize) config
|
||||
function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
||||
var defaultKey = Object.keys(config).filter(function forKey(key) {
|
||||
const defaultKey = Object.keys(config).filter(function forKey(key) {
|
||||
return key.toUpperCase() === "DEFAULT";
|
||||
});
|
||||
var ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]];
|
||||
var effectiveConfig = {};
|
||||
const ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]];
|
||||
const effectiveConfig = {};
|
||||
ruleList.forEach(function forRule(rule) {
|
||||
var ruleName = rule.names[0].toUpperCase();
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
effectiveConfig[ruleName] = ruleDefault;
|
||||
});
|
||||
Object.keys(config).forEach(function forKey(key) {
|
||||
var value = config[key];
|
||||
let value = config[key];
|
||||
if (value) {
|
||||
if (!(value instanceof Object)) {
|
||||
value = {};
|
||||
|
|
@ -224,7 +224,7 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
|||
} else {
|
||||
value = false;
|
||||
}
|
||||
var keyUpper = key.toUpperCase();
|
||||
const keyUpper = key.toUpperCase();
|
||||
(aliasToRuleNames[keyUpper] || []).forEach(function forRule(ruleName) {
|
||||
effectiveConfig[ruleName] = value;
|
||||
});
|
||||
|
|
@ -236,16 +236,16 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
|||
function getEnabledRulesPerLineNumber(
|
||||
ruleList, lines, frontMatterLines, noInlineConfig,
|
||||
effectiveConfig, aliasToRuleNames) {
|
||||
var enabledRules = {};
|
||||
var allRuleNames = [];
|
||||
let enabledRules = {};
|
||||
const allRuleNames = [];
|
||||
ruleList.forEach(function forRule(rule) {
|
||||
var ruleName = rule.names[0].toUpperCase();
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
allRuleNames.push(ruleName);
|
||||
enabledRules[ruleName] = !!effectiveConfig[ruleName];
|
||||
});
|
||||
function forMatch(match) {
|
||||
var enabled = match[1].toUpperCase() === "EN";
|
||||
var items = match[2] ?
|
||||
const enabled = match[1].toUpperCase() === "EN";
|
||||
const items = match[2] ?
|
||||
match[2].trim().toUpperCase().split(/\s+/) :
|
||||
allRuleNames;
|
||||
items.forEach(function forItem(nameUpper) {
|
||||
|
|
@ -254,10 +254,10 @@ function getEnabledRulesPerLineNumber(
|
|||
});
|
||||
});
|
||||
}
|
||||
var enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length);
|
||||
const enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length);
|
||||
lines.forEach(function forLine(line) {
|
||||
if (!noInlineConfig) {
|
||||
var match = shared.inlineCommentRe.exec(line);
|
||||
let match = shared.inlineCommentRe.exec(line);
|
||||
if (match) {
|
||||
enabledRules = shared.clone(enabledRules);
|
||||
while (match) {
|
||||
|
|
@ -288,38 +288,39 @@ function lintContent(
|
|||
// Remove UTF-8 byte order marker (if present)
|
||||
content = content.replace(/^\ufeff/, "");
|
||||
// Remove front matter
|
||||
var removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
||||
var frontMatterLines = removeFrontMatterResult.frontMatterLines;
|
||||
const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
||||
const frontMatterLines = removeFrontMatterResult.frontMatterLines;
|
||||
// Ignore the content of HTML comments
|
||||
content = shared.clearHtmlCommentText(removeFrontMatterResult.content);
|
||||
// Parse content into tokens and lines
|
||||
var tokens = md.parse(content, {});
|
||||
var lines = content.split(shared.newLineRe);
|
||||
const tokens = md.parse(content, {});
|
||||
const lines = content.split(shared.newLineRe);
|
||||
annotateTokens(tokens, lines);
|
||||
var aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
||||
var effectiveConfig = getEffectiveConfig(ruleList, config, aliasToRuleNames);
|
||||
var enabledRulesPerLineNumber = getEnabledRulesPerLineNumber(
|
||||
const aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
||||
const effectiveConfig =
|
||||
getEffectiveConfig(ruleList, config, aliasToRuleNames);
|
||||
const enabledRulesPerLineNumber = getEnabledRulesPerLineNumber(
|
||||
ruleList, lines, frontMatterLines, noInlineConfig,
|
||||
effectiveConfig, aliasToRuleNames);
|
||||
// Create parameters for rules
|
||||
var params = {
|
||||
const params = {
|
||||
"tokens": tokens,
|
||||
"lines": lines,
|
||||
"frontMatterLines": frontMatterLines
|
||||
};
|
||||
shared.makeTokenCache(params);
|
||||
// Function to run for each rule
|
||||
var result = (resultVersion === 0) ? {} : [];
|
||||
const result = (resultVersion === 0) ? {} : [];
|
||||
function forRule(rule) {
|
||||
// Configure rule
|
||||
var ruleNameFriendly = rule.names[0];
|
||||
var ruleName = ruleNameFriendly.toUpperCase();
|
||||
const ruleNameFriendly = rule.names[0];
|
||||
const ruleName = ruleNameFriendly.toUpperCase();
|
||||
params.config = effectiveConfig[ruleName];
|
||||
function throwError(property) {
|
||||
throw new Error(
|
||||
"Property '" + property + "' of onError parameter is incorrect.");
|
||||
}
|
||||
var errors = [];
|
||||
const errors = [];
|
||||
function onError(errorInfo) {
|
||||
if (!errorInfo ||
|
||||
!errorInfo.lineNumber ||
|
||||
|
|
@ -353,7 +354,7 @@ function lintContent(
|
|||
// Record any errors (significant performance benefit from length check)
|
||||
if (errors.length) {
|
||||
errors.sort(lineNumberComparison);
|
||||
var filteredErrors = errors
|
||||
const filteredErrors = errors
|
||||
.filter(uniqueFilterForSortedErrors)
|
||||
.filter(function removeDisabledRules(error) {
|
||||
return enabledRulesPerLineNumber[error.lineNumber][ruleName];
|
||||
|
|
@ -362,7 +363,7 @@ function lintContent(
|
|||
if (resultVersion === 0) {
|
||||
return error.lineNumber;
|
||||
}
|
||||
var errorObject = {};
|
||||
const errorObject = {};
|
||||
errorObject.lineNumber = error.lineNumber;
|
||||
if (resultVersion === 1) {
|
||||
errorObject.ruleName = ruleNameFriendly;
|
||||
|
|
@ -425,30 +426,30 @@ function lintInput(options, synchronous, callback) {
|
|||
// Normalize inputs
|
||||
options = options || {};
|
||||
callback = callback || function noop() {};
|
||||
var ruleList = rules.concat(options.customRules || []);
|
||||
var ruleErr = validateRuleList(ruleList);
|
||||
const ruleList = rules.concat(options.customRules || []);
|
||||
const ruleErr = validateRuleList(ruleList);
|
||||
if (ruleErr) {
|
||||
return callback(ruleErr);
|
||||
}
|
||||
var files = [];
|
||||
let files = [];
|
||||
if (Array.isArray(options.files)) {
|
||||
files = options.files.slice();
|
||||
} else if (options.files) {
|
||||
files = [ String(options.files) ];
|
||||
}
|
||||
var strings = options.strings || {};
|
||||
var stringsKeys = Object.keys(strings);
|
||||
var config = options.config || { "default": true };
|
||||
var frontMatter = (options.frontMatter === undefined) ?
|
||||
const strings = options.strings || {};
|
||||
const stringsKeys = Object.keys(strings);
|
||||
const config = options.config || { "default": true };
|
||||
const frontMatter = (options.frontMatter === undefined) ?
|
||||
shared.frontMatterRe : options.frontMatter;
|
||||
var noInlineConfig = !!options.noInlineConfig;
|
||||
var resultVersion = (options.resultVersion === undefined) ?
|
||||
const noInlineConfig = !!options.noInlineConfig;
|
||||
const resultVersion = (options.resultVersion === undefined) ?
|
||||
2 : options.resultVersion;
|
||||
var results = newResults(ruleList);
|
||||
const results = newResults(ruleList);
|
||||
// Helper to lint the next string or file
|
||||
function lintNextItem() {
|
||||
var iterating = true;
|
||||
var item = null;
|
||||
let iterating = true;
|
||||
let item = null;
|
||||
function lintNextItemCallback(err, result) {
|
||||
if (err) {
|
||||
iterating = false;
|
||||
|
|
@ -506,7 +507,7 @@ function markdownlint(options, callback) {
|
|||
* @returns {Object} Result object.
|
||||
*/
|
||||
function markdownlintSync(options) {
|
||||
var results = null;
|
||||
let results = null;
|
||||
lintInput(options, true, function callback(error, res) {
|
||||
if (error) {
|
||||
throw error;
|
||||
|
|
@ -530,7 +531,7 @@ function readConfig(file, callback) {
|
|||
return callback(err);
|
||||
}
|
||||
// Parse file
|
||||
var config = null;
|
||||
let config = null;
|
||||
try {
|
||||
config = JSON.parse(content);
|
||||
} catch (ex) {
|
||||
|
|
@ -538,7 +539,7 @@ function readConfig(file, callback) {
|
|||
}
|
||||
if (config.extends) {
|
||||
// Extend configuration
|
||||
var extendsFile = path.resolve(path.dirname(file), config.extends);
|
||||
const extendsFile = path.resolve(path.dirname(file), config.extends);
|
||||
readConfig(extendsFile, function handleConfig(errr, extendsConfig) {
|
||||
if (errr) {
|
||||
return callback(errr);
|
||||
|
|
@ -560,7 +561,7 @@ function readConfig(file, callback) {
|
|||
*/
|
||||
function readConfigSync(file) {
|
||||
// Parse file
|
||||
var config = JSON.parse(fs.readFileSync(file, shared.utf8Encoding));
|
||||
let config = JSON.parse(fs.readFileSync(file, shared.utf8Encoding));
|
||||
if (config.extends) {
|
||||
// Extend configuration
|
||||
config = shared.assign(
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"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;
|
||||
let prevLevel = 0;
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
var level = parseInt(token.tag.slice(1), 10);
|
||||
const level = parseInt(token.tag.slice(1), 10);
|
||||
if (prevLevel && (level > prevLevel)) {
|
||||
shared.addErrorDetailIf(onError, token.lineNumber,
|
||||
"h" + (prevLevel + 1), "h" + level);
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"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;
|
||||
const level = params.config.level || 1;
|
||||
const tag = "h" + level;
|
||||
params.tokens.every(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
shared.addErrorDetailIf(onError, token.lineNumber, tag, token.tag);
|
||||
|
|
|
|||
14
lib/md003.js
14
lib/md003.js
|
|
@ -2,31 +2,31 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD003", "heading-style", "header-style" ],
|
||||
"description": "Heading style",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD003(params, onError) {
|
||||
var style = params.config.style || "consistent";
|
||||
let style = params.config.style || "consistent";
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
var styleForToken = shared.headingStyleFor(token);
|
||||
const styleForToken = shared.headingStyleFor(token);
|
||||
if (style === "consistent") {
|
||||
style = styleForToken;
|
||||
}
|
||||
if (styleForToken !== style) {
|
||||
var h12 = /h[12]/.test(token.tag);
|
||||
var setextWithAtx =
|
||||
const h12 = /h[12]/.test(token.tag);
|
||||
const setextWithAtx =
|
||||
(style === "setext_with_atx") &&
|
||||
((h12 && (styleForToken === "setext")) ||
|
||||
(!h12 && (styleForToken === "atx")));
|
||||
var setextWithAtxClosed =
|
||||
const setextWithAtxClosed =
|
||||
(style === "setext_with_atx_closed") &&
|
||||
((h12 && (styleForToken === "setext")) ||
|
||||
(!h12 && (styleForToken === "atx_closed")));
|
||||
if (!setextWithAtx && !setextWithAtxClosed) {
|
||||
var expected = style;
|
||||
let expected = style;
|
||||
if (style === "setext_with_atx") {
|
||||
expected = h12 ? "setext" : "atx";
|
||||
} else if (style === "setext_with_atx_closed") {
|
||||
|
|
|
|||
12
lib/md004.js
12
lib/md004.js
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
// Returns the unordered list style for a list item token
|
||||
function unorderedListStyleFor(token) {
|
||||
|
|
@ -22,18 +22,18 @@ module.exports = {
|
|||
"description": "Unordered list style",
|
||||
"tags": [ "bullet", "ul" ],
|
||||
"function": function MD004(params, onError) {
|
||||
var style = params.config.style || "consistent";
|
||||
var expectedStyle = style;
|
||||
var nestingStyles = [];
|
||||
const style = params.config.style || "consistent";
|
||||
let expectedStyle = style;
|
||||
const nestingStyles = [];
|
||||
shared.flattenLists().forEach(function forList(list) {
|
||||
if (list.unordered) {
|
||||
if (expectedStyle === "consistent") {
|
||||
expectedStyle = unorderedListStyleFor(list.items[0]);
|
||||
}
|
||||
list.items.forEach(function forItem(item) {
|
||||
var itemStyle = unorderedListStyleFor(item);
|
||||
const itemStyle = unorderedListStyleFor(item);
|
||||
if (style === "sublist") {
|
||||
var nesting = list.nesting;
|
||||
const nesting = list.nesting;
|
||||
if (!nestingStyles[nesting] &&
|
||||
(itemStyle !== nestingStyles[nesting - 1])) {
|
||||
nestingStyles[nesting] = itemStyle;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD005", "list-indent" ],
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD006", "ul-start-left" ],
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD007", "ul-indent" ],
|
||||
"description": "Unordered list indentation",
|
||||
"tags": [ "bullet", "ul", "indentation" ],
|
||||
"function": function MD007(params, onError) {
|
||||
var optionsIndent = params.config.indent || 2;
|
||||
const optionsIndent = params.config.indent || 2;
|
||||
shared.flattenLists().forEach(function forList(list) {
|
||||
if (list.unordered && list.parentsUnordered && list.indent) {
|
||||
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
||||
|
|
|
|||
18
lib/md009.js
18
lib/md009.js
|
|
@ -2,32 +2,32 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var trailingSpaceRe = /\s+$/;
|
||||
const trailingSpaceRe = /\s+$/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD009", "no-trailing-spaces" ],
|
||||
"description": "Trailing spaces",
|
||||
"tags": [ "whitespace" ],
|
||||
"function": function MD009(params, onError) {
|
||||
var brSpaces = params.config.br_spaces || 0;
|
||||
var listItemEmptyLines = params.config.list_item_empty_lines;
|
||||
var allowListItemEmptyLines =
|
||||
const brSpaces = params.config.br_spaces || 0;
|
||||
const listItemEmptyLines = params.config.list_item_empty_lines;
|
||||
const allowListItemEmptyLines =
|
||||
(listItemEmptyLines === undefined) ? false : !!listItemEmptyLines;
|
||||
var listItemLineNumbers = [];
|
||||
const listItemLineNumbers = [];
|
||||
if (allowListItemEmptyLines) {
|
||||
shared.filterTokens(params, "list_item_open", function forToken(token) {
|
||||
for (var i = token.map[0]; i < token.map[1]; i++) {
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
listItemLineNumbers.push(i + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
shared.forEachLine(function forLine(line, lineIndex) {
|
||||
var lineNumber = lineIndex + 1;
|
||||
const lineNumber = lineIndex + 1;
|
||||
if (trailingSpaceRe.test(line) &&
|
||||
(listItemLineNumbers.indexOf(lineNumber) === -1)) {
|
||||
var expected = (brSpaces < 2) ? 0 : brSpaces;
|
||||
const expected = (brSpaces < 2) ? 0 : brSpaces;
|
||||
shared.addErrorDetailIf(onError, lineNumber,
|
||||
expected, line.length - shared.trimRight(line).length, null,
|
||||
shared.rangeFromRegExp(line, trailingSpaceRe));
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var tabRe = /\t+/;
|
||||
const tabRe = /\t+/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD010", "no-hard-tabs" ],
|
||||
"description": "Hard tabs",
|
||||
"tags": [ "whitespace", "hard_tab" ],
|
||||
"function": function MD010(params, onError) {
|
||||
var codeBlocks = params.config.code_blocks;
|
||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
const codeBlocks = params.config.code_blocks;
|
||||
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
shared.forEachLine(function forLine(line, lineIndex, inCode) {
|
||||
if (tabRe.test(line) && (!inCode || includeCodeBlocks)) {
|
||||
shared.addError(onError, lineIndex + 1,
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var reversedLinkRe = /\([^)]+\)\[[^\]^][^\]]*]/;
|
||||
const reversedLinkRe = /\([^)]+\)\[[^\]^][^\]]*]/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD011", "no-reversed-links" ],
|
||||
|
|
@ -12,7 +12,7 @@ module.exports = {
|
|||
"tags": [ "links" ],
|
||||
"function": function MD011(params, onError) {
|
||||
shared.forEachInlineChild(params, "text", function forToken(token) {
|
||||
var match = reversedLinkRe.exec(token.content);
|
||||
const match = reversedLinkRe.exec(token.content);
|
||||
if (match) {
|
||||
shared.addError(onError, token.lineNumber, match[0], null,
|
||||
shared.rangeFromRegExp(token.line, reversedLinkRe));
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD012", "no-multiple-blanks" ],
|
||||
"description": "Multiple consecutive blank lines",
|
||||
"tags": [ "whitespace", "blank_lines" ],
|
||||
"function": function MD012(params, onError) {
|
||||
var maximum = params.config.maximum || 1;
|
||||
var count = 0;
|
||||
const maximum = params.config.maximum || 1;
|
||||
let count = 0;
|
||||
shared.forEachLine(function forLine(line, lineIndex, inCode) {
|
||||
count = (inCode || line.trim().length) ? 0 : count + 1;
|
||||
if (maximum < count) {
|
||||
|
|
|
|||
30
lib/md013.js
30
lib/md013.js
|
|
@ -2,32 +2,32 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var labelRe = /^\s*\[.*[^\\]]:/;
|
||||
const 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 headings = params.config.headings;
|
||||
const lineLength = params.config.line_length || 80;
|
||||
const codeBlocks = params.config.code_blocks;
|
||||
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
const tables = params.config.tables;
|
||||
const includeTables = (tables === undefined) ? true : !!tables;
|
||||
let headings = params.config.headings;
|
||||
if (headings === undefined) {
|
||||
headings = params.config.headers;
|
||||
}
|
||||
var includeHeadings = (headings === undefined) ? true : !!headings;
|
||||
var headingLineNumbers = [];
|
||||
const includeHeadings = (headings === undefined) ? true : !!headings;
|
||||
const headingLineNumbers = [];
|
||||
if (!includeHeadings) {
|
||||
shared.forEachHeading(params, function forHeading(heading) {
|
||||
headingLineNumbers.push(heading.lineNumber);
|
||||
});
|
||||
}
|
||||
var tokenTypeMap = {
|
||||
const tokenTypeMap = {
|
||||
"em_open": "e",
|
||||
"em_close": "E",
|
||||
"link_open": "l",
|
||||
|
|
@ -36,9 +36,9 @@ module.exports = {
|
|||
"strong_close": "S",
|
||||
"text": "T"
|
||||
};
|
||||
var linkOnlyLineNumbers = [];
|
||||
const linkOnlyLineNumbers = [];
|
||||
shared.filterTokens(params, "inline", function forToken(token) {
|
||||
var childTokenTypes = "";
|
||||
let childTokenTypes = "";
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type !== "text" || child.content !== "") {
|
||||
childTokenTypes += tokenTypeMap[child.type] || "x";
|
||||
|
|
@ -48,10 +48,10 @@ module.exports = {
|
|||
linkOnlyLineNumbers.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
var longLineRe = new RegExp("^(.{" + lineLength + "})(.*\\s.*)$");
|
||||
const longLineRe = new RegExp("^(.{" + lineLength + "})(.*\\s.*)$");
|
||||
shared.forEachLine(
|
||||
function forLine(line, lineIndex, inCode, onFence, inTable) {
|
||||
var lineNumber = lineIndex + 1;
|
||||
const lineNumber = lineIndex + 1;
|
||||
if ((includeCodeBlocks || !inCode) &&
|
||||
(includeTables || !inTable) &&
|
||||
(includeHeadings || (headingLineNumbers.indexOf(lineNumber)) < 0) &&
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var dollarCommandRe = /^(\s*)(\$\s)/;
|
||||
const dollarCommandRe = /^(\s*)(\$\s)/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD014", "commands-show-output" ],
|
||||
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
"function": function MD014(params, onError) {
|
||||
[ "code_block", "fence" ].forEach(function forType(type) {
|
||||
shared.filterTokens(params, type, function forToken(token) {
|
||||
var allBlank = true;
|
||||
let allBlank = true;
|
||||
if (token.content && token.content.split(shared.newLineRe)
|
||||
.every(function forLine(line) {
|
||||
return !line || (allBlank = false) || dollarCommandRe.test(line);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD018", "no-missing-space-atx" ],
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD019", "no-multiple-space-atx" ],
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var atxClosedHeadingNoSpaceRe = /(?:^#+[^#\s])|(?:[^#\s]#+\s*$)/;
|
||||
const atxClosedHeadingNoSpaceRe = /(?:^#+[^#\s])|(?:[^#\s]#+\s*$)/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD020", "no-missing-space-closed-atx" ],
|
||||
|
|
@ -13,8 +13,8 @@ module.exports = {
|
|||
"function": function MD020(params, onError) {
|
||||
shared.forEachLine(function forLine(line, lineIndex, inCode) {
|
||||
if (!inCode && /^#+[^#]*[^\\]#+$/.test(line)) {
|
||||
var left = /^#+[^#\s]/.test(line);
|
||||
var right = /[^#\s]#+$/.test(line);
|
||||
const left = /^#+[^#\s]/.test(line);
|
||||
const right = /[^#\s]#+$/.test(line);
|
||||
if (left || right) {
|
||||
shared.addErrorContext(onError, lineIndex + 1, line.trim(), left,
|
||||
right, shared.rangeFromRegExp(line, atxClosedHeadingNoSpaceRe));
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var atxClosedHeadingSpaceRe = /(?:^#+\s\s+?\S)|(?:\S\s\s+?#+\s*$)/;
|
||||
const atxClosedHeadingSpaceRe = /(?:^#+\s\s+?\S)|(?:\S\s\s+?#+\s*$)/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD021", "no-multiple-space-closed-atx" ],
|
||||
|
|
@ -13,8 +13,8 @@ module.exports = {
|
|||
"function": function MD021(params, onError) {
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (shared.headingStyleFor(token) === "atx_closed") {
|
||||
var left = /^#+\s\s/.test(token.line);
|
||||
var right = /\s\s#+$/.test(token.line);
|
||||
const left = /^#+\s\s/.test(token.line);
|
||||
const right = /\s\s#+$/.test(token.line);
|
||||
if (left || right) {
|
||||
shared.addErrorContext(onError, token.lineNumber, token.line.trim(),
|
||||
left, right,
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"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;
|
||||
var needBlankLine = false;
|
||||
let prevHeadingLineNumber = 0;
|
||||
let prevMaxLineIndex = -1;
|
||||
let needBlankLine = false;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
if ((token.map[0] - prevMaxLineIndex) === 0) {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var spaceBeforeHeadingRe = /^\s+\S/;
|
||||
const spaceBeforeHeadingRe = /^\s+\S/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD023", "heading-start-left", "header-start-left" ],
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"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 = [];
|
||||
const knownContent = [];
|
||||
shared.forEachHeading(params, function forHeading(heading, content) {
|
||||
if (knownContent.indexOf(content) === -1) {
|
||||
knownContent.push(content);
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD025", "single-h1" ],
|
||||
"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;
|
||||
var hasTopLevelHeading = false;
|
||||
const level = params.config.level || 1;
|
||||
const tag = "h" + level;
|
||||
let hasTopLevelHeading = false;
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (token.tag === tag) {
|
||||
if (hasTopLevelHeading) {
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD026", "no-trailing-punctuation" ],
|
||||
"description": "Trailing punctuation in heading",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD026(params, onError) {
|
||||
var punctuation = params.config.punctuation || ".,;:!?";
|
||||
var trailingPunctuationRe = new RegExp("[" + punctuation + "]$");
|
||||
const punctuation = params.config.punctuation || ".,;:!?";
|
||||
const trailingPunctuationRe = new RegExp("[" + punctuation + "]$");
|
||||
shared.forEachHeading(params, function forHeading(heading, content) {
|
||||
var match = trailingPunctuationRe.exec(content);
|
||||
const match = trailingPunctuationRe.exec(content);
|
||||
if (match) {
|
||||
shared.addError(onError, heading.lineNumber,
|
||||
"Punctuation: '" + match[0] + "'", null,
|
||||
|
|
|
|||
10
lib/md027.js
10
lib/md027.js
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var spaceAfterBlockQuote = /^\s*(?:>\s+)+\S/;
|
||||
const spaceAfterBlockQuote = /^\s*(?:>\s+)+\S/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
||||
"description": "Multiple spaces after blockquote symbol",
|
||||
"tags": [ "blockquote", "whitespace", "indentation" ],
|
||||
"function": function MD027(params, onError) {
|
||||
var blockquoteNesting = 0;
|
||||
var listItemNesting = 0;
|
||||
let blockquoteNesting = 0;
|
||||
let listItemNesting = 0;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if (token.type === "blockquote_open") {
|
||||
blockquoteNesting++;
|
||||
|
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
} else if (token.type === "list_item_close") {
|
||||
listItemNesting--;
|
||||
} else if ((token.type === "inline") && (blockquoteNesting > 0)) {
|
||||
var multipleSpaces = listItemNesting ?
|
||||
const multipleSpaces = listItemNesting ?
|
||||
/^(\s*>)+\s\s+>/.test(token.line) :
|
||||
/^(\s*>)+\s\s/.test(token.line);
|
||||
if (multipleSpaces) {
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD028", "no-blanks-blockquote" ],
|
||||
"description": "Blank line inside blockquote",
|
||||
"tags": [ "blockquote", "whitespace" ],
|
||||
"function": function MD028(params, onError) {
|
||||
var prevToken = {};
|
||||
let prevToken = {};
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if ((token.type === "blockquote_open") &&
|
||||
(prevToken.type === "blockquote_close")) {
|
||||
|
|
|
|||
14
lib/md029.js
14
lib/md029.js
|
|
@ -2,27 +2,27 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var numberRe = /^[\s>]*([^.)]*)[.)]/;
|
||||
const numberRe = /^[\s>]*([^.)]*)[.)]/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD029", "ol-prefix" ],
|
||||
"description": "Ordered list item prefix",
|
||||
"tags": [ "ol" ],
|
||||
"function": function MD029(params, onError) {
|
||||
var style = params.config.style || "one_or_ordered";
|
||||
const style = params.config.style || "one_or_ordered";
|
||||
shared.flattenLists().forEach(function forList(list) {
|
||||
if (!list.unordered) {
|
||||
var listStyle = style;
|
||||
let listStyle = style;
|
||||
if (listStyle === "one_or_ordered") {
|
||||
var second = (list.items.length > 1) &&
|
||||
const second = (list.items.length > 1) &&
|
||||
numberRe.exec(list.items[1].line);
|
||||
listStyle = (second && (second[1] !== "1")) ? "ordered" : "one";
|
||||
}
|
||||
var number = 1;
|
||||
let number = 1;
|
||||
list.items.forEach(function forItem(item) {
|
||||
var match = numberRe.exec(item.line);
|
||||
const match = numberRe.exec(item.line);
|
||||
shared.addErrorDetailIf(onError, item.lineNumber,
|
||||
String(number), !match || match[1],
|
||||
"Style: " + (listStyle === "one" ? "1/1/1" : "1/2/3"),
|
||||
|
|
|
|||
18
lib/md030.js
18
lib/md030.js
|
|
@ -2,25 +2,25 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD030", "list-marker-space" ],
|
||||
"description": "Spaces after list markers",
|
||||
"tags": [ "ol", "ul", "whitespace" ],
|
||||
"function": function MD030(params, onError) {
|
||||
var ulSingle = params.config.ul_single || 1;
|
||||
var olSingle = params.config.ol_single || 1;
|
||||
var ulMulti = params.config.ul_multi || 1;
|
||||
var olMulti = params.config.ol_multi || 1;
|
||||
const ulSingle = params.config.ul_single || 1;
|
||||
const olSingle = params.config.ol_single || 1;
|
||||
const ulMulti = params.config.ul_multi || 1;
|
||||
const olMulti = params.config.ol_multi || 1;
|
||||
shared.flattenLists().forEach(function forList(list) {
|
||||
var lineCount = list.lastLineIndex - list.open.map[0];
|
||||
var allSingle = lineCount === list.items.length;
|
||||
var expectedSpaces = list.unordered ?
|
||||
const lineCount = list.lastLineIndex - list.open.map[0];
|
||||
const allSingle = lineCount === list.items.length;
|
||||
const expectedSpaces = list.unordered ?
|
||||
(allSingle ? ulSingle : ulMulti) :
|
||||
(allSingle ? olSingle : olMulti);
|
||||
list.items.forEach(function forItem(item) {
|
||||
var match = /^[\s>]*\S+(\s+)/.exec(item.line);
|
||||
const match = /^[\s>]*\S+(\s+)/.exec(item.line);
|
||||
shared.addErrorDetailIf(onError, item.lineNumber,
|
||||
expectedSpaces, (match ? match[1].length : 0), null,
|
||||
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD031", "blanks-around-fences" ],
|
||||
"description": "Fenced code blocks should be surrounded by blank lines",
|
||||
"tags": [ "code", "blank_lines" ],
|
||||
"function": function MD031(params, onError) {
|
||||
var lines = params.lines;
|
||||
const lines = params.lines;
|
||||
shared.forEachLine(function forLine(line, i, inCode, onFence) {
|
||||
if (((onFence > 0) && (i - 1 >= 0) && lines[i - 1].length) ||
|
||||
((onFence < 0) && (i + 1 < lines.length) && lines[i + 1].length)) {
|
||||
|
|
|
|||
14
lib/md032.js
14
lib/md032.js
|
|
@ -2,23 +2,23 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var listItemMarkerInterruptsRe = /^[\s>]*(?:[*+-]|1\.)\s+/;
|
||||
var blankOrListRe = /^[\s>]*($|\s)/;
|
||||
const listItemMarkerInterruptsRe = /^[\s>]*(?:[*+-]|1\.)\s+/;
|
||||
const blankOrListRe = /^[\s>]*($|\s)/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD032", "blanks-around-lists" ],
|
||||
"description": "Lists should be surrounded by blank lines",
|
||||
"tags": [ "bullet", "ul", "ol", "blank_lines" ],
|
||||
"function": function MD032(params, onError) {
|
||||
var inList = false;
|
||||
var prevLine = "";
|
||||
let inList = false;
|
||||
let prevLine = "";
|
||||
shared.forEachLine(
|
||||
function forLine(line, lineIndex, inCode, onFence) {
|
||||
if (!inCode || onFence) {
|
||||
var lineTrim = line.trim();
|
||||
var listMarker = shared.listItemMarkerRe.test(lineTrim);
|
||||
const lineTrim = line.trim();
|
||||
let listMarker = shared.listItemMarkerRe.test(lineTrim);
|
||||
if (listMarker && !inList && !blankOrListRe.test(prevLine)) {
|
||||
// Check whether this list prefix can interrupt a paragraph
|
||||
if (listItemMarkerInterruptsRe.test(lineTrim)) {
|
||||
|
|
|
|||
|
|
@ -2,23 +2,23 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var htmlRe = /<[^>]*>/;
|
||||
const htmlRe = /<[^>]*>/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD033", "no-inline-html" ],
|
||||
"description": "Inline HTML",
|
||||
"tags": [ "html" ],
|
||||
"function": function MD033(params, onError) {
|
||||
var allowedElements = (params.config.allowed_elements || [])
|
||||
const allowedElements = (params.config.allowed_elements || [])
|
||||
.map(function forElement(element) {
|
||||
return element.toLowerCase();
|
||||
});
|
||||
function forToken(token) {
|
||||
token.content.split(shared.newLineRe)
|
||||
.forEach(function forLine(line, offset) {
|
||||
var allowed = (line.match(/<[^/\s>!]*/g) || [])
|
||||
const allowed = (line.match(/<[^/\s>!]*/g) || [])
|
||||
.filter(function forElement(element) {
|
||||
return element.length > 1;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD034", "no-bare-urls" ],
|
||||
|
|
@ -10,9 +10,9 @@ module.exports = {
|
|||
"tags": [ "links", "url" ],
|
||||
"function": function MD034(params, onError) {
|
||||
shared.filterTokens(params, "inline", function forToken(token) {
|
||||
var inLink = false;
|
||||
let inLink = false;
|
||||
token.children.forEach(function forChild(child) {
|
||||
var match = null;
|
||||
let match = null;
|
||||
if (child.type === "link_open") {
|
||||
inLink = true;
|
||||
} else if (child.type === "link_close") {
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD035", "hr-style" ],
|
||||
"description": "Horizontal rule style",
|
||||
"tags": [ "hr" ],
|
||||
"function": function MD035(params, onError) {
|
||||
var style = params.config.style || "consistent";
|
||||
let style = params.config.style || "consistent";
|
||||
shared.filterTokens(params, "hr", function forToken(token) {
|
||||
var lineTrim = token.line.trim();
|
||||
const lineTrim = token.line.trim();
|
||||
if (style === "consistent") {
|
||||
style = lineTrim;
|
||||
}
|
||||
|
|
|
|||
10
lib/md036.js
10
lib/md036.js
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"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 + "]$");
|
||||
const punctuation = params.config.punctuation || ".,;:!?";
|
||||
const re = new RegExp("[" + punctuation + "]$");
|
||||
function base(token) {
|
||||
if (token.type === "paragraph_open") {
|
||||
return function inParagraph(t) {
|
||||
// Always paragraph_open/inline/paragraph_close,
|
||||
// omit (t.type === "inline")
|
||||
var children = t.children.filter(function notEmptyText(child) {
|
||||
const children = t.children.filter(function notEmptyText(child) {
|
||||
return (child.type !== "text") || (child.content !== "");
|
||||
});
|
||||
if ((children.length === 3) &&
|
||||
|
|
@ -46,7 +46,7 @@ module.exports = {
|
|||
}
|
||||
return base;
|
||||
}
|
||||
var state = base;
|
||||
let state = base;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
state = state(token);
|
||||
});
|
||||
|
|
|
|||
14
lib/md037.js
14
lib/md037.js
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD037", "no-space-in-emphasis" ],
|
||||
|
|
@ -10,17 +10,17 @@ module.exports = {
|
|||
"tags": [ "whitespace", "emphasis" ],
|
||||
"function": function MD037(params, onError) {
|
||||
shared.forEachInlineChild(params, "text", function forToken(token) {
|
||||
var left = true;
|
||||
var match = /\s(\*\*?|__?)\s.+\1/.exec(token.content);
|
||||
let left = true;
|
||||
let match = /\s(\*\*?|__?)\s.+\1/.exec(token.content);
|
||||
if (!match) {
|
||||
left = false;
|
||||
match = /(\*\*?|__?).+\s\1\s/.exec(token.content);
|
||||
}
|
||||
if (match) {
|
||||
var text = match[0].trim();
|
||||
var line = params.lines[token.lineNumber - 1];
|
||||
var column = line.indexOf(text) + 1;
|
||||
var length = text.length;
|
||||
const text = match[0].trim();
|
||||
const line = params.lines[token.lineNumber - 1];
|
||||
const column = line.indexOf(text) + 1;
|
||||
const length = text.length;
|
||||
shared.addErrorContext(onError, token.lineNumber,
|
||||
text, left, !left, [ column, length ]);
|
||||
}
|
||||
|
|
|
|||
18
lib/md038.js
18
lib/md038.js
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var inlineCodeSpansRe = /(?:^|[^\\])((`+)((?:.*?[^`])|)\2(?!`))/g;
|
||||
const inlineCodeSpansRe = /(?:^|[^\\])((`+)((?:.*?[^`])|)\2(?!`))/g;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD038", "no-space-in-code" ],
|
||||
|
|
@ -13,14 +13,14 @@ module.exports = {
|
|||
"function": function MD038(params, onError) {
|
||||
shared.forEachInlineChild(params, "code_inline",
|
||||
function forToken(token) {
|
||||
var line = params.lines[token.lineNumber - 1];
|
||||
var match = null;
|
||||
const line = params.lines[token.lineNumber - 1];
|
||||
let 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 ];
|
||||
const inlineCodeSpan = match[1];
|
||||
const content = match[3];
|
||||
const length = inlineCodeSpan.length;
|
||||
const column = match.index + 1 + (match[0].length - length);
|
||||
const range = [ column, length ];
|
||||
if (/^\s([^`]|$)/.test(content)) {
|
||||
shared.addErrorContext(onError, token.lineNumber,
|
||||
inlineCodeSpan, true, false, range);
|
||||
|
|
|
|||
12
lib/md039.js
12
lib/md039.js
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=\(\S*\))/;
|
||||
const spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=\(\S*\))/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD039", "no-space-in-links" ],
|
||||
|
|
@ -12,16 +12,16 @@ module.exports = {
|
|||
"tags": [ "whitespace", "links" ],
|
||||
"function": function MD039(params, onError) {
|
||||
shared.filterTokens(params, "inline", function forToken(token) {
|
||||
var inLink = false;
|
||||
var linkText = "";
|
||||
let inLink = false;
|
||||
let linkText = "";
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type === "link_open") {
|
||||
inLink = true;
|
||||
linkText = "";
|
||||
} else if (child.type === "link_close") {
|
||||
inLink = false;
|
||||
var left = shared.trimLeft(linkText).length !== linkText.length;
|
||||
var right = shared.trimRight(linkText).length !== linkText.length;
|
||||
const left = shared.trimLeft(linkText).length !== linkText.length;
|
||||
const right = shared.trimRight(linkText).length !== linkText.length;
|
||||
if (left || right) {
|
||||
shared.addErrorContext(onError, token.lineNumber,
|
||||
"[" + linkText + "]", left, right,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD040", "fenced-code-language" ],
|
||||
|
|
|
|||
10
lib/md041.js
10
lib/md041.js
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD041", "first-line-h1" ],
|
||||
"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;
|
||||
var tag = "h" + level;
|
||||
var frontMatterTitleRe =
|
||||
const level = params.config.level || 1;
|
||||
const frontMatterTitle = params.config.front_matter_title;
|
||||
const tag = "h" + level;
|
||||
const frontMatterTitleRe =
|
||||
new RegExp(frontMatterTitle || "^\\s*title\\s*[:=]", "i");
|
||||
params.tokens.every(function forToken(token, index) {
|
||||
if (token.type === "heading_open") {
|
||||
|
|
|
|||
10
lib/md042.js
10
lib/md042.js
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
var emptyLinkRe = /\[[^\]]*](?:\((?:#?|(?:<>))\))/;
|
||||
const emptyLinkRe = /\[[^\]]*](?:\((?:#?|(?:<>))\))/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD042", "no-empty-links" ],
|
||||
|
|
@ -12,9 +12,9 @@ module.exports = {
|
|||
"tags": [ "links" ],
|
||||
"function": function MD042(params, onError) {
|
||||
shared.filterTokens(params, "inline", function forToken(token) {
|
||||
var inLink = false;
|
||||
var linkText = "";
|
||||
var emptyLink = false;
|
||||
let inLink = false;
|
||||
let linkText = "";
|
||||
let emptyLink = false;
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type === "link_open") {
|
||||
inLink = true;
|
||||
|
|
|
|||
16
lib/md043.js
16
lib/md043.js
|
|
@ -2,26 +2,26 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD043", "required-headings", "required-headers" ],
|
||||
"description": "Required heading structure",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD043(params, onError) {
|
||||
var requiredHeadings = params.config.headings || params.config.headers;
|
||||
const requiredHeadings = params.config.headings || params.config.headers;
|
||||
if (requiredHeadings) {
|
||||
var levels = {};
|
||||
const levels = {};
|
||||
[ 1, 2, 3, 4, 5, 6 ].forEach(function forLevel(level) {
|
||||
levels["h" + level] = "######".substr(-level);
|
||||
});
|
||||
var i = 0;
|
||||
var optional = false;
|
||||
var errorCount = 0;
|
||||
let i = 0;
|
||||
let optional = false;
|
||||
let errorCount = 0;
|
||||
shared.forEachHeading(params, function forHeading(heading, content) {
|
||||
if (!errorCount) {
|
||||
var actual = levels[heading.tag] + " " + content;
|
||||
var expected = requiredHeadings[i++] || "[None]";
|
||||
const actual = levels[heading.tag] + " " + content;
|
||||
const expected = requiredHeadings[i++] || "[None]";
|
||||
if (expected === "*") {
|
||||
optional = true;
|
||||
} else if (expected.toLowerCase() === actual.toLowerCase()) {
|
||||
|
|
|
|||
26
lib/md044.js
26
lib/md044.js
|
|
@ -2,33 +2,33 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD044", "proper-names" ],
|
||||
"description": "Proper names should have the correct capitalization",
|
||||
"tags": [ "spelling" ],
|
||||
"function": function MD044(params, onError) {
|
||||
var names = params.config.names || [];
|
||||
var codeBlocks = params.config.code_blocks;
|
||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
const names = params.config.names || [];
|
||||
const codeBlocks = params.config.code_blocks;
|
||||
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
names.forEach(function forName(name) {
|
||||
var escapedName = shared.escapeForRegExp(name);
|
||||
var namePattern = "\\S*\\b(" + escapedName + ")\\b\\S*";
|
||||
var anyNameRe = new RegExp(namePattern, "gi");
|
||||
const escapedName = shared.escapeForRegExp(name);
|
||||
const namePattern = "\\S*\\b(" + escapedName + ")\\b\\S*";
|
||||
const anyNameRe = new RegExp(namePattern, "gi");
|
||||
function forToken(token) {
|
||||
var fenceOffset = (token.type === "fence") ? 1 : 0;
|
||||
const fenceOffset = (token.type === "fence") ? 1 : 0;
|
||||
token.content.split(shared.newLineRe)
|
||||
.forEach(function forLine(line, index) {
|
||||
var match = null;
|
||||
let match = null;
|
||||
while ((match = anyNameRe.exec(line)) !== null) {
|
||||
var fullMatch = match[0];
|
||||
const fullMatch = match[0];
|
||||
if (!shared.bareUrlRe.test(fullMatch)) {
|
||||
var wordMatch = fullMatch
|
||||
const wordMatch = fullMatch
|
||||
.replace(/^\W*/, "").replace(/\W*$/, "");
|
||||
if (names.indexOf(wordMatch) === -1) {
|
||||
var lineNumber = token.lineNumber + index + fenceOffset;
|
||||
var range = [ match.index + 1, wordMatch.length ];
|
||||
const lineNumber = token.lineNumber + index + fenceOffset;
|
||||
const range = [ match.index + 1, wordMatch.length ];
|
||||
shared.addErrorDetailIf(onError, lineNumber,
|
||||
name, match[1], null, range);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
const shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD045", "no-alt-text" ],
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ module.exports.newLineRe = /\r\n|\r|\n/;
|
|||
module.exports.frontMatterRe = /^(---|\+\+\+)$[^]*?^\1$(\r\n|\r|\n)/m;
|
||||
|
||||
// Regular expression for matching inline disable/enable comments
|
||||
var inlineCommentRe =
|
||||
const inlineCommentRe =
|
||||
/<!--\s*markdownlint-(dis|en)able((?:\s+[a-z0-9_-]+)*)\s*-->/ig;
|
||||
module.exports.inlineCommentRe = inlineCommentRe;
|
||||
|
||||
|
|
@ -65,24 +65,24 @@ module.exports.isEmptyString = function isEmptyString(str) {
|
|||
// This preserves the line/column information for the rest of the document
|
||||
// Trailing whitespace is avoided with a '\' character in the last column
|
||||
// See https://www.w3.org/TR/html5/syntax.html#comments for details
|
||||
var htmlCommentBegin = "<!--";
|
||||
var htmlCommentEnd = "-->";
|
||||
const htmlCommentBegin = "<!--";
|
||||
const htmlCommentEnd = "-->";
|
||||
module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
|
||||
var i = 0;
|
||||
let i = 0;
|
||||
while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) {
|
||||
var j = text.indexOf(htmlCommentEnd, i);
|
||||
let j = text.indexOf(htmlCommentEnd, i);
|
||||
if (j === -1) {
|
||||
j = text.length;
|
||||
text += "\\";
|
||||
}
|
||||
var comment = text.slice(i + htmlCommentBegin.length, j);
|
||||
const comment = text.slice(i + htmlCommentBegin.length, j);
|
||||
if ((comment.length > 0) &&
|
||||
(comment[0] !== ">") &&
|
||||
(comment[comment.length - 1] !== "-") &&
|
||||
(comment.indexOf("--") === -1) &&
|
||||
(text.slice(i, j + htmlCommentEnd.length)
|
||||
.search(inlineCommentRe) === -1)) {
|
||||
var blanks = comment
|
||||
const blanks = comment
|
||||
.replace(/[^\r\n]/g, " ")
|
||||
.replace(/ ([\r\n])/g, "\\$1");
|
||||
text = text.slice(0, i + htmlCommentBegin.length) +
|
||||
|
|
@ -100,7 +100,7 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) {
|
|||
|
||||
// Returns the indent for a token
|
||||
function indentFor(token) {
|
||||
var line = token.line.replace(/^[\s>]*(> |>)/, "");
|
||||
const line = token.line.replace(/^[\s>]*(> |>)/, "");
|
||||
return line.length - trimLeft(line).length;
|
||||
}
|
||||
module.exports.indentFor = indentFor;
|
||||
|
|
@ -126,7 +126,7 @@ function filterTokens(params, type, callback) {
|
|||
}
|
||||
module.exports.filterTokens = filterTokens;
|
||||
|
||||
var tokenCache = null;
|
||||
let tokenCache = null;
|
||||
// Caches line metadata and flattened lists for reuse
|
||||
function makeTokenCache(params) {
|
||||
if (!params) {
|
||||
|
|
@ -135,14 +135,14 @@ function makeTokenCache(params) {
|
|||
}
|
||||
|
||||
// Populate line metadata array
|
||||
var lineMetadata = new Array(params.lines.length);
|
||||
var fenceStart = null;
|
||||
var inFence = false;
|
||||
const lineMetadata = new Array(params.lines.length);
|
||||
let fenceStart = null;
|
||||
let inFence = false;
|
||||
// Find fenced code by pattern (parser ignores "``` close fence")
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
var metadata = 0;
|
||||
var match = /^[ ]{0,3}(`{3,}|~{3,})/.exec(line);
|
||||
var fence = match && match[1];
|
||||
let metadata = 0;
|
||||
const match = /^[ ]{0,3}(`{3,}|~{3,})/.exec(line);
|
||||
const fence = match && match[1];
|
||||
if (fence &&
|
||||
(!inFence || (fence.substr(0, fenceStart.length) === fenceStart))) {
|
||||
metadata = inFence ? 2 : 6;
|
||||
|
|
@ -155,22 +155,22 @@ function makeTokenCache(params) {
|
|||
});
|
||||
// Find code blocks normally
|
||||
filterTokens(params, "code_block", function forToken(token) {
|
||||
for (var i = token.map[0]; i < token.map[1]; i++) {
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
lineMetadata[i] = 1;
|
||||
}
|
||||
});
|
||||
// Find tables normally
|
||||
filterTokens(params, "table_open", function forToken(token) {
|
||||
for (var i = token.map[0]; i < token.map[1]; i++) {
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
lineMetadata[i] += 8;
|
||||
}
|
||||
});
|
||||
|
||||
// Flatten lists
|
||||
var flattenedLists = [];
|
||||
var stack = [];
|
||||
var current = null;
|
||||
var lastWithMap = { "map": [ 0, 1 ] };
|
||||
const flattenedLists = [];
|
||||
const stack = [];
|
||||
let current = null;
|
||||
let lastWithMap = { "map": [ 0, 1 ] };
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if ((token.type === "bullet_list_open") ||
|
||||
(token.type === "ordered_list_open")) {
|
||||
|
|
@ -217,7 +217,7 @@ module.exports.makeTokenCache = makeTokenCache;
|
|||
module.exports.forEachLine = function forEachLine(callback) {
|
||||
// Invoke callback
|
||||
tokenCache.params.lines.forEach(function forLine(line, lineIndex) {
|
||||
var metadata = tokenCache.lineMetadata[lineIndex];
|
||||
const metadata = tokenCache.lineMetadata[lineIndex];
|
||||
callback(
|
||||
line,
|
||||
lineIndex,
|
||||
|
|
@ -241,7 +241,7 @@ function forEachInlineChild(params, type, callback) {
|
|||
|
||||
// Calls the provided function for each heading's content
|
||||
module.exports.forEachHeading = function forEachHeading(params, callback) {
|
||||
var heading = null;
|
||||
let heading = null;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
heading = token;
|
||||
|
|
@ -300,11 +300,11 @@ function addErrorContext(onError, lineNumber, context, left, right, range) {
|
|||
|
||||
// Returns a range object for a line by applying a RegExp
|
||||
module.exports.rangeFromRegExp = function rangeFromRegExp(line, regexp) {
|
||||
var range = null;
|
||||
var match = line.match(regexp);
|
||||
let range = null;
|
||||
const match = line.match(regexp);
|
||||
if (match) {
|
||||
var column = match.index + 1;
|
||||
var length = match[0].length;
|
||||
let column = match.index + 1;
|
||||
let length = match[0].length;
|
||||
if (match[2]) {
|
||||
column += match[1].length;
|
||||
length -= match[1].length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue