2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorContext, filterTokens, newLineRe, rangeFromRegExp } =
|
|
|
|
require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const dollarCommandRe = /^(\s*)(\$\s)/;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD014", "commands-show-output" ],
|
|
|
|
"description": "Dollar signs used before commands without showing output",
|
|
|
|
"tags": [ "code" ],
|
|
|
|
"function": function MD014(params, onError) {
|
|
|
|
[ "code_block", "fence" ].forEach(function forType(type) {
|
2019-04-13 11:18:57 -07:00
|
|
|
filterTokens(params, type, function forToken(token) {
|
2018-04-27 22:05:34 -07:00
|
|
|
let allBlank = true;
|
2019-04-13 11:18:57 -07:00
|
|
|
if (token.content && token.content.split(newLineRe)
|
2018-01-21 21:44:25 -08:00
|
|
|
.every(function forLine(line) {
|
|
|
|
return !line || (allBlank = false) || dollarCommandRe.test(line);
|
|
|
|
}) && !allBlank) {
|
2019-04-13 11:18:57 -07:00
|
|
|
addErrorContext(onError, token.lineNumber,
|
|
|
|
token.content.split(newLineRe)[0].trim(), null, null,
|
|
|
|
rangeFromRegExp(token.line, dollarCommandRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|