detect-non-literal-require.js 768 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Tries to detect calls to require with non-literal argument
  3. * @author Adam Baldwin
  4. */
  5. //------------------------------------------------------------------------------
  6. // Rule Definition
  7. //------------------------------------------------------------------------------
  8. module.exports = function(context) {
  9. "use strict";
  10. return {
  11. "CallExpression": function (node) {
  12. if (node.callee.name === 'require') {
  13. var args = node.arguments;
  14. if (args && args.length > 0 && args[0].type !== 'Literal') {
  15. var token = context.getTokens(node)[0];
  16. return context.report(node, 'Found non-literal argument in require');
  17. }
  18. }
  19. }
  20. };
  21. };