forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd014.js
53 lines (49 loc) · 1.53 KB
/
md014.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// @ts-check
"use strict";
const { addErrorContext, filterTokens } = require("../helpers");
const dollarCommandRe = /^(\s*)(\$\s+)/;
module.exports = {
"names": [ "MD014", "commands-show-output" ],
"description": "Dollar signs used before commands without showing output",
"tags": [ "code" ],
"function": function MD014(params, onError) {
for (const type of [ "code_block", "fence" ]) {
filterTokens(params, type, (token) => {
const margin = (token.type === "fence") ? 1 : 0;
const dollarInstances = [];
let allDollars = true;
for (let i = token.map[0] + margin; i < token.map[1] - margin; i++) {
const line = params.lines[i];
const lineTrim = line.trim();
if (lineTrim) {
const match = dollarCommandRe.exec(line);
if (match) {
const column = match[1].length + 1;
const length = match[2].length;
dollarInstances.push([ i, lineTrim, column, length ]);
} else {
allDollars = false;
}
}
}
if (allDollars) {
for (const instance of dollarInstances) {
const [ i, lineTrim, column, length ] = instance;
addErrorContext(
onError,
i + 1,
lineTrim,
null,
null,
[ column, length ],
{
"editColumn": column,
"deleteCount": length
}
);
}
}
});
}
}
};