Files
NapCatQQ/.pnpm-store/v3/files/8c/816af2b3df5146ab4ec855c8adea638ed10ea625d592f06951e1ab102418fc57c12f2e277d633e5a7931abf754c153f00ed6d96205a79dfce8062efbcb2d3b
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

60 lines
2.0 KiB
Plaintext

import { createRule } from '../utils/index.js';
export default createRule({
name: 'no-mutable-exports',
meta: {
type: 'suggestion',
docs: {
category: 'Helpful warnings',
description: 'Forbid the use of mutable exports with `var` or `let`.',
},
schema: [],
messages: {
noMutable: "Exporting mutable '{{kind}}' binding, use 'const' instead.",
},
},
defaultOptions: [],
create(context) {
function checkDeclaration(node) {
if ('kind' in node && (node.kind === 'var' || node.kind === 'let')) {
context.report({
node,
messageId: 'noMutable',
data: {
kind: node.kind,
},
});
}
}
function checkDeclarationsInScope({ variables }, name) {
for (const variable of variables) {
if (variable.name === name) {
for (const def of variable.defs) {
if (def.type === 'Variable' && def.parent) {
checkDeclaration(def.parent);
}
}
}
}
}
return {
ExportDefaultDeclaration(node) {
const scope = context.sourceCode.getScope(node);
if ('name' in node.declaration) {
checkDeclarationsInScope(scope, node.declaration.name);
}
},
ExportNamedDeclaration(node) {
const scope = context.sourceCode.getScope(node);
if (node.declaration) {
checkDeclaration(node.declaration);
}
else if (!node.source) {
for (const specifier of node.specifiers) {
checkDeclarationsInScope(scope, specifier.local.name);
}
}
},
};
},
});
//# sourceMappingURL=no-mutable-exports.js.map