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;
|
2021-04-09 16:33:01 -07:00
|
|
|
const spacesPerTab = params.config.spaces_per_tab;
|
|
|
|
|
const spaceMultiplier = (spacesPerTab === undefined) ?
|
|
|
|
|
1 :
|
|
|
|
|
Math.max(0, Number(spacesPerTab));
|
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;
|
2019-08-24 22:55:51 -07:00
|
|
|
const length = match[0].length;
|
2019-08-21 21:02:09 -07:00
|
|
|
addError(
|
|
|
|
|
onError,
|
|
|
|
|
lineIndex + 1,
|
|
|
|
|
"Column: " + column,
|
|
|
|
|
null,
|
2019-08-24 22:55:51 -07:00
|
|
|
[ column, length ],
|
|
|
|
|
{
|
|
|
|
|
"editColumn": column,
|
|
|
|
|
"deleteCount": length,
|
2021-04-09 16:33:01 -07:00
|
|
|
"insertText": "".padEnd(length * spaceMultiplier)
|
2019-08-24 22:55:51 -07:00
|
|
|
});
|
2019-08-21 21:02:09 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|