odin-js-fundamentals-part-4/node_modules/eslint-plugin-import/lib/rules/no-amd.js

47 lines
4.7 KiB
JavaScript

'use strict';
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Module systems',
description: 'Forbid AMD `require` and `define` calls.',
url: (0, _docsUrl2['default'])('no-amd') },
schema: [] },
create: function () {function create(context) {
return {
CallExpression: function () {function CallExpression(node) {
if (context.getScope().type !== 'module') {return;}
if (node.callee.type !== 'Identifier') {return;}
if (node.callee.name !== 'require' && node.callee.name !== 'define') {return;}
// todo: capture define((require, module, exports) => {}) form?
if (node.arguments.length !== 2) {return;}
var modules = node.arguments[0];
if (modules.type !== 'ArrayExpression') {return;}
// todo: check second arg type? (identifier or callback)
context.report(node, 'Expected imports instead of AMD ' + String(node.callee.name) + '().');
}return CallExpression;}() };
}return create;}() }; /**
* @fileoverview Rule to prefer imports to AMD
* @author Jamund Ferguson
*/
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbWQuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwiZGVzY3JpcHRpb24iLCJ1cmwiLCJzY2hlbWEiLCJjcmVhdGUiLCJjb250ZXh0IiwiQ2FsbEV4cHJlc3Npb24iLCJub2RlIiwiZ2V0U2NvcGUiLCJjYWxsZWUiLCJuYW1lIiwiYXJndW1lbnRzIiwibGVuZ3RoIiwibW9kdWxlcyIsInJlcG9ydCJdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFLQSxxQzs7QUFFQTtBQUNBO0FBQ0E7O0FBRUFBLE9BQU9DLE9BQVAsR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