2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import { addErrorContext } from "../helpers/helpers.cjs";
|
|
|
|
import { filterByTypesCached } from "./cache.mjs";
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2019-10-01 22:12:12 -07:00
|
|
|
const dollarCommandRe = /^(\s*)(\$\s+)/;
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
/** @type {import("./markdownlint.mjs").Rule} */
|
|
|
|
export default {
|
2018-01-21 21:44:25 -08:00
|
|
|
"names": [ "MD014", "commands-show-output" ],
|
|
|
|
"description": "Dollar signs used before commands without showing output",
|
|
|
|
"tags": [ "code" ],
|
2024-06-22 15:12:37 -07:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD014(params, onError) {
|
2024-08-24 22:05:16 -07:00
|
|
|
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
2024-10-09 22:42:36 -07:00
|
|
|
const codeFlowValues = codeBlock.children.filter((child) => child.type === "codeFlowValue");
|
2024-09-01 16:16:05 -07:00
|
|
|
const dollarMatches = codeFlowValues
|
|
|
|
.map((codeFlowValue) => ({
|
2024-06-22 15:12:37 -07:00
|
|
|
"result": codeFlowValue.text.match(dollarCommandRe),
|
|
|
|
"startColumn": codeFlowValue.startColumn,
|
|
|
|
"startLine": codeFlowValue.startLine,
|
|
|
|
"text": codeFlowValue.text
|
2024-09-01 16:16:05 -07:00
|
|
|
}))
|
|
|
|
.filter((dollarMatch) => dollarMatch.result);
|
2024-06-22 15:12:37 -07:00
|
|
|
if (dollarMatches.length === codeFlowValues.length) {
|
|
|
|
for (const dollarMatch of dollarMatches) {
|
|
|
|
// @ts-ignore
|
|
|
|
const column = dollarMatch.startColumn + dollarMatch.result[1].length;
|
|
|
|
// @ts-ignore
|
|
|
|
const length = dollarMatch.result[2].length;
|
|
|
|
addErrorContext(
|
|
|
|
onError,
|
|
|
|
dollarMatch.startLine,
|
|
|
|
dollarMatch.text,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
[ column, length ],
|
|
|
|
{
|
|
|
|
"editColumn": column,
|
|
|
|
"deleteCount": length
|
2020-01-18 21:28:42 -08:00
|
|
|
}
|
2024-06-22 15:12:37 -07:00
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2024-06-22 15:12:37 -07:00
|
|
|
}
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|