internet-programming/lab3/node_modules/eslint-plugin-import/lib/rules/max-dependencies.js

60 lines
6.2 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: {
category: 'Style guide',
description: 'Enforce the maximum number of dependencies a module can have.',
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9tYXgtZGVwZW5kZW5jaWVzLmpzIl0sIm5hbWVzIjpbIkRFR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