Files
SnowLuma/.pnpm-store/v11/files/84/5063fa437c24b6c8bd72331a2187697073281f40315b0bffeb16aa3ce46ba8ff29f3c04085071b69410837bb3864ecd7d0f8c760f687cab4df70331bae371f
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Skipped
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

54 lines
1.7 KiB
Plaintext

import { f as createRule } from "../utils.js";
var no_mixed_spaces_and_tabs_default = createRule({
name: "no-mixed-spaces-and-tabs",
meta: {
type: "layout",
docs: { description: "Disallow mixed spaces and tabs for indentation" },
schema: [{ oneOf: [{
type: "string",
enum: ["smart-tabs"]
}, { type: "boolean" }] }],
defaultOptions: [false],
messages: { mixedSpacesAndTabs: "Mixed spaces and tabs." }
},
create(context, [style]) {
const sourceCode = context.sourceCode;
const smartTabs = typeof style === "boolean" ? style : style === "smart-tabs";
return { "Program:exit": function(node) {
const lines = sourceCode.lines;
const comments = sourceCode.getAllComments();
const ignoredCommentLines = /* @__PURE__ */ new Set();
comments.forEach((comment) => {
for (let i = comment.loc.start.line + 1; i <= comment.loc.end.line; i++) ignoredCommentLines.add(i);
});
let regex = /^(?=( +|\t+))\1(?:\t| )/u;
if (smartTabs) regex = /^(?=(\t*))\1(?=( +))\2\t/u;
lines.forEach((line, i) => {
const match = regex.exec(line);
if (match) {
const lineNumber = i + 1;
const loc = {
start: {
line: lineNumber,
column: match[0].length - 2
},
end: {
line: lineNumber,
column: match[0].length
}
};
if (!ignoredCommentLines.has(lineNumber)) {
const containingNode = sourceCode.getNodeByRangeIndex(sourceCode.getIndexFromLoc(loc.start));
if (!(containingNode && ["Literal", "TemplateElement"].includes(containingNode.type))) context.report({
node,
loc,
messageId: "mixedSpacesAndTabs"
});
}
}
});
} };
}
});
export { no_mixed_spaces_and_tabs_default as t };