46 lines
4.1 KiB
JavaScript
46 lines
4.1 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: {
|
|
docs: {
|
|
url: (0, _docsUrl2.default)('no-amd')
|
|
}
|
|
},
|
|
|
|
create: function (context) {
|
|
|
|
return {
|
|
|
|
'CallExpression': function (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;
|
|
|
|
const 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 ${node.callee.name}().`);
|
|
}
|
|
};
|
|
}
|
|
}; /**
|
|
* @fileoverview Rule to prefer imports to AMD
|
|
* @author Jamund Ferguson
|
|
*/
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25vLWFtZC5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJ1cmwiLCJjcmVhdGUiLCJjb250ZXh0Iiwibm9kZSIsImdldFNjb3BlIiwidHlwZSIsImNhbGxlZSIsIm5hbWUiLCJhcmd1bWVudHMiLCJsZW5ndGgiLCJtb2R1bGVzIiwicmVwb3J0Il0sIm1hcHBpbmdzIjoiOztBQUtBOzs7Ozs7QUFFQTtBQUNBO0FBQ0E7O0FBRUFBLE9BQU9DLE9BQVAsR0FBaUI7QUFDYkMsVU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AgIC8vIHRvZG86IGNoZWNrIHNlY29uZCBhcmcgdHlwZT8gKGlkZW50aWZpZXIgb3IgY2FsbGJhY2spXG5cbiAgICAgICAgICAgICAgICBjb250ZXh0LnJlcG9ydChub2RlLCBgRXhwZWN0ZWQgaW1wb3J0cyBpbnN0ZWFkIG9mIEFNRCAke25vZGUuY2FsbGVlLm5hbWV9KCkuYClcbiAgICAgICAgICAgIH0sXG4gICAgICAgIH1cblxuICAgIH0sXG59XG4iXX0=
|