mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-11-29 19:05:22 +01:00
105 lines
14 KiB
JavaScript
105 lines
14 KiB
JavaScript
|
'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 _importType = require('../core/importType');
|
||
|
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: {
|
||
|
oneOf: [
|
||
|
{
|
||
|
description: 'maximum dependency depth to traverse',
|
||
|
type: 'integer',
|
||
|
minimum: 1 },
|
||
|
|
||
|
{
|
||
|
enum: ['∞'],
|
||
|
type: 'string' }] },
|
||
|
|
||
|
|
||
|
|
||
|
ignoreExternal: {
|
||
|
description: 'ignore external modules',
|
||
|
type: 'boolean',
|
||
|
default: false } })] },
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
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 = typeof options.maxDepth === 'number' ? options.maxDepth : Infinity;
|
||
|
const ignoreModule = name => options.ignoreExternal ? (0, _importType.isExternalModule)(name) : false;
|
||
|
|
||
|
function checkSourceValue(sourceNode, importer) {
|
||
|
if (ignoreModule(sourceNode.value)) {
|
||
|
return; // ignore external modules
|
||
|
}
|
||
|
|
||
|
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 (ignoreModule(source.value)) 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jeWNsZS5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwibWF4RGVwdGgiLCJvbmVPZiIsImRlc2NyaXB0aW9uIiwibWluaW11bSIsImVudW0iLCJpZ25vcmVFeHRlcm5hbCIsImRlZmF1bHQiLCJjcmVhdGUiLCJjb250ZXh0IiwibXlQYXRoIiwiZ2V0RmlsZW5hbWUiLCJvcHRpb25zIiwiSW5maW5pdHkiLCJpZ25vcmVNb2R1bGUiLCJuYW1lIiwiY2hlY2tTb3VyY2VWYWx1ZSIsInNvdXJjZU5vZGUiLCJpbXBvcnRlciIsInZhbHVlIiwiaW1wb3J0ZWQiLCJFeHBvcnRzIiwiZ2V0IiwiaW1wb3J0S2luZCIsInBhdGgiLCJ1bnRyYXZlcnNlZCIsIm1nZXQiLCJyb3V0ZSIsInRyYXZlcnNlZCIsIlNldCIsImRldGVjdEN5Y2xlIiwibSIsImhhcyIsImFkZCIsImltcG9ydHMiLCJnZXR0ZXIiLCJzb3VyY2UiLCJsZW5ndGgiLCJwdXNoIiwiY29uY2F0IiwibmV4dCIsInNoaWZ0IiwibWVzc2FnZSIsInJvdXRlU3RyaW5nIiwicmVwb3J0IiwibWFwIiwicyIsImxvYyIsInN0YXJ0IiwibGluZSIsImpvaW4iXSwibWFwcGluZ3MiOiJzb0JBQUE7Ozs7O0FBS0EseUM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