mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-29 03:45:15 +00:00
131 lines
19 KiB
JavaScript
131 lines
19 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 _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
|
|
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 };}function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {arr2[i] = arr[i];}return arr2;} else {return Array.from(arr);}}
|
|
|
|
// 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 () {function create(context) {
|
|
var myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
|
|
if (myPath === '<text>') return {}; // can't cycle-check a non-file
|
|
|
|
var options = context.options[0] || {};
|
|
var maxDepth = typeof options.maxDepth === 'number' ? options.maxDepth : Infinity;
|
|
var ignoreModule = function () {function ignoreModule(name) {return options.ignoreExternal && (0, _importType.isExternalModule)(
|
|
name,
|
|
context.settings,
|
|
(0, _resolve2['default'])(name, context),
|
|
context);}return ignoreModule;}();
|
|
|
|
|
|
function checkSourceValue(sourceNode, importer) {
|
|
if (ignoreModule(sourceNode.value)) {
|
|
return; // ignore external modules
|
|
}
|
|
|
|
if (
|
|
importer.type === 'ImportDeclaration' && (
|
|
// import type { Foo } (TS and Flow)
|
|
importer.importKind === 'type' ||
|
|
// import { type Foo } (Flow)
|
|
importer.specifiers.every(function (_ref) {var importKind = _ref.importKind;return importKind === 'type';})))
|
|
|
|
{
|
|
return; // ignore type imports
|
|
}
|
|
|
|
var imported = _ExportMap2['default'].get(sourceNode.value, context);
|
|
|
|
if (imported == null) {
|
|
return; // no-unresolved territory
|
|
}
|
|
|
|
if (imported.path === myPath) {
|
|
return; // no-self-import territory
|
|
}
|
|
|
|
var untraversed = [{ mget: function () {function mget() {return imported;}return mget;}(), route: [] }];
|
|
var traversed = new Set();
|
|
function detectCycle(_ref2) {var mget = _ref2.mget,route = _ref2.route;
|
|
var m = mget();
|
|
if (m == null) return;
|
|
if (traversed.has(m.path)) return;
|
|
traversed.add(m.path);var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try {
|
|
|
|
for (var _iterator = m.imports[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var _ref3 = _step.value;var _ref4 = _slicedToArray(_ref3, 2);var path = _ref4[0];var _ref4$ = _ref4[1];var getter = _ref4$.getter;var declarations = _ref4$.declarations;
|
|
if (traversed.has(path)) continue;
|
|
var toTraverse = [].concat(_toConsumableArray(declarations)).filter(function (_ref5) {var source = _ref5.source,isOnlyImportingTypes = _ref5.isOnlyImportingTypes;return (
|
|
!ignoreModule(source.value) &&
|
|
// Ignore only type imports
|
|
!isOnlyImportingTypes);});
|
|
|
|
/*
|
|
Only report as a cycle if there are any import declarations that are considered by
|
|
the rule. For example:
|
|
a.ts:
|
|
import { foo } from './b' // should not be reported as a cycle
|
|
b.ts:
|
|
import type { Bar } from './a'
|
|
*/
|
|
|
|
|
|
if (path === myPath && toTraverse.length > 0) return true;
|
|
if (route.length + 1 < maxDepth) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try {
|
|
for (var _iterator2 = toTraverse[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref6 = _step2.value;var source = _ref6.source;
|
|
untraversed.push({ mget: getter, route: route.concat(source) });
|
|
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}}
|
|
}
|
|
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}}
|
|
}
|
|
|
|
while (untraversed.length > 0) {
|
|
var next = untraversed.shift(); // bfs!
|
|
if (detectCycle(next)) {
|
|
var message = next.route.length > 0 ? 'Dependency cycle via ' + String(
|
|
routeString(next.route)) :
|
|
'Dependency cycle detected.';
|
|
context.report(importer, message);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
return (0, _moduleVisitor2['default'])(checkSourceValue, context.options[0]);
|
|
}return create;}() };
|
|
|
|
|
|
function routeString(route) {
|
|
return route.map(function (s) {return String(s.value) + ':' + String(s.loc.start.line);}).join('=>');
|
|
}
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jeWNsZS5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwibWF4RGVwdGgiLCJvbmVPZiIsImRlc2NyaXB0aW9uIiwibWluaW11bSIsImlnbm9yZUV4dGVybmFsIiwiY3JlYXRlIiwiY29udGV4dCIsIm15UGF0aCIsImdldFBoeXNpY2FsRmlsZW5hbWUiLCJnZXRGaWxlbmFtZSIsIm9wdGlvbnMiLCJJbmZpbml0eSIsImlnbm9yZU1vZHVsZSIsIm5hbWUiLCJzZXR0aW5ncyIsImNoZWNrU291cmNlVmFsdWUiLCJzb3VyY2VOb2RlIiwiaW1wb3J0ZXIiLCJ2YWx1ZSIsImltcG9ydEtpbmQiLCJzcGVjaWZpZXJzIiwiZXZlcnkiLCJpbXBvcnRlZCIsIkV4cG9ydHMiLCJnZXQiLCJwYXRoIiwidW50cmF2ZXJzZWQiLCJtZ2V0Iiwicm91dGUiLCJ0cmF2ZXJzZWQiLCJTZXQiLCJkZXRlY3RDeWNsZSIsIm0iLCJoYXMiLCJhZGQiLCJpbXBvcnRzIiwiZ2V0dGVyIiwiZGVjbGFyYXRpb25zIiwidG9UcmF2ZXJzZSIsImZpbHRlciIsInNvdXJjZSIsImlzT25seUltcG9ydGluZ1R5cGVzIiwibGVuZ3RoIiwicHVzaCIsImNvbmNhdCIsIm5leHQiLCJzaGlmdCIsIm1lc3NhZ2UiLCJyb3V0ZVN0cmluZyIsInJlcG9ydCIsIm1hcCIsInMiLCJsb2MiLCJzdGFydCIsImxpbmUiLCJqb2luIl0sIm1hcHBpbmdzIjoic29CQUFBOzs7OztBQUtB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