eslint-plugin-node icon indicating copy to clipboard operation
eslint-plugin-node copied to clipboard

prefer-global allow dynamic

Open remcohaszing opened this issue 5 years ago • 0 comments

I like the prefer-global rule, but sometimes a dynamic require is needed inside a function. I suggest to add a boolean option allowDynamic. If this is set to true, this rule only reports nested imports if a literal string or template string without variables is passed.

For example:

valid:

require('./bar');

function foo(bar) {
  return require('./' + bar);
}

function foo(bar) {
  return require(`./${bar}`);
}

invalid:

function foo() {
  return require('./bar');
}

function foo() {
  return require(`./bar`);
}

remcohaszing avatar Aug 04 '20 20:08 remcohaszing