eslint-plugin-node
eslint-plugin-node copied to clipboard
prefer-global allow dynamic
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`);
}