UNPKG

eslint-plugin-export-scope

Version:

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

43 lines 1.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateJsDoc = void 0; const esLintUtils_1 = require("./esLintUtils"); const path_1 = require("path"); const utils_1 = require("../utils"); const fs_1 = __importDefault(require("fs")); let cachedScopeDeclarations = []; const validateJsDoc = (context, node) => { const scopeDeclarations = (0, esLintUtils_1.getScopeDeclarations)(context.sourceCode.getAllComments()); if (scopeDeclarations.length === cachedScopeDeclarations.length && scopeDeclarations.every(({ path, type }, i) => { const cached = cachedScopeDeclarations[i]; return cached?.path === path && cached.type === type; })) { return; } cachedScopeDeclarations = scopeDeclarations; const exportDir = (0, path_1.dirname)(context.filename); scopeDeclarations.forEach(({ type, path, loc }) => { const fullPath = (0, utils_1.getFullScopePath)(exportDir, path); if (!fullPath || path === "*") return; if (type === "scope" || type === "scopeDefault") { if (!exportDir.toLowerCase().startsWith(fullPath.toLowerCase())) { return context.report({ node, messageId: "onlyParents", loc: (0, esLintUtils_1.getPathLoc)(context.sourceCode.text, loc) }); } } if (!fs_1.default.existsSync(fullPath)) { context.report({ node, messageId: "invalidPath", data: { identifier: fullPath }, loc: (0, esLintUtils_1.getPathLoc)(context.sourceCode.text, loc), }); } }); }; exports.validateJsDoc = validateJsDoc; //# sourceMappingURL=validateJsDoc.js.map