29 lines
No EOL
2.9 KiB
JavaScript
29 lines
No EOL
2.9 KiB
JavaScript
'use strict';
|
|
|
|
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: {
|
|
docs: {}
|
|
},
|
|
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25vLWR5bmFtaWMtcmVxdWlyZS5qcyJdLCJuYW1lcyI6WyJpc1JlcXVpcmUiLCJub2RlIiwiY2FsbGVlIiwidHlwZSIsIm5hbWUiLCJhcmd1bWVudHMiLCJsZW5ndGgiLCJpc1N0YXRpY1ZhbHVlIiwiYXJnIiwiZXhwcmVzc2lvbnMiLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJjcmVhdGUiLCJjb250ZXh0IiwiQ2FsbEV4cHJlc3Npb24iLCJyZXBvcnQiLCJtZXNzYWdlIl0sIm1hcHBpbmdzIjoiOztBQUFBLFNBQVNBLFNBQVQsQ0FBbUJDLElBQW5CLEVBQXlCO0FBQ3ZCLFNBQU9BLFFBQ0xBLEtBQUtDLE1BREEsSUFFTEQsS0FBS0MsTUFBTCxDQUFZQyxJQUFaLEtBQXFCLFlBRmhCLElBR0xGLEtBQUtDLE1BQUwsQ0FBWUUsSUFBWixLQUFxQixTQUhoQixJQUlMSCxLQUFLSSxTQUFMLENBQWVDLE1BQWYsSUFBeUIsQ0FKM0I7QUFLRDs7QUFFR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