UNPKG

eslint-plugin-no-barrel-files

Version:

ESLint plugin to disallow [barrel files](https://github.com/basarat/typescript-book/blob/master/docs/tips/barrel.md).

72 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("@typescript-eslint/utils"); const noBarrelFiles = { defaultOptions: [], meta: { type: 'suggestion', docs: { url: 'https://github.com/art0rz/eslint-plugin-no-barrel-files', description: 'disallow barrel files', }, schema: [], messages: { noReExport: 'Do not re-export imported variable (`{{name}}`)', noExportAll: 'Do not use export all (`export * from ...`)', }, }, create(context) { const declaredImports = []; return { ExportDefaultDeclaration(node) { if (node.declaration.type === 'Identifier' && declaredImports.includes(node.declaration.name)) { context.report({ node, messageId: 'noReExport', data: { name: node.declaration.name, }, }); } }, ExportAllDeclaration(node) { context.report({ node, messageId: 'noExportAll', }); }, ExportNamedDeclaration(node) { var _a; if (((_a = node === null || node === void 0 ? void 0 : node.source) === null || _a === void 0 ? void 0 : _a.type) === 'Literal') { context.report({ node, messageId: 'noReExport', data: { name: node.source.value, }, }); } node.specifiers.forEach(specifier => { if (specifier.local.type === utils_1.AST_NODE_TYPES.Identifier && specifier.exported.type === utils_1.AST_NODE_TYPES.Identifier && declaredImports.includes(specifier.local.name)) { context.report({ node: specifier, messageId: 'noReExport', data: { name: specifier.exported.name, }, }); } }); }, ImportDeclaration(node) { node.specifiers.forEach(item => { declaredImports.push(item.local.name); }); }, }; }, }; exports.default = noBarrelFiles; //# sourceMappingURL=no-barrel-files.js.map