no-amd.js 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
  3. //------------------------------------------------------------------------------
  4. // Rule Definition
  5. //------------------------------------------------------------------------------
  6. module.exports = {
  7. meta: {
  8. type: 'suggestion',
  9. docs: {
  10. category: 'Module systems',
  11. description: 'Forbid AMD `require` and `define` calls.',
  12. url: (0, _docsUrl2['default'])('no-amd') },
  13. schema: [] },
  14. create: function () {function create(context) {
  15. return {
  16. CallExpression: function () {function CallExpression(node) {
  17. if (context.getScope().type !== 'module') {return;}
  18. if (node.callee.type !== 'Identifier') {return;}
  19. if (node.callee.name !== 'require' && node.callee.name !== 'define') {return;}
  20. // todo: capture define((require, module, exports) => {}) form?
  21. if (node.arguments.length !== 2) {return;}
  22. var modules = node.arguments[0];
  23. if (modules.type !== 'ArrayExpression') {return;}
  24. // todo: check second arg type? (identifier or callback)
  25. context.report(node, 'Expected imports instead of AMD ' + String(node.callee.name) + '().');
  26. }return CallExpression;}() };
  27. }return create;}() }; /**
  28. * @fileoverview Rule to prefer imports to AMD
  29. * @author Jamund Ferguson
  30. */
  31. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbWQuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwiZGVzY3JpcHRpb24iLCJ1cmwiLCJzY2hlbWEiLCJjcmVhdGUiLCJjb250ZXh0IiwiQ2FsbEV4cHJlc3Npb24iLCJub2RlIiwiZ2V0U2NvcGUiLCJjYWxsZWUiLCJuYW1lIiwiYXJndW1lbnRzIiwibGVuZ3RoIiwibW9kdWxlcyIsInJlcG9ydCJdLCJtYXBwa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