2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-08-21 21:02:09 -07:00
|
|
|
const { addError, forEachLine } = require("../helpers");
|
2019-04-10 21:26:59 -07:00
|
|
|
const { lineMetadata } = require("./cache");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2019-08-21 21:02:09 -07:00
|
|
|
const tabRe = /\t+/g;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD010", "no-hard-tabs" ],
|
|
|
|
"description": "Hard tabs",
|
|
|
|
"tags": [ "whitespace", "hard_tab" ],
|
|
|
|
"function": function MD010(params, onError) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const codeBlocks = params.config.code_blocks;
|
|
|
|
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
2019-04-10 21:26:59 -07:00
|
|
|
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
2019-08-21 21:02:09 -07:00
|
|
|
if (!inCode || includeCodeBlocks) {
|
|
|
|
let match = null;
|
|
|
|
while ((match = tabRe.exec(line)) !== null) {
|
|
|
|
const column = match.index + 1;
|
|
|
|
addError(
|
|
|
|
onError,
|
|
|
|
lineIndex + 1,
|
|
|
|
"Column: " + column,
|
|
|
|
null,
|
|
|
|
[ column, match[0].length ]);
|
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|