katoikia-app/web-ui/web-react/node_modules/eslint-plugin-import/lib/rules/max-dependencies.js

71 lines
5.9 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"); } }; }();
var _staticRequire = require('../core/staticRequire');
var _staticRequire2 = _interopRequireDefault(_staticRequire);
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const DEFAULT_MAX = 10;
const countDependencies = (dependencies, lastNode, context) => {
var _ref = context.options[0] || { max: DEFAULT_MAX };
const max = _ref.max;
if (dependencies.size > max) {
context.report(lastNode, `Maximum number of dependencies (${max}) exceeded.`);
}
};
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2.default)('max-dependencies')
},
schema: [{
'type': 'object',
'properties': {
'max': { 'type': 'number' }
},
'additionalProperties': false
}]
},
create: context => {
const dependencies = new Set(); // keep track of dependencies
let lastNode; // keep track of the last node to report on
return {
ImportDeclaration(node) {
dependencies.add(node.source.value);
lastNode = node.source;
},
CallExpression(node) {
if ((0, _staticRequire2.default)(node)) {
var _node$arguments = _slicedToArray(node.arguments, 1);
const requirePath = _node$arguments[0];
dependencies.add(requirePath.value);
lastNode = node;
}
},
'Program:exit': function () {
countDependencies(dependencies, lastNode, context);
}
};
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy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