UNPKG

eslint-plugin-export-scope

Version:

Don't leak LOCAL utils, states, components into the global scope

36 lines 1.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateScopeFileScopePath = void 0; const utils_1 = require("@typescript-eslint/utils"); const path_1 = require("path"); const checkIsImportable_1 = require("../checkIsImportable"); const utils_2 = require("../utils"); const fs_1 = __importDefault(require("fs")); const validateScopeFileScopePath = (context, node) => { if (![checkIsImportable_1.SCOPE_TS_FILE_NAME, checkIsImportable_1.SCOPE_JS_FILE_NAME].includes((0, path_1.basename)(context.filename))) return; const exportDir = (0, path_1.dirname)(context.filename); node.loc.start.column += 1; node.loc.end.column -= 1; if (typeof node.value !== "string") { return; } const fullPath = (0, utils_2.getFullScopePath)(exportDir, node.value); if (!fullPath || node.value === "*") return; if (node.parent.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) { if (!exportDir.toLowerCase().startsWith(fullPath.toLowerCase())) { return context.report({ node, messageId: "onlyParents", loc: node.loc }); } } if (["ArrayExpression", "ExportDefaultDeclaration"].includes(node.parent.type)) { if (!fs_1.default.existsSync(fullPath)) { context.report({ node, messageId: "invalidPath", data: { identifier: fullPath }, loc: node.loc }); } } }; exports.validateScopeFileScopePath = validateScopeFileScopePath; //# sourceMappingURL=validateScopeFileScopePath.js.map