Constnium/node_modules/eslint-plugin-import/lib/rules/no-amd.js
2022-06-23 02:27:43 +02:00

46 lines
No EOL
4.3 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: {
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbWQuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJub2RlIiwiZ2V0U2NvcGUiLCJjYWxsZWUiLCJuYW1lIiwiYXJndW1lbnRzIiwibGVuZ3RoIiwibW9kdWxlcyIsInJlcG9ydCJdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFLQSxxQzs7QUFFQTtBQUNBO0FBQ0E7O0FBRUFBLE9BQU9DLE9BQVAsR0FBaUI7QUFDZkMsUUFBTTtBQUNKQyxVQUFNLFlBREY7QUFFSkMsVUFBTTtBQUNKQyxXQUFLLDBCQUFRLFFBQVIs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