Path: blob/main/src/rules/no-mutable-exports.js
829 views
import docsUrl from '../docsUrl';12module.exports = {3meta: {4type: 'suggestion',5docs: {6url: docsUrl('no-mutable-exports'),7},8schema: [],9},1011create(context) {12function checkDeclaration(node) {13const { kind } = node;14if (kind === 'var' || kind === 'let') {15context.report(node, `Exporting mutable '${kind}' binding, use 'const' instead.`);16}17}1819function checkDeclarationsInScope({ variables }, name) {20for (const variable of variables) {21if (variable.name === name) {22for (const def of variable.defs) {23if (def.type === 'Variable' && def.parent) {24checkDeclaration(def.parent);25}26}27}28}29}3031function handleExportDefault(node) {32const scope = context.getScope();3334if (node.declaration.name) {35checkDeclarationsInScope(scope, node.declaration.name);36}37}3839function handleExportNamed(node) {40const scope = context.getScope();4142if (node.declaration) {43checkDeclaration(node.declaration);44} else if (!node.source) {45for (const specifier of node.specifiers) {46checkDeclarationsInScope(scope, specifier.local.name);47}48}49}5051return {52'ExportDefaultDeclaration': handleExportDefault,53'ExportNamedDeclaration': handleExportNamed,54};55},56};575859