bigint-crypto-utils/node_modules/eslint-plugin-import/lib/rules/no-dynamic-require.js

38 lines
3.3 KiB
JavaScript

'use strict';
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isRequire(node) {
return node && node.callee && node.callee.type === 'Identifier' && node.callee.name === 'require' && node.arguments.length >= 1;
}
function isStaticValue(arg) {
return arg.type === 'Literal' || arg.type === 'TemplateLiteral' && arg.expressions.length === 0;
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2.default)('no-dynamic-require')
}
},
create: function (context) {
return {
CallExpression(node) {
if (isRequire(node) && !isStaticValue(node.arguments[0])) {
context.report({
node,
message: 'Calls to require() should use string literals'
});
}
}
};
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1keW5hbWljLXJlcXVpcmUuanMiXSwibmFtZXMiOlsiaXNSZXF1aXJlIiwibm9kZSIsImNhbGxlZSIsInR5cGUiLCJuYW1lIiwiYXJndW1lbnRzIiwibGVuZ3RoIiwiaXNTdGF0aWNWYWx1ZSIsImFyZyIsImV4cHJlc3Npb25zIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJkb2NzIiwidXJsIiwiY3JlYXRlIiwiY29udGV4dCIsIkNhbGxFeHByZXNzaW9uIiwicmVwb3J0IiwibWVzc2FnZSJdLCJtYXBwaW5ncyI6Ijs7QUFBQTs7Ozs7O0FBRUEsU0FBU0EsU0FBVCxDQUFtQkMsSUFBbkIsRUFBeUI7QUFDdkIsU0FBT0EsUUFDTEEsS0FBS0MsTUFEQSxJQUVMRCxLQUFLQyxNQUFMLENBQVlDLElBQVosS0FBcUIsWUFGaEIsSUFHTEYsS0FBS0MsTUFBTCxDQUFZRSxJQUFaLEtBQXFCLFNBSGhCLElBSUxILEtBQUtJLFNB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