no-amd.js 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. url: (0, _docsUrl2.default)('no-amd') },
  11. schema: [] },
  12. create: function (context) {
  13. return {
  14. 'CallExpression': function (node) {
  15. if (context.getScope().type !== 'module') return;
  16. if (node.callee.type !== 'Identifier') return;
  17. if (node.callee.name !== 'require' &&
  18. node.callee.name !== 'define') return;
  19. // todo: capture define((require, module, exports) => {}) form?
  20. if (node.arguments.length !== 2) return;
  21. const modules = node.arguments[0];
  22. if (modules.type !== 'ArrayExpression') return;
  23. // todo: check second arg type? (identifier or callback)
  24. context.report(node, `Expected imports instead of AMD ${node.callee.name}().`);
  25. } };
  26. } }; /**
  27. * @fileoverview Rule to prefer imports to AMD
  28. * @author Jamund Ferguson
  29. */
  30. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbWQuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJub2RlIiwiZ2V0U2NvcGUiLCJjYWxsZWUiLCJuYW1lIiwiYXJndW1lbnRzIiwibGVuZ3RoIiwibW9kdWxlcyIsInJlcG9ydCJdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFLQSxxQzs7QUFFQTtBQUNBO0FBQ0E7O0FBRUFBLE9BQU9DLE9BQVAsR0FBaUI7QUFDZkMsUUFBTTtBQUNKQyxVQUFNLFlBREY7QUFFSkMsVUFBTTtBQUN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