54 lines
No EOL
5.9 KiB
JavaScript
54 lines
No EOL
5.9 KiB
JavaScript
'use strict';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 };}
|
|
|
|
var DEFAULT_MAX = 10;
|
|
var DEFAULT_IGNORE_TYPE_IMPORTS = false;
|
|
var TYPE_IMPORT = 'type';
|
|
|
|
var countDependencies = function countDependencies(dependencies, lastNode, context) {var _ref =
|
|
context.options[0] || { max: DEFAULT_MAX },max = _ref.max;
|
|
|
|
if (dependencies.size > max) {
|
|
context.report(lastNode, 'Maximum number of dependencies (' + String(max) + ') exceeded.');
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2['default'])('max-dependencies') },
|
|
|
|
|
|
schema: [
|
|
{
|
|
'type': 'object',
|
|
'properties': {
|
|
'max': { 'type': 'number' },
|
|
'ignoreTypeImports': { 'type': 'boolean' } },
|
|
|
|
'additionalProperties': false }] },
|
|
|
|
|
|
|
|
|
|
create: function () {function create(context) {var _ref2 =
|
|
|
|
|
|
context.options[0] || {},_ref2$ignoreTypeImpor = _ref2.ignoreTypeImports,ignoreTypeImports = _ref2$ignoreTypeImpor === undefined ? DEFAULT_IGNORE_TYPE_IMPORTS : _ref2$ignoreTypeImpor;
|
|
|
|
var dependencies = new Set(); // keep track of dependencies
|
|
var lastNode = void 0; // keep track of the last node to report on
|
|
|
|
return Object.assign({
|
|
'Program:exit': function () {function ProgramExit() {
|
|
countDependencies(dependencies, lastNode, context);
|
|
}return ProgramExit;}() },
|
|
(0, _moduleVisitor2['default'])(function (source, _ref3) {var importKind = _ref3.importKind;
|
|
if (importKind !== TYPE_IMPORT || !ignoreTypeImports) {
|
|
dependencies.add(source.value);
|
|
}
|
|
lastNode = source;
|
|
}, { commonjs: true }));
|
|
}return create;}() };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9tYXgtZGVwZW5kZW5jaWVzLmpzIl0sIm5hbWVzIjpbIkRFRkFVTFRfTUFYIiwiREVGQVVMVF9JR05PUkVfVFlQRV9JTVBPUlRTIiwiVFlQRV9JTVBPUlQiLCJjb3VudERlcGVuZGVuY2llcyIsImRlcGVuZGVuY2llcyIsImxhc3ROb2RlIiwiY29udGV4dCIsIm9wdGlvbnMiLCJtYXgiLCJzaXplIiwicmVwb3J0IiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImlnbm9yZVR5cGVJbXBvcnRzIiwiU2V0IiwiT2JqZWN0IiwiYXNzaWduIiwic291cmNlIiwiaW1wb3J0S2luZCIsImFkZCIsInZhbHVlIiwiY29tbW9uanMiXSwibWFwcGluZ3MiOiJhQUFBLGtFO0FBQ0EscUM7O0FBRUEsSUFBTUEsY0FBYyxFQUFwQjtBQUNBLElBQU1DLDhCQUE4QixLQUFwQztBQUNBLElBQU1DLGNBQWMsTUFBcEI7O0FBRUEsSUFBTUMsb0JBQW9CLFNBQXBCQSxpQkFBb0IsQ0FBQ0MsWUFBRCxFQUFlQyxRQUFmLEVBQXlCQyxPQUF6QixFQUFxQztBQUM3Q0EsVUFBUUMsT0FBUixDQUFnQixDQUFoQixLQUFzQixFQUFFQyxLQUFLUixXQUFQLEVBRHVCLENBQ3JEUSxHQURxRCxRQUNyREEsR0FEcUQ7O0FBRzdELE1BQUlKLGFBQWFLLElBQWIsR0FBb0JELEdBQXhCLEVBQTZCO0FBQzNCRixZQUFRSSxNQUFSLENBQWVMLFFBQWYsOENBQTRERyxHQUE1RDtBQUNEO0FBQ0YsQ0FORDs7QUFRQUcsT0FBT0MsT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