70 lines
5.8 KiB
JavaScript
70 lines
5.8 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: {
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL21heC1kZXBlbmRlbmNpZXMuanMiXSwibmFtZXMiOlsiREVGQVVMVF9NQVgiLCJjb3VudERlcGVuZGVuY2llcyIsImRlcGVuZGVuY2llcyIsImxhc3ROb2RlIiwiY29udGV4dCIsIm9wdGlvbnMiLCJtYXgiLCJzaXplIiwicmVwb3J0IiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiU2V0IiwiSW1wb3J0RGVjbGFyYXRpb24iLCJub2RlIiwiYWRkIiwic291cmNlIiwidmFsdWUiLCJDYWxsRXhwcmVzc2lvbiIsImFyZ3VtZW50cyIsInJlcXVpcmVQYXRoIl0sIm1hcHBpbmdzIjoiOzs7O0FBQUE7Ozs7QUFDQTs7Ozs7O0FBRUEsTUFBTUEsY0FBYyxFQUFwQjs7QUFFQSxNQUFNQyxvQkFBb0IsQ0FBQ0MsWUFBRCxFQUFlQyxRQUFmLEVBQXlCQyxPQUF6QixLQUFxQztBQUFBLGFBQy9DQSxRQUFRQyxPQUFSLENBQWdCLENBQWhCLEtBQXNCLEVBQUVDLEtBQUtOLFdBQVAsRUFEeUI7O0FBQUEsUUFDdERNLEdBRHNELFFBQ3REQSxHQURzRDs7O0FBRzdELE1BQUlKLGFBQWFLLElBQWIsR0FBb0JELEdBQXhCLEVBQTZCO0FBQzNCRixZQUFRSSxNQUFSLENBQ0VMLFFBREYsRUFFRyxtQ0FBa0NHLEdBQUksYUFGekM7QUFJRDtBQUNGLENBVEQ7O0FBV0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