mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +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
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"parser": "espree",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
|
@ -203,7 +206,7 @@
|
|||
"no-useless-escape": "error",
|
||||
"no-useless-rename": "error",
|
||||
"no-useless-return": "error",
|
||||
"no-var": "off",
|
||||
"no-var": "error",
|
||||
"no-void": "error",
|
||||
"no-warning-comments": "error",
|
||||
"no-whitespace-before-property": "error",
|
||||
|
@ -220,7 +223,7 @@
|
|||
"padded-blocks": "off",
|
||||
"padding-line-between-statements": "off",
|
||||
"prefer-arrow-callback": "off",
|
||||
"prefer-const": "off",
|
||||
"prefer-const": "error",
|
||||
"prefer-destructuring": "off",
|
||||
"prefer-numeric-literals": "error",
|
||||
"prefer-promise-reject-errors": "error",
|
||||
|
|
34
README.md
34
README.md
|
@ -203,8 +203,8 @@ package, but can be defined inline.
|
|||
Example:
|
||||
|
||||
```js
|
||||
var extraRules = require("extraRules");
|
||||
var options = {
|
||||
const extraRules = require("extraRules");
|
||||
const options = {
|
||||
"customRules": [ extraRules.one, extraRules.two ]
|
||||
};
|
||||
```
|
||||
|
@ -276,7 +276,7 @@ Sets of rules (known as a "style") can be stored separately and loaded as
|
|||
Example:
|
||||
|
||||
```js
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [ "..." ],
|
||||
"config": require("style/relaxed.json")
|
||||
};
|
||||
|
@ -310,7 +310,7 @@ And a `custom.json` configuration file:
|
|||
Then code like the following:
|
||||
|
||||
```js
|
||||
var options = {
|
||||
const options = {
|
||||
"config": markdownlint.readConfigSync("./custom.json")
|
||||
};
|
||||
```
|
||||
|
@ -318,7 +318,7 @@ var options = {
|
|||
Merges `custom.json` and `base.json` and is equivalent to:
|
||||
|
||||
```js
|
||||
var options = {
|
||||
const options = {
|
||||
"config": {
|
||||
"default": true,
|
||||
"line-length": false
|
||||
|
@ -458,9 +458,9 @@ Configuration object.
|
|||
Invoke `markdownlint` and use the `result` object's `toString` method:
|
||||
|
||||
```js
|
||||
var markdownlint = require("markdownlint");
|
||||
const markdownlint = require("markdownlint");
|
||||
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [ "good.md", "bad.md" ],
|
||||
"strings": {
|
||||
"good.string": "# good.string\n\nThis string passes all rules.",
|
||||
|
@ -491,7 +491,7 @@ bad.md: 1: MD041/first-line-h1 First line in file should be a top level heading
|
|||
Or invoke `markdownlint.sync` for a synchronous call:
|
||||
|
||||
```js
|
||||
var result = markdownlint.sync(options);
|
||||
const result = markdownlint.sync(options);
|
||||
console.log(result.toString());
|
||||
```
|
||||
|
||||
|
@ -542,9 +542,9 @@ Output:
|
|||
Integration with the [gulp](http://gulpjs.com/) build system is straightforward:
|
||||
|
||||
```js
|
||||
var gulp = require("gulp");
|
||||
var through2 = require("through2");
|
||||
var markdownlint = require("markdownlint");
|
||||
const gulp = require("gulp");
|
||||
const through2 = require("through2");
|
||||
const markdownlint = require("markdownlint");
|
||||
|
||||
gulp.task("markdownlint", function task() {
|
||||
return gulp.src("*.md", { "read": false })
|
||||
|
@ -552,7 +552,7 @@ gulp.task("markdownlint", function task() {
|
|||
markdownlint(
|
||||
{ "files": [ file.relative ] },
|
||||
function callback(err, result) {
|
||||
var resultString = (result || "").toString();
|
||||
const resultString = (result || "").toString();
|
||||
if (resultString) {
|
||||
console.log(resultString);
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ bad.md: 1: MD041/first-line-h1 First line in file should be a top level heading
|
|||
Integration with the [Grunt](http://gruntjs.com/) build system is similar:
|
||||
|
||||
```js
|
||||
var markdownlint = require("markdownlint");
|
||||
const markdownlint = require("markdownlint");
|
||||
|
||||
module.exports = function wrapper(grunt) {
|
||||
grunt.initConfig({
|
||||
|
@ -588,11 +588,11 @@ module.exports = function wrapper(grunt) {
|
|||
});
|
||||
|
||||
grunt.registerMultiTask("markdownlint", function task() {
|
||||
var done = this.async();
|
||||
const done = this.async();
|
||||
markdownlint(
|
||||
{ "files": this.filesSrc },
|
||||
function callback(err, result) {
|
||||
var resultString = err || ((result || "").toString());
|
||||
const resultString = err || ((result || "").toString());
|
||||
if (resultString) {
|
||||
grunt.fail.warn("\n" + resultString + "\n");
|
||||
}
|
||||
|
@ -634,12 +634,12 @@ Then reference `markdown-it` and `markdownlint`:
|
|||
And call it like so:
|
||||
|
||||
```js
|
||||
var options = {
|
||||
const options = {
|
||||
"strings": {
|
||||
"content": "Some Markdown to lint."
|
||||
}
|
||||
};
|
||||
var results = window.markdownlint.sync(options).toString();
|
||||
const results = window.markdownlint.sync(options).toString();
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
|
||||
var markdownlint = require("../lib/markdownlint");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
|
||||
module.exports = function wrapper(grunt) {
|
||||
grunt.initConfig({
|
||||
|
@ -12,11 +12,11 @@ module.exports = function wrapper(grunt) {
|
|||
});
|
||||
|
||||
grunt.registerMultiTask("markdownlint", function task() {
|
||||
var done = this.async();
|
||||
const done = this.async();
|
||||
markdownlint(
|
||||
{ "files": this.filesSrc },
|
||||
function callback(err, result) {
|
||||
var resultString = err || ((result || "").toString());
|
||||
const resultString = err || ((result || "").toString());
|
||||
if (resultString) {
|
||||
grunt.fail.warn("\n" + resultString + "\n");
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
var gulp = require("gulp");
|
||||
var through2 = require("through2");
|
||||
var markdownlint = require("../lib/markdownlint");
|
||||
const gulp = require("gulp");
|
||||
const through2 = require("through2");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
|
||||
// Simple task wrapper
|
||||
gulp.task("markdownlint", function task() {
|
||||
|
@ -11,7 +11,7 @@ gulp.task("markdownlint", function task() {
|
|||
markdownlint(
|
||||
{ "files": [ file.relative ] },
|
||||
function callback(err, result) {
|
||||
var resultString = (result || "").toString();
|
||||
const resultString = (result || "").toString();
|
||||
if (resultString) {
|
||||
console.log(resultString);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
var markdownlint = require("../lib/markdownlint");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [ "good.md", "bad.md" ],
|
||||
"strings": {
|
||||
"good.string": "# good.string\n\nThis string passes all rules.",
|
||||
|
@ -11,7 +11,7 @@ var options = {
|
|||
};
|
||||
|
||||
// Makes a synchronous call, using result.toString for pretty formatting
|
||||
var result = markdownlint.sync(options);
|
||||
const result = markdownlint.sync(options);
|
||||
console.log(result.toString());
|
||||
|
||||
// Makes an asynchronous call
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"test-cover": "istanbul cover node_modules/nodeunit/bin/nodeunit test/markdownlint-test.js",
|
||||
"test-extra": "nodeunit test/markdownlint-test-extra.js",
|
||||
"debug": "node debug node_modules/nodeunit/bin/nodeunit",
|
||||
"lint": "eslint lib test schema && eslint --env browser --global markdownit --global markdownlint --rule \"no-unused-vars: 0, no-extend-native: 0, max-statements: 0, no-console: 0\" demo && eslint --rule \"no-console: 0, no-shadow: 0, object-property-newline: 0\" example",
|
||||
"lint": "eslint lib test schema && eslint --env browser --global markdownit --global markdownlint --rule \"no-unused-vars: 0, no-extend-native: 0, max-statements: 0, no-console: 0, no-var: 0\" demo && eslint --rule \"no-console: 0, no-shadow: 0, object-property-newline: 0\" example",
|
||||
"build-config-schema": "node schema/build-config-schema.js",
|
||||
"build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && tsc --allowJs --outDir ../lib-es3 ../lib/markdownlint.js && browserify ../lib-es3/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && uglifyjs markdownlint-browser.js --compress --mangle --comments --output markdownlint-browser.min.js",
|
||||
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var rules = require("../lib/rules");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const rules = require("../lib/rules");
|
||||
|
||||
// Schema scaffolding
|
||||
var schema = {
|
||||
const schema = {
|
||||
"title": "Markdownlint configuration schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -22,21 +22,21 @@ var schema = {
|
|||
},
|
||||
"additionalProperties": false
|
||||
};
|
||||
var tags = {};
|
||||
const tags = {};
|
||||
|
||||
// Add rules
|
||||
rules.forEach(function forRule(rule) {
|
||||
rule.tags.forEach(function forTag(tag) {
|
||||
var tagRules = tags[tag] || [];
|
||||
const tagRules = tags[tag] || [];
|
||||
tagRules.push(rule.names[0]);
|
||||
tags[tag] = tagRules;
|
||||
});
|
||||
var scheme = {
|
||||
const scheme = {
|
||||
"description": rule.names.join("/") + " - " + rule.description,
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
};
|
||||
var custom = true;
|
||||
let custom = true;
|
||||
switch (rule.names[0]) {
|
||||
case "MD002":
|
||||
case "MD025":
|
||||
|
@ -286,7 +286,7 @@ rules.forEach(function forRule(rule) {
|
|||
|
||||
// Add tags
|
||||
Object.keys(tags).forEach(function forTag(tag) {
|
||||
var scheme = {
|
||||
const scheme = {
|
||||
"description": tag + " - " + tags[tag].join(", "),
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
|
@ -295,5 +295,5 @@ Object.keys(tags).forEach(function forTag(tag) {
|
|||
});
|
||||
|
||||
// Write schema
|
||||
var schemaFile = path.join(__dirname, "markdownlint-config-schema.json");
|
||||
const schemaFile = path.join(__dirname, "markdownlint-config-schema.json");
|
||||
fs.writeFileSync(schemaFile, JSON.stringify(schema, null, " "));
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var glob = require("glob");
|
||||
var markdownlint = require("../lib/markdownlint");
|
||||
var shared = require("../lib/shared");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const glob = require("glob");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const shared = require("../lib/shared");
|
||||
|
||||
module.exports.typeTestFiles = function typeTestFiles(test) {
|
||||
// Simulates typing each test file to validate handling of partial input
|
||||
function validate(file, content) {
|
||||
var results = markdownlint.sync({
|
||||
const results = markdownlint.sync({
|
||||
"strings": {
|
||||
"content": content
|
||||
},
|
||||
"resultVersion": 0
|
||||
});
|
||||
var contentLineCount = content.split(shared.newLineRe).length;
|
||||
const contentLineCount = content.split(shared.newLineRe).length;
|
||||
Object.keys(results.content).forEach(function forKey(ruleName) {
|
||||
results.content[ruleName].forEach(function forLine(line) {
|
||||
test.ok((line >= 1) && (line <= contentLineCount),
|
||||
|
@ -24,10 +24,10 @@ module.exports.typeTestFiles = function typeTestFiles(test) {
|
|||
});
|
||||
});
|
||||
}
|
||||
var files = fs.readdirSync("./test");
|
||||
const files = fs.readdirSync("./test");
|
||||
files.forEach(function forFile(file) {
|
||||
if (/\.md$/.test(file)) {
|
||||
var content = fs.readFileSync(
|
||||
let content = fs.readFileSync(
|
||||
path.join("./test", file), shared.utf8Encoding);
|
||||
while (content) {
|
||||
validate(file, content);
|
||||
|
@ -40,13 +40,13 @@ module.exports.typeTestFiles = function typeTestFiles(test) {
|
|||
|
||||
module.exports.parseAllFiles = function parseAllFiles(test) {
|
||||
// Parses all Markdown files in all dependencies
|
||||
var globOptions = {
|
||||
const globOptions = {
|
||||
// "cwd": "/",
|
||||
"realpath": true
|
||||
};
|
||||
glob("**/*.{md,markdown}", globOptions, function globCallback(err, matches) {
|
||||
test.ifError(err);
|
||||
var markdownlintOptions = {
|
||||
const markdownlintOptions = {
|
||||
"files": matches
|
||||
};
|
||||
markdownlint(markdownlintOptions, function markdownlintCallback(errr) {
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var md = require("markdown-it")();
|
||||
var Q = require("q");
|
||||
var tv4 = require("tv4");
|
||||
var markdownlint = require("../lib/markdownlint");
|
||||
var shared = require("../lib/shared");
|
||||
var rules = require("../lib/rules");
|
||||
var customRules = require("./rules");
|
||||
var defaultConfig = require("./markdownlint-test-default-config.json");
|
||||
var configSchema = require("../schema/markdownlint-config-schema.json");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const md = require("markdown-it")();
|
||||
const Q = require("q");
|
||||
const tv4 = require("tv4");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const shared = require("../lib/shared");
|
||||
const rules = require("../lib/rules");
|
||||
const customRules = require("./rules");
|
||||
const defaultConfig = require("./markdownlint-test-default-config.json");
|
||||
const configSchema = require("../schema/markdownlint-config-schema.json");
|
||||
|
||||
function createTestForFile(file) {
|
||||
return function testForFile(test) {
|
||||
test.expect(1);
|
||||
var detailedResults = /[/\\]detailed-results-/.test(file);
|
||||
var resultsFile = file.replace(/\.md$/, ".results.json");
|
||||
var configFile = file.replace(/\.md$/, ".json");
|
||||
var actualPromise = Q.nfcall(fs.stat, configFile)
|
||||
const detailedResults = /[/\\]detailed-results-/.test(file);
|
||||
const resultsFile = file.replace(/\.md$/, ".results.json");
|
||||
const configFile = file.replace(/\.md$/, ".json");
|
||||
const actualPromise = Q.nfcall(fs.stat, configFile)
|
||||
.then(
|
||||
function configFileExists() {
|
||||
return Q.nfcall(fs.readFile, configFile, shared.utf8Encoding)
|
||||
|
@ -29,32 +29,33 @@ function createTestForFile(file) {
|
|||
})
|
||||
.then(
|
||||
function lintWithConfig(config) {
|
||||
var mergedConfig = shared.assign(shared.clone(defaultConfig), config);
|
||||
const mergedConfig =
|
||||
shared.assign(shared.clone(defaultConfig), config);
|
||||
return Q.nfcall(markdownlint, {
|
||||
"files": [ file ],
|
||||
"config": mergedConfig,
|
||||
"resultVersion": detailedResults ? 2 : 0
|
||||
});
|
||||
});
|
||||
var expectedPromise = detailedResults ?
|
||||
const expectedPromise = detailedResults ?
|
||||
Q.nfcall(fs.readFile, resultsFile, shared.utf8Encoding)
|
||||
.then(JSON.parse) :
|
||||
Q.nfcall(fs.readFile, file, shared.utf8Encoding)
|
||||
.then(
|
||||
function fileContents(contents) {
|
||||
var lines = contents.split(shared.newLineRe);
|
||||
var results = {};
|
||||
const lines = contents.split(shared.newLineRe);
|
||||
const results = {};
|
||||
lines.forEach(function forLine(line, lineNum) {
|
||||
var regex = /\{(MD\d+)(?::(\d+))?\}/g;
|
||||
var match = null;
|
||||
const regex = /\{(MD\d+)(?::(\d+))?\}/g;
|
||||
let match = null;
|
||||
while ((match = regex.exec(line))) {
|
||||
var rule = match[1];
|
||||
var errors = results[rule] || [];
|
||||
const rule = match[1];
|
||||
const errors = results[rule] || [];
|
||||
errors.push(match[2] ? parseInt(match[2], 10) : lineNum + 1);
|
||||
results[rule] = errors;
|
||||
}
|
||||
});
|
||||
var sortedResults = {};
|
||||
const sortedResults = {};
|
||||
Object.keys(results).sort().forEach(function forKey(key) {
|
||||
sortedResults[key] = results[key];
|
||||
});
|
||||
|
@ -63,9 +64,9 @@ function createTestForFile(file) {
|
|||
Q.all([ actualPromise, expectedPromise ])
|
||||
.then(
|
||||
function compareResults(fulfillments) {
|
||||
var actual = fulfillments[0];
|
||||
var results = fulfillments[1];
|
||||
var expected = {};
|
||||
const actual = fulfillments[0];
|
||||
const results = fulfillments[1];
|
||||
const expected = {};
|
||||
expected[file] = results;
|
||||
test.deepEqual(actual, expected, "Line numbers are not correct.");
|
||||
})
|
||||
|
@ -81,7 +82,7 @@ fs.readdirSync("./test").forEach(function forFile(file) {
|
|||
|
||||
module.exports.projectFiles = function projectFiles(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [ "README.md" ],
|
||||
"noInlineConfig": true,
|
||||
"config": {
|
||||
|
@ -91,7 +92,7 @@ module.exports.projectFiles = function projectFiles(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actual) {
|
||||
test.ifError(err);
|
||||
var expected = { "README.md": [] };
|
||||
const expected = { "README.md": [] };
|
||||
test.deepEqual(actual, expected, "Issue(s) with project files.");
|
||||
test.done();
|
||||
});
|
||||
|
@ -99,7 +100,7 @@ module.exports.projectFiles = function projectFiles(test) {
|
|||
|
||||
module.exports.resultFormattingV0 = function resultFormattingV0(test) {
|
||||
test.expect(4);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -109,7 +110,7 @@ module.exports.resultFormattingV0 = function resultFormattingV0(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD018": [ 1 ],
|
||||
|
@ -120,8 +121,8 @@ module.exports.resultFormattingV0 = function resultFormattingV0(test) {
|
|||
}
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
let actualMessage = actualResult.toString();
|
||||
let expectedMessage =
|
||||
"./test/atx_heading_spacing.md: 3: MD002" +
|
||||
" First heading should be a top level heading\n" +
|
||||
"./test/atx_heading_spacing.md: 1: MD018" +
|
||||
|
@ -152,7 +153,7 @@ module.exports.resultFormattingV0 = function resultFormattingV0(test) {
|
|||
|
||||
module.exports.resultFormattingSyncV0 = function resultFormattingSyncV0(test) {
|
||||
test.expect(3);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -160,8 +161,8 @@ module.exports.resultFormattingSyncV0 = function resultFormattingSyncV0(test) {
|
|||
"config": defaultConfig,
|
||||
"resultVersion": 0
|
||||
};
|
||||
var actualResult = markdownlint.sync(options);
|
||||
var expectedResult = {
|
||||
const actualResult = markdownlint.sync(options);
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD018": [ 1 ],
|
||||
|
@ -172,8 +173,8 @@ module.exports.resultFormattingSyncV0 = function resultFormattingSyncV0(test) {
|
|||
}
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
let actualMessage = actualResult.toString();
|
||||
let expectedMessage =
|
||||
"./test/atx_heading_spacing.md: 3: MD002" +
|
||||
" First heading should be a top level heading\n" +
|
||||
"./test/atx_heading_spacing.md: 1: MD018" +
|
||||
|
@ -203,7 +204,7 @@ module.exports.resultFormattingSyncV0 = function resultFormattingSyncV0(test) {
|
|||
|
||||
module.exports.resultFormattingV1 = function resultFormattingV1(test) {
|
||||
test.expect(3);
|
||||
var options = {
|
||||
const options = {
|
||||
"strings": {
|
||||
"truncate":
|
||||
"# Multiple spaces inside hashes on closed atx style heading #"
|
||||
|
@ -217,7 +218,7 @@ module.exports.resultFormattingV1 = function resultFormattingV1(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"truncate": [
|
||||
{ "lineNumber": 1,
|
||||
"ruleName": "MD021",
|
||||
|
@ -269,8 +270,8 @@ module.exports.resultFormattingV1 = function resultFormattingV1(test) {
|
|||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"truncate: 1: MD021/no-multiple-space-closed-atx" +
|
||||
" Multiple spaces inside hashes on closed atx style heading" +
|
||||
" [Context: \"# Multiple spa...tyle heading #\"]\n" +
|
||||
|
@ -296,7 +297,7 @@ module.exports.resultFormattingV1 = function resultFormattingV1(test) {
|
|||
|
||||
module.exports.resultFormattingV2 = function resultFormattingV2(test) {
|
||||
test.expect(3);
|
||||
var options = {
|
||||
const options = {
|
||||
"strings": {
|
||||
"truncate":
|
||||
"# Multiple spaces inside hashes on closed atx style heading #"
|
||||
|
@ -309,7 +310,7 @@ module.exports.resultFormattingV2 = function resultFormattingV2(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"truncate": [
|
||||
{ "lineNumber": 1,
|
||||
"ruleNames": [ "MD021", "no-multiple-space-closed-atx" ],
|
||||
|
@ -355,8 +356,8 @@ module.exports.resultFormattingV2 = function resultFormattingV2(test) {
|
|||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"truncate: 1: MD021/no-multiple-space-closed-atx" +
|
||||
" Multiple spaces inside hashes on closed atx style heading" +
|
||||
" [Context: \"# Multiple spa...tyle heading #\"]\n" +
|
||||
|
@ -384,7 +385,7 @@ module.exports.resultFormattingV2 = function resultFormattingV2(test) {
|
|||
|
||||
module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"strings": {
|
||||
"cr": "One\rTwo\r#Three",
|
||||
"lf": "One\nTwo\n#Three",
|
||||
|
@ -396,7 +397,7 @@ module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"cr": { "MD018": [ 3 ] },
|
||||
"lf": { "MD018": [ 3 ] },
|
||||
"crlf": { "MD018": [ 3 ] },
|
||||
|
@ -409,7 +410,7 @@ module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
|
|||
|
||||
module.exports.inputOnlyNewline = function inputOnlyNewline(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"strings": {
|
||||
"cr": "\r",
|
||||
"lf": "\n",
|
||||
|
@ -421,7 +422,7 @@ module.exports.inputOnlyNewline = function inputOnlyNewline(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"cr": [],
|
||||
"lf": [],
|
||||
"crlf": []
|
||||
|
@ -433,7 +434,7 @@ module.exports.inputOnlyNewline = function inputOnlyNewline(test) {
|
|||
|
||||
module.exports.defaultTrue = function defaultTrue(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -445,7 +446,7 @@ module.exports.defaultTrue = function defaultTrue(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD018": [ 1 ],
|
||||
|
@ -464,7 +465,7 @@ module.exports.defaultTrue = function defaultTrue(test) {
|
|||
|
||||
module.exports.defaultFalse = function defaultFalse(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -476,7 +477,7 @@ module.exports.defaultFalse = function defaultFalse(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {},
|
||||
"./test/first_heading_bad_atx.md": {}
|
||||
};
|
||||
|
@ -487,7 +488,7 @@ module.exports.defaultFalse = function defaultFalse(test) {
|
|||
|
||||
module.exports.defaultUndefined = function defaultUndefined(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -497,7 +498,7 @@ module.exports.defaultUndefined = function defaultUndefined(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD018": [ 1 ],
|
||||
|
@ -516,7 +517,7 @@ module.exports.defaultUndefined = function defaultUndefined(test) {
|
|||
|
||||
module.exports.disableRules = function disableRules(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -531,7 +532,7 @@ module.exports.disableRules = function disableRules(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD018": [ 1 ]
|
||||
},
|
||||
|
@ -544,7 +545,7 @@ module.exports.disableRules = function disableRules(test) {
|
|||
|
||||
module.exports.enableRules = function enableRules(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -558,7 +559,7 @@ module.exports.enableRules = function enableRules(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD019": [ 3, 5 ]
|
||||
|
@ -574,7 +575,7 @@ module.exports.enableRules = function enableRules(test) {
|
|||
|
||||
module.exports.enableRulesMixedCase = function enableRulesMixedCase(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -588,7 +589,7 @@ module.exports.enableRulesMixedCase = function enableRulesMixedCase(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD019": [ 3, 5 ]
|
||||
|
@ -604,7 +605,7 @@ module.exports.enableRulesMixedCase = function enableRulesMixedCase(test) {
|
|||
|
||||
module.exports.disableTag = function disableTag(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -617,7 +618,7 @@ module.exports.disableTag = function disableTag(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD041": [ 1 ]
|
||||
|
@ -634,7 +635,7 @@ module.exports.disableTag = function disableTag(test) {
|
|||
|
||||
module.exports.enableTag = function enableTag(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -648,7 +649,7 @@ module.exports.enableTag = function enableTag(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD018": [ 1 ],
|
||||
"MD019": [ 3, 5 ]
|
||||
|
@ -662,7 +663,7 @@ module.exports.enableTag = function enableTag(test) {
|
|||
|
||||
module.exports.enableTagMixedCase = function enableTagMixedCase(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
|
@ -676,7 +677,7 @@ module.exports.enableTagMixedCase = function enableTagMixedCase(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD018": [ 1 ],
|
||||
"MD019": [ 3, 5 ]
|
||||
|
@ -701,14 +702,14 @@ module.exports.styleFiles = function styleFiles(test) {
|
|||
|
||||
module.exports.styleAll = function styleAll(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [ "./test/break-all-the-rules.md" ],
|
||||
"config": require("../style/all.json"),
|
||||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/break-all-the-rules.md": {
|
||||
"MD001": [ 3 ],
|
||||
"MD002": [ 1 ],
|
||||
|
@ -757,14 +758,14 @@ module.exports.styleAll = function styleAll(test) {
|
|||
|
||||
module.exports.styleRelaxed = function styleRelaxed(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"files": [ "./test/break-all-the-rules.md" ],
|
||||
"config": require("../style/relaxed.json"),
|
||||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"./test/break-all-the-rules.md": {
|
||||
"MD001": [ 3 ],
|
||||
"MD002": [ 1 ],
|
||||
|
@ -809,7 +810,7 @@ module.exports.nullFrontMatter = function nullFrontMatter(test) {
|
|||
"resultVersion": 0
|
||||
}, function callback(err, result) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"content": { "MD010": [ 2 ] }
|
||||
};
|
||||
test.deepEqual(result, expectedResult, "Undetected issues.");
|
||||
|
@ -830,7 +831,7 @@ module.exports.customFrontMatter = function customFrontMatter(test) {
|
|||
}
|
||||
}, function callback(err, result) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"content": []
|
||||
};
|
||||
test.deepEqual(result, expectedResult, "Did not get empty results.");
|
||||
|
@ -860,7 +861,7 @@ module.exports.noInlineConfig = function noInlineConfig(test) {
|
|||
"resultVersion": 0
|
||||
}, function callback(err, result) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"content": {
|
||||
"MD010": [ 3, 7, 11 ]
|
||||
}
|
||||
|
@ -915,7 +916,7 @@ module.exports.readmeHeadings = function readmeHeadings(test) {
|
|||
}
|
||||
}, function callback(err, result) {
|
||||
test.ifError(err);
|
||||
var expected = { "README.md": [] };
|
||||
const expected = { "README.md": [] };
|
||||
test.deepEqual(result, expected, "Unexpected issues.");
|
||||
test.done();
|
||||
});
|
||||
|
@ -923,11 +924,11 @@ module.exports.readmeHeadings = function readmeHeadings(test) {
|
|||
|
||||
module.exports.filesArrayNotModified = function filesArrayNotModified(test) {
|
||||
test.expect(2);
|
||||
var files = [
|
||||
const files = [
|
||||
"./test/atx_heading_spacing.md",
|
||||
"./test/first_heading_bad_atx.md"
|
||||
];
|
||||
var expectedFiles = files.slice();
|
||||
const expectedFiles = files.slice();
|
||||
markdownlint({ "files": files }, function callback(err) {
|
||||
test.ifError(err);
|
||||
test.deepEqual(files, expectedFiles, "Files modified.");
|
||||
|
@ -946,7 +947,7 @@ module.exports.filesArrayAsString = function filesArrayAsString(test) {
|
|||
}
|
||||
}, function callback(err, actual) {
|
||||
test.ifError(err);
|
||||
var expected = { "README.md": [] };
|
||||
const expected = { "README.md": [] };
|
||||
test.deepEqual(actual, expected, "Unexpected issues.");
|
||||
test.done();
|
||||
});
|
||||
|
@ -1015,7 +1016,7 @@ module.exports.missingStringValue = function missingStringValue(test) {
|
|||
"config": defaultConfig
|
||||
}, function callback(err, result) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"undefined": [],
|
||||
"null": [],
|
||||
"empty": []
|
||||
|
@ -1027,10 +1028,10 @@ module.exports.missingStringValue = function missingStringValue(test) {
|
|||
|
||||
module.exports.readme = function readme(test) {
|
||||
test.expect(109);
|
||||
var tagToRules = {};
|
||||
const tagToRules = {};
|
||||
rules.forEach(function forRule(rule) {
|
||||
rule.tags.forEach(function forTag(tag) {
|
||||
var tagRules = tagToRules[tag] || [];
|
||||
const tagRules = tagToRules[tag] || [];
|
||||
tagRules.push(rule.names[0]);
|
||||
tagToRules[tag] = tagRules;
|
||||
});
|
||||
|
@ -1038,12 +1039,12 @@ module.exports.readme = function readme(test) {
|
|||
fs.readFile("README.md", shared.utf8Encoding,
|
||||
function readFile(err, contents) {
|
||||
test.ifError(err);
|
||||
var rulesLeft = rules.slice();
|
||||
var seenRelated = false;
|
||||
var seenRules = false;
|
||||
var inRules = false;
|
||||
var seenTags = false;
|
||||
var inTags = false;
|
||||
const rulesLeft = rules.slice();
|
||||
let seenRelated = false;
|
||||
let seenRules = false;
|
||||
let inRules = false;
|
||||
let seenTags = false;
|
||||
let inTags = false;
|
||||
md.parse(contents, {}).forEach(function forToken(token) {
|
||||
if (token.type === "bullet_list_open") {
|
||||
if (!seenRelated) {
|
||||
|
@ -1057,31 +1058,32 @@ module.exports.readme = function readme(test) {
|
|||
inRules = inTags = false;
|
||||
} else if (token.type === "inline") {
|
||||
if (inRules) {
|
||||
var rule = rulesLeft.shift();
|
||||
const rule = rulesLeft.shift();
|
||||
test.ok(rule,
|
||||
"Missing rule implementation for " + token.content + ".");
|
||||
if (rule) {
|
||||
var ruleName = rule.names[0];
|
||||
var ruleAliases = rule.names.slice(1);
|
||||
var expected = "**[" + ruleName + "](doc/Rules.md#" +
|
||||
const ruleName = rule.names[0];
|
||||
const ruleAliases = rule.names.slice(1);
|
||||
const expected = "**[" + ruleName + "](doc/Rules.md#" +
|
||||
ruleName.toLowerCase() + ")** *" +
|
||||
ruleAliases.join("/") + "* - " + rule.description;
|
||||
test.equal(token.content, expected, "Rule mismatch.");
|
||||
}
|
||||
} else if (inTags) {
|
||||
var parts = token.content.replace(/\*\*/g, "").split(/ - |, |,\n/);
|
||||
var tag = parts.shift();
|
||||
const parts =
|
||||
token.content.replace(/\*\*/g, "").split(/ - |, |,\n/);
|
||||
const tag = parts.shift();
|
||||
test.deepEqual(parts, tagToRules[tag] || [],
|
||||
"Rule mismatch for tag " + tag + ".");
|
||||
delete tagToRules[tag];
|
||||
}
|
||||
}
|
||||
});
|
||||
var ruleLeft = rulesLeft.shift();
|
||||
const ruleLeft = rulesLeft.shift();
|
||||
test.ok(!ruleLeft,
|
||||
"Missing rule documentation for " +
|
||||
(ruleLeft || "[NO RULE]").toString() + ".");
|
||||
var tagLeft = Object.keys(tagToRules).shift();
|
||||
const tagLeft = Object.keys(tagToRules).shift();
|
||||
test.ok(!tagLeft, "Undocumented tag " + tagLeft + ".");
|
||||
test.done();
|
||||
});
|
||||
|
@ -1092,13 +1094,13 @@ module.exports.doc = function doc(test) {
|
|||
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
||||
function readFile(err, contents) {
|
||||
test.ifError(err);
|
||||
var rulesLeft = rules.slice();
|
||||
var inHeading = false;
|
||||
var rule = null;
|
||||
var ruleHasTags = true;
|
||||
var ruleHasAliases = true;
|
||||
var ruleUsesParams = null;
|
||||
var tagAliasParameterRe = /, |: | /;
|
||||
const rulesLeft = rules.slice();
|
||||
let inHeading = false;
|
||||
let rule = null;
|
||||
let ruleHasTags = true;
|
||||
let ruleHasAliases = true;
|
||||
let ruleUsesParams = null;
|
||||
const tagAliasParameterRe = /, |: | /;
|
||||
function testTagsAliasesParams(r) {
|
||||
r = r || "[NO RULE]";
|
||||
test.ok(ruleHasTags,
|
||||
|
@ -1140,8 +1142,8 @@ module.exports.doc = function doc(test) {
|
|||
"Alias mismatch for rule " + rule.toString() + ".");
|
||||
ruleHasAliases = true;
|
||||
} else if (/^Parameters: /.test(token.content) && rule) {
|
||||
var inDetails = false;
|
||||
var parameters = token.content.split(tagAliasParameterRe)
|
||||
let inDetails = false;
|
||||
const parameters = token.content.split(tagAliasParameterRe)
|
||||
.slice(1)
|
||||
.filter(function forPart(part) {
|
||||
inDetails = inDetails || (part[0] === "(");
|
||||
|
@ -1153,7 +1155,7 @@ module.exports.doc = function doc(test) {
|
|||
}
|
||||
}
|
||||
});
|
||||
var ruleLeft = rulesLeft.shift();
|
||||
const ruleLeft = rulesLeft.shift();
|
||||
test.ok(!ruleLeft,
|
||||
"Missing rule documentation for " +
|
||||
(ruleLeft || "[NO RULE]").toString() + ".");
|
||||
|
@ -1165,14 +1167,14 @@ module.exports.doc = function doc(test) {
|
|||
};
|
||||
|
||||
module.exports.validateConfigSchema = function validateConfigSchema(test) {
|
||||
var jsonFileRe = /\.json$/i;
|
||||
var resultsFileRe = /\.results\.json$/i;
|
||||
var testDirectory = __dirname;
|
||||
var testFiles = fs.readdirSync(testDirectory);
|
||||
const jsonFileRe = /\.json$/i;
|
||||
const resultsFileRe = /\.results\.json$/i;
|
||||
const testDirectory = __dirname;
|
||||
const testFiles = fs.readdirSync(testDirectory);
|
||||
testFiles.filter(function filterFile(file) {
|
||||
return jsonFileRe.test(file) && !resultsFileRe.test(file);
|
||||
}).forEach(function forFile(file) {
|
||||
var data = fs.readFileSync(path.join(testDirectory, file));
|
||||
const data = fs.readFileSync(path.join(testDirectory, file));
|
||||
test.ok(
|
||||
tv4.validate(JSON.parse(data), configSchema),
|
||||
file + "\n" + JSON.stringify(tv4.error, null, 2));
|
||||
|
@ -1183,7 +1185,7 @@ module.exports.validateConfigSchema = function validateConfigSchema(test) {
|
|||
module.exports.clearHtmlCommentTextValid =
|
||||
function clearHtmlCommentTextValid(test) {
|
||||
test.expect(1);
|
||||
var validComments = [
|
||||
const validComments = [
|
||||
"<!-- text -->",
|
||||
"<!--text-->",
|
||||
"<!-- -->",
|
||||
|
@ -1219,7 +1221,7 @@ function clearHtmlCommentTextValid(test) {
|
|||
"<!--",
|
||||
"text"
|
||||
];
|
||||
var validResult = [
|
||||
const validResult = [
|
||||
"<!-- -->",
|
||||
"<!-- -->",
|
||||
"<!-- -->",
|
||||
|
@ -1255,8 +1257,8 @@ function clearHtmlCommentTextValid(test) {
|
|||
"<!--",
|
||||
" \\"
|
||||
];
|
||||
var actual = shared.clearHtmlCommentText(validComments.join("\n"));
|
||||
var expected = validResult.join("\n");
|
||||
const actual = shared.clearHtmlCommentText(validComments.join("\n"));
|
||||
const expected = validResult.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.done();
|
||||
};
|
||||
|
@ -1264,7 +1266,7 @@ function clearHtmlCommentTextValid(test) {
|
|||
module.exports.clearHtmlCommentTextInvalid =
|
||||
function clearHtmlCommentTextInvalid(test) {
|
||||
test.expect(1);
|
||||
var invalidComments = [
|
||||
const invalidComments = [
|
||||
"<!>",
|
||||
"<!->",
|
||||
"<!-->",
|
||||
|
@ -1282,8 +1284,8 @@ function clearHtmlCommentTextInvalid(test) {
|
|||
"<!--text--->",
|
||||
"<!--te--xt-->"
|
||||
];
|
||||
var actual = shared.clearHtmlCommentText(invalidComments.join("\n"));
|
||||
var expected = invalidComments.join("\n");
|
||||
const actual = shared.clearHtmlCommentText(invalidComments.join("\n"));
|
||||
const expected = invalidComments.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.done();
|
||||
};
|
||||
|
@ -1291,20 +1293,20 @@ function clearHtmlCommentTextInvalid(test) {
|
|||
module.exports.clearHtmlCommentTextNonGreedy =
|
||||
function clearHtmlCommentTextNonGreedy(test) {
|
||||
test.expect(1);
|
||||
var nonGreedyComments = [
|
||||
const nonGreedyComments = [
|
||||
"<!-- text --> -->",
|
||||
"<!---text --> -->",
|
||||
"<!--t--> -->",
|
||||
"<!----> -->"
|
||||
];
|
||||
var nonGreedyResult = [
|
||||
const nonGreedyResult = [
|
||||
"<!-- --> -->",
|
||||
"<!-- --> -->",
|
||||
"<!-- --> -->",
|
||||
"<!----> -->"
|
||||
];
|
||||
var actual = shared.clearHtmlCommentText(nonGreedyComments.join("\n"));
|
||||
var expected = nonGreedyResult.join("\n");
|
||||
const actual = shared.clearHtmlCommentText(nonGreedyComments.join("\n"));
|
||||
const expected = nonGreedyResult.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.done();
|
||||
};
|
||||
|
@ -1312,28 +1314,28 @@ function clearHtmlCommentTextNonGreedy(test) {
|
|||
module.exports.clearHtmlCommentTextEmbedded =
|
||||
function clearHtmlCommentTextEmbedded(test) {
|
||||
test.expect(1);
|
||||
var embeddedComments = [
|
||||
const embeddedComments = [
|
||||
"text<!--text-->text",
|
||||
"<!-- markdownlint-disable MD010 -->",
|
||||
"text<!--text-->text",
|
||||
"text<!-- markdownlint-disable MD010 -->text",
|
||||
"text<!--text-->text"
|
||||
];
|
||||
var embeddedResult = [
|
||||
const embeddedResult = [
|
||||
"text<!-- -->text",
|
||||
"<!-- markdownlint-disable MD010 -->",
|
||||
"text<!-- -->text",
|
||||
"text<!-- markdownlint-disable MD010 -->text",
|
||||
"text<!-- -->text"
|
||||
];
|
||||
var actual = shared.clearHtmlCommentText(embeddedComments.join("\n"));
|
||||
var expected = embeddedResult.join("\n");
|
||||
const actual = shared.clearHtmlCommentText(embeddedComments.join("\n"));
|
||||
const expected = embeddedResult.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.done();
|
||||
};
|
||||
|
||||
module.exports.trimLeftRight = function trimLeftRight(test) {
|
||||
var inputs = [
|
||||
const inputs = [
|
||||
"text text",
|
||||
" text text ",
|
||||
" text text ",
|
||||
|
@ -1365,7 +1367,7 @@ module.exports.configSingle = function configSingle(test) {
|
|||
markdownlint.readConfig("./test/config-child.json",
|
||||
function callback(err, actual) {
|
||||
test.ifError(err);
|
||||
var expected = require("./config-child.json");
|
||||
const expected = require("./config-child.json");
|
||||
test.deepEqual(actual, expected, "Config object not correct.");
|
||||
test.done();
|
||||
});
|
||||
|
@ -1376,7 +1378,7 @@ module.exports.configAbsolute = function configAbsolute(test) {
|
|||
markdownlint.readConfig(path.join(__dirname, "config-child.json"),
|
||||
function callback(err, actual) {
|
||||
test.ifError(err);
|
||||
var expected = require("./config-child.json");
|
||||
const expected = require("./config-child.json");
|
||||
test.deepEqual(actual, expected, "Config object not correct.");
|
||||
test.done();
|
||||
});
|
||||
|
@ -1387,7 +1389,7 @@ module.exports.configMultiple = function configMultiple(test) {
|
|||
markdownlint.readConfig("./test/config-grandparent.json",
|
||||
function callback(err, actual) {
|
||||
test.ifError(err);
|
||||
var expected = shared.assign(
|
||||
const expected = shared.assign(
|
||||
shared.assign(
|
||||
shared.assign({}, require("./config-child.json")),
|
||||
require("./config-parent.json")),
|
||||
|
@ -1447,25 +1449,25 @@ module.exports.configBadChildJson = function configBadChildJson(test) {
|
|||
|
||||
module.exports.configSingleSync = function configSingleSync(test) {
|
||||
test.expect(1);
|
||||
var actual = markdownlint.readConfigSync("./test/config-child.json");
|
||||
var expected = require("./config-child.json");
|
||||
const actual = markdownlint.readConfigSync("./test/config-child.json");
|
||||
const expected = require("./config-child.json");
|
||||
test.deepEqual(actual, expected, "Config object not correct.");
|
||||
test.done();
|
||||
};
|
||||
|
||||
module.exports.configAbsoluteSync = function configAbsoluteSync(test) {
|
||||
test.expect(1);
|
||||
var actual = markdownlint.readConfigSync(
|
||||
const actual = markdownlint.readConfigSync(
|
||||
path.join(__dirname, "config-child.json"));
|
||||
var expected = require("./config-child.json");
|
||||
const expected = require("./config-child.json");
|
||||
test.deepEqual(actual, expected, "Config object not correct.");
|
||||
test.done();
|
||||
};
|
||||
|
||||
module.exports.configMultipleSync = function configMultipleSync(test) {
|
||||
test.expect(1);
|
||||
var actual = markdownlint.readConfigSync("./test/config-grandparent.json");
|
||||
var expected = shared.assign(
|
||||
const actual = markdownlint.readConfigSync("./test/config-grandparent.json");
|
||||
const expected = shared.assign(
|
||||
shared.assign(
|
||||
shared.assign({}, require("./config-child.json")),
|
||||
require("./config-parent.json")),
|
||||
|
@ -1527,15 +1529,15 @@ module.exports.configBadChildJsonSync = function configBadChildJsonSync(test) {
|
|||
|
||||
module.exports.customRulesV0 = function customRulesV0(test) {
|
||||
test.expect(4);
|
||||
var customRulesMd = "./test/custom-rules.md";
|
||||
var options = {
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {};
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = {
|
||||
"any-blockquote": [ 12 ],
|
||||
"every-n-lines": [ 2, 4, 6, 10, 12 ],
|
||||
|
@ -1543,8 +1545,8 @@ module.exports.customRulesV0 = function customRulesV0(test) {
|
|||
"letters-E-X": [ 3, 7 ]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
let actualMessage = actualResult.toString();
|
||||
let expectedMessage =
|
||||
"./test/custom-rules.md: 12: any-blockquote" +
|
||||
" Rule that reports an error for any blockquote\n" +
|
||||
"./test/custom-rules.md: 2: every-n-lines" +
|
||||
|
@ -1591,15 +1593,15 @@ module.exports.customRulesV0 = function customRulesV0(test) {
|
|||
|
||||
module.exports.customRulesV1 = function customRulesV1(test) {
|
||||
test.expect(3);
|
||||
var customRulesMd = "./test/custom-rules.md";
|
||||
var options = {
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
"resultVersion": 1
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {};
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = [
|
||||
{ "lineNumber": 12,
|
||||
"ruleName": "any-blockquote",
|
||||
|
@ -1668,8 +1670,8 @@ module.exports.customRulesV1 = function customRulesV1(test) {
|
|||
"errorRange": null }
|
||||
];
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"./test/custom-rules.md: 12: any-blockquote/any-blockquote" +
|
||||
" Rule that reports an error for any blockquote" +
|
||||
" [Blockquote spans 1 line(s).] [Context: \"> Block\"]\n" +
|
||||
|
@ -1698,15 +1700,15 @@ module.exports.customRulesV1 = function customRulesV1(test) {
|
|||
|
||||
module.exports.customRulesV2 = function customRulesV2(test) {
|
||||
test.expect(3);
|
||||
var customRulesMd = "./test/custom-rules.md";
|
||||
var options = {
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
"resultVersion": 2
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {};
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = [
|
||||
{ "lineNumber": 12,
|
||||
"ruleNames": [ "any-blockquote" ],
|
||||
|
@ -1766,8 +1768,8 @@ module.exports.customRulesV2 = function customRulesV2(test) {
|
|||
"errorRange": null }
|
||||
];
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"./test/custom-rules.md: 12: any-blockquote" +
|
||||
" Rule that reports an error for any blockquote" +
|
||||
" [Blockquote spans 1 line(s).] [Context: \"> Block\"]\n" +
|
||||
|
@ -1796,8 +1798,8 @@ module.exports.customRulesV2 = function customRulesV2(test) {
|
|||
|
||||
module.exports.customRulesConfig = function customRulesConfig(test) {
|
||||
test.expect(2);
|
||||
var customRulesMd = "./test/custom-rules.md";
|
||||
var options = {
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
"config": {
|
||||
|
@ -1811,7 +1813,7 @@ module.exports.customRulesConfig = function customRulesConfig(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {};
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = {
|
||||
"any-blockquote": [ 12 ],
|
||||
"every-n-lines": [ 3, 6, 12 ],
|
||||
|
@ -1831,11 +1833,11 @@ module.exports.customRulesBadProperty = function customRulesBadProperty(test) {
|
|||
[ "tags", [ null, "string", [], [ null ], [ "" ], [ "string", 10 ] ] ],
|
||||
[ "function", [ null, "string", [] ] ]
|
||||
].forEach(function forProperty(property) {
|
||||
var propertyName = property[0];
|
||||
const propertyName = property[0];
|
||||
property[1].forEach(function forPropertyValue(propertyValue) {
|
||||
var badRule = shared.clone(customRules.anyBlockquote);
|
||||
const badRule = shared.clone(customRules.anyBlockquote);
|
||||
badRule[propertyName] = propertyValue;
|
||||
var options = {
|
||||
const options = {
|
||||
"customRules": [ badRule ]
|
||||
};
|
||||
test.throws(function badRuleCall() {
|
||||
|
@ -1934,7 +1936,7 @@ function customRulesUsedTagName(test) {
|
|||
module.exports.customRulesThrowForFile =
|
||||
function customRulesThrowForFile(test) {
|
||||
test.expect(4);
|
||||
var exceptionMessage = "Test exception message";
|
||||
const exceptionMessage = "Test exception message";
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
{
|
||||
|
@ -1960,7 +1962,7 @@ function customRulesThrowForFile(test) {
|
|||
module.exports.customRulesThrowForFileSync =
|
||||
function customRulesThrowForFileSync(test) {
|
||||
test.expect(4);
|
||||
var exceptionMessage = "Test exception message";
|
||||
const exceptionMessage = "Test exception message";
|
||||
test.throws(function customRuleThrowsCall() {
|
||||
markdownlint.sync({
|
||||
"customRules": [
|
||||
|
@ -1988,7 +1990,7 @@ function customRulesThrowForFileSync(test) {
|
|||
module.exports.customRulesThrowForString =
|
||||
function customRulesThrowForString(test) {
|
||||
test.expect(4);
|
||||
var exceptionMessage = "Test exception message";
|
||||
const exceptionMessage = "Test exception message";
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
{
|
||||
|
@ -2015,7 +2017,7 @@ function customRulesThrowForString(test) {
|
|||
|
||||
module.exports.customRulesOnErrorNull = function customRulesOnErrorNull(test) {
|
||||
test.expect(4);
|
||||
var options = {
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
@ -2051,13 +2053,13 @@ module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) {
|
|||
[ "context", [ 10, [] ] ],
|
||||
[ "range", [ 10, [], [ 10 ], [ 10, null ], [ 10, 11, 12 ] ] ]
|
||||
].forEach(function forProperty(property) {
|
||||
var propertyName = property[0];
|
||||
const propertyName = property[0];
|
||||
property[1].forEach(function forPropertyValue(propertyValue) {
|
||||
var badObject = {
|
||||
const badObject = {
|
||||
"lineNumber": 1
|
||||
};
|
||||
badObject[propertyName] = propertyValue;
|
||||
var options = {
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
@ -2089,7 +2091,7 @@ module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) {
|
|||
|
||||
module.exports.customRulesOnErrorLazy = function customRulesOnErrorLazy(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
@ -2111,7 +2113,7 @@ module.exports.customRulesOnErrorLazy = function customRulesOnErrorLazy(test) {
|
|||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
var expectedResult = {
|
||||
const expectedResult = {
|
||||
"string": [
|
||||
{
|
||||
"lineNumber": 1,
|
||||
|
@ -2137,7 +2139,7 @@ module.exports.customRulesDoc = function customRulesDoc(test) {
|
|||
}
|
||||
}, function callback(err, actual) {
|
||||
test.ifError(err);
|
||||
var expected = { "doc/CustomRules.md": [] };
|
||||
const expected = { "doc/CustomRules.md": [] };
|
||||
test.deepEqual(actual, expected, "Unexpected issues.");
|
||||
test.done();
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ module.exports = {
|
|||
params.tokens.filter(function filterToken(token) {
|
||||
return token.type === "blockquote_open";
|
||||
}).forEach(function forToken(blockquote) {
|
||||
var lines = blockquote.map[1] - blockquote.map[0];
|
||||
const lines = blockquote.map[1] - blockquote.map[0];
|
||||
onError({
|
||||
"lineNumber": blockquote.lineNumber,
|
||||
"detail": "Blockquote spans " + lines + " line(s).",
|
||||
|
|
|
@ -7,9 +7,9 @@ module.exports = {
|
|||
"description": "Rule that reports an error every N lines",
|
||||
"tags": [ "test" ],
|
||||
"function": function rule(params, onError) {
|
||||
var n = params.config.n || 2;
|
||||
const n = params.config.n || 2;
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
var lineNumber = lineIndex + 1;
|
||||
const lineNumber = lineIndex + 1;
|
||||
if ((lineNumber % n) === 0) {
|
||||
onError({
|
||||
"lineNumber": lineNumber,
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
inline.children.filter(function filterChild(child) {
|
||||
return child.type === "text";
|
||||
}).forEach(function forChild(text) {
|
||||
var index = text.content.toLowerCase().indexOf("ex");
|
||||
const index = text.content.toLowerCase().indexOf("ex");
|
||||
if (index !== -1) {
|
||||
onError({
|
||||
"lineNumber": text.lineNumber,
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var anyBlockquote = require("./any-blockquote");
|
||||
const anyBlockquote = require("./any-blockquote");
|
||||
module.exports.anyBlockquote = anyBlockquote;
|
||||
|
||||
var everyNLines = require("./every-n-lines");
|
||||
const everyNLines = require("./every-n-lines");
|
||||
module.exports.everyNLines = everyNLines;
|
||||
|
||||
var firstLine = require("./first-line");
|
||||
const firstLine = require("./first-line");
|
||||
module.exports.firstLine = firstLine;
|
||||
|
||||
var lettersEX = require("./letters-E-X");
|
||||
const lettersEX = require("./letters-E-X");
|
||||
module.exports.lettersEX = lettersEX;
|
||||
|
||||
module.exports.all = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue