mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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
|
@ -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