2 * @fileoverview Rule to disallow specified names in exports
3 * @author Milos Djermanovic
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
17 description: "disallow specified names in exports",
18 category: "ECMAScript 6",
20 url: "https://eslint.org/docs/rules/no-restricted-exports"
26 restrictedNamedExports: {
34 additionalProperties: false
38 restrictedNamed: "'{{name}}' is restricted from being used as an exported name."
44 const restrictedNames = new Set(context.options[0] && context.options[0].restrictedNamedExports);
47 * Checks and reports given exported identifier.
48 * @param {ASTNode} node exported `Identifier` node to check.
51 function checkExportedName(node) {
52 const name = node.name;
54 if (restrictedNames.has(name)) {
57 messageId: "restrictedNamed",
64 ExportAllDeclaration(node) {
66 checkExportedName(node.exported);
70 ExportNamedDeclaration(node) {
71 const declaration = node.declaration;
74 if (declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") {
75 checkExportedName(declaration.id);
76 } else if (declaration.type === "VariableDeclaration") {
77 context.getDeclaredVariables(declaration)
78 .map(v => v.defs.find(d => d.parent === declaration))
79 .map(d => d.name) // Identifier nodes
80 .forEach(checkExportedName);
85 .forEach(checkExportedName);