max-dependencies.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
  2. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  3. const DEFAULT_MAX = 10;
  4. const countDependencies = (dependencies, lastNode, context) => {var _ref =
  5. context.options[0] || { max: DEFAULT_MAX };const max = _ref.max;
  6. if (dependencies.size > max) {
  7. context.report(
  8. lastNode,
  9. `Maximum number of dependencies (${max}) exceeded.`);
  10. }
  11. };
  12. module.exports = {
  13. meta: {
  14. type: 'suggestion',
  15. docs: {
  16. url: (0, _docsUrl2.default)('max-dependencies') },
  17. schema: [
  18. {
  19. 'type': 'object',
  20. 'properties': {
  21. 'max': { 'type': 'number' } },
  22. 'additionalProperties': false }] },
  23. create: context => {
  24. const dependencies = new Set(); // keep track of dependencies
  25. let lastNode; // keep track of the last node to report on
  26. return Object.assign({
  27. 'Program:exit': function () {
  28. countDependencies(dependencies, lastNode, context);
  29. } },
  30. (0, _moduleVisitor2.default)(source => {
  31. dependencies.add(source.value);
  32. lastNode = source;
  33. }, { commonjs: true }));
  34. } };
  35. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9tYXgtZGVwZW5kZW5jaWVzLmpzIl0sIm5hbWVzIjpbIkRFRkFVTFRfTUFYIiwiY291bnREZXBlbmRlbmNpZXMiLCJkZXBlbmRlbmNpZXMiLCJsYXN0Tm9kZSIsImNvbnRleHQiLCJvcHRpb25zIiwibWF4Iiwic2l6ZSIsInJlcG9ydCIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJjcmVhdGUiLCJTZXQiLCJP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