katoikia-app/web-ui/web-react/node_modules/eslint-plugin-import/lib/rules/no-cycle.js

105 lines
12 KiB
JavaScript
Raw Normal View History

2022-07-06 04:15:11 +00:00
'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
* @fileOverview Ensures that no imported module imports the linted module.
* @author Ben Mosher
*/
var _ExportMap = require('../ExportMap');
var _ExportMap2 = _interopRequireDefault(_ExportMap);
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');
var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// todo: cache cycles / deep relationships for faster repeat evaluation
module.exports = {
meta: {
type: 'suggestion',
docs: { url: (0, _docsUrl2.default)('no-cycle') },
schema: [(0, _moduleVisitor.makeOptionsSchema)({
maxDepth: {
description: 'maximum dependency depth to traverse',
type: 'integer',
minimum: 1
}
})]
},
create: function (context) {
const myPath = context.getFilename();
if (myPath === '<text>') return {}; // can't cycle-check a non-file
const options = context.options[0] || {};
const maxDepth = options.maxDepth || Infinity;
function checkSourceValue(sourceNode, importer) {
const imported = _ExportMap2.default.get(sourceNode.value, context);
if (importer.importKind === 'type') {
return; // no Flow import resolution
}
if (imported == null) {
return; // no-unresolved territory
}
if (imported.path === myPath) {
return; // no-self-import territory
}
const untraversed = [{ mget: () => imported, route: [] }];
const traversed = new Set();
function detectCycle(_ref) {
let mget = _ref.mget,
route = _ref.route;
const m = mget();
if (m == null) return;
if (traversed.has(m.path)) return;
traversed.add(m.path);
for (let _ref2 of m.imports) {
var _ref3 = _slicedToArray(_ref2, 2);
let path = _ref3[0];
var _ref3$ = _ref3[1];
let getter = _ref3$.getter;
let source = _ref3$.source;
if (path === myPath) return true;
if (traversed.has(path)) continue;
if (route.length + 1 < maxDepth) {
untraversed.push({
mget: getter,
route: route.concat(source)
});
}
}
}
while (untraversed.length > 0) {
const next = untraversed.shift(); // bfs!
if (detectCycle(next)) {
const message = next.route.length > 0 ? `Dependency cycle via ${routeString(next.route)}` : 'Dependency cycle detected.';
context.report(importer, message);
return;
}
}
}
return (0, _moduleVisitor2.default)(checkSourceValue, context.options[0]);
}
};
function routeString(route) {
return route.map(s => `${s.value}:${s.loc.start.line}`).join('=>');
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jeWNsZS5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwibWF4RGVwdGgiLCJkZXNjcmlwdGlvbiIsIm1pbmltdW0iLCJjcmVhdGUiLCJjb250ZXh0IiwibXlQYXRoIiwiZ2V0RmlsZW5hbWUiLCJvcHRpb25zIiwiSW5maW5pdHkiLCJjaGVja1NvdXJjZVZhbHVlIiwic291cmNlTm9kZSIsImltcG9ydGVyIiwiaW1wb3J0ZWQiLCJFeHBvcnRzIiwiZ2V0IiwidmFsdWUiLCJpbXBvcnRLaW5kIiwicGF0aCIsInVudHJhdmVyc2VkIiwibWdldCIsInJvdXRlIiwidHJhdmVyc2VkIiwiU2V0IiwiZGV0ZWN0Q3ljbGUiLCJtIiwiaGFzIiwiYWRkIiwiaW1wb3J0cyIsImdldHRlciIsInNvdXJjZSIsImxlbmd0aCIsInB1c2giLCJjb25jYXQiL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