'use strict'; var _docsUrl = require('../docsUrl'); var _docsUrl2 = _interopRequireDefault(_docsUrl); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const meta = { docs: { url: (0, _docsUrl2.default)('group-exports') } /* eslint-disable max-len */ };const errors = { ExportNamedDeclaration: 'Multiple named export declarations; consolidate all named exports into a single export declaration', AssignmentExpression: 'Multiple CommonJS exports; consolidate all exports into a single assignment to `module.exports`' /* eslint-enable max-len */ /** * Returns an array with names of the properties in the accessor chain for MemberExpression nodes * * Example: * * `module.exports = {}` => ['module', 'exports'] * `module.exports.property = true` => ['module', 'exports', 'property'] * * @param {Node} node AST Node (MemberExpression) * @return {Array} Array with the property names in the chain * @private */ };function accessorChain(node) { const chain = []; do { chain.unshift(node.property.name); if (node.object.type === 'Identifier') { chain.unshift(node.object.name); break; } node = node.object; } while (node.type === 'MemberExpression'); return chain; } function create(context) { const nodes = { modules: new Set(), commonjs: new Set() }; return { ExportNamedDeclaration(node) { nodes.modules.add(node); }, AssignmentExpression(node) { if (node.left.type !== 'MemberExpression') { return; } const chain = accessorChain(node.left); // Assignments to module.exports // Deeper assignments are ignored since they just modify what's already being exported // (ie. module.exports.exported.prop = true is ignored) if (chain[0] === 'module' && chain[1] === 'exports' && chain.length <= 3) { nodes.commonjs.add(node); return; } // Assignments to exports (exports.* = *) if (chain[0] === 'exports' && chain.length === 2) { nodes.commonjs.add(node); return; } }, 'Program:exit': function onExit() { // Report multiple `export` declarations (ES2015 modules) if (nodes.modules.size > 1) { nodes.modules.forEach(node => { context.report({ node, message: errors[node.type] }); }); } // Report multiple `module.exports` assignments (CommonJS) if (nodes.commonjs.size > 1) { nodes.commonjs.forEach(node => { context.report({ node, message: errors[node.type] }); }); } } }; } module.exports = { meta, create }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL2dyb3VwLWV4cG9ydHMuanMiXSwibmFtZXMiOlsibWV0YSIsImRvY3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