47 lines
4.2 KiB
JavaScript
47 lines
4.2 KiB
JavaScript
'use strict';
|
|
|
|
var _importType = require('../core/importType');
|
|
|
|
var _importType2 = _interopRequireDefault(_importType);
|
|
|
|
var _staticRequire = require('../core/staticRequire');
|
|
|
|
var _staticRequire2 = _interopRequireDefault(_staticRequire);
|
|
|
|
var _docsUrl = require('../docsUrl');
|
|
|
|
var _docsUrl2 = _interopRequireDefault(_docsUrl);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function reportIfMissing(context, node, allowed, name) {
|
|
if (allowed.indexOf(name) === -1 && (0, _importType2.default)(name, context) === 'builtin') {
|
|
context.report(node, 'Do not import Node.js builtin module "' + name + '"');
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2.default)('no-nodejs-modules')
|
|
}
|
|
},
|
|
|
|
create: function (context) {
|
|
const options = context.options[0] || {};
|
|
const allowed = options.allow || [];
|
|
|
|
return {
|
|
ImportDeclaration: function handleImports(node) {
|
|
reportIfMissing(context, node, allowed, node.source.value);
|
|
},
|
|
CallExpression: function handleRequires(node) {
|
|
if ((0, _staticRequire2.default)(node)) {
|
|
reportIfMissing(context, node, allowed, node.arguments[0].value);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1ub2RlanMtbW9kdWxlcy5qcyJdLCJuYW1lcyI6WyJyZXBvcnRJZk1pc3NpbmciLCJjb250ZXh0Iiwibm9kZSIsImFsbG93ZWQiLCJuYW1lIiwiaW5kZXhPZiIsInJlcG9ydCIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJjcmVhdGUiLCJvcHRpb25zIiwiYWxsb3ciLCJJbXBv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