Files
NapCatQQ/.pnpm-store/v3/files/50/24fb430f99de73b0328ec195b4348406b5def282fbe204edc41f7f019251b63364157911864c251c0d307ee865abebec8efed25ef92f4be3f7ff1195b27615
T
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

90 lines
2.3 KiB
Plaintext

'use strict';
var utils = require('../utils.js');
require('eslint-visitor-keys');
require('espree');
require('estraverse');
var noMixedSpacesAndTabs = utils.createRule({
name: "no-mixed-spaces-and-tabs",
package: "js",
meta: {
type: "layout",
docs: {
description: "Disallow mixed spaces and tabs for indentation"
},
schema: [
{
oneOf: [
{
type: "string",
enum: ["smart-tabs"]
},
{
type: "boolean"
}
]
}
],
messages: {
mixedSpacesAndTabs: "Mixed spaces and tabs."
}
},
create(context) {
const sourceCode = context.sourceCode;
let smartTabs;
switch (context.options[0]) {
case true:
// Support old syntax, maybe add deprecation warning here
case "smart-tabs":
smartTabs = true;
break;
default:
smartTabs = false;
}
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"
});
}
}
}
});
}
};
}
});
module.exports = noMixedSpacesAndTabs;