'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,[encoded data, 4268 characters]