no-dynamic-require

ESLint rule enforcing that require() calls have only string literals as arguments.

Usage

var rule = require( '@stdlib/_tools/eslint/rules/no-dynamic-require' );

rule

ESLint rule enforcing that require() calls have only string literals as arguments.

Bad:

var pkg = '@stdlib/math/base/special/betainc';
var betainc = require( pkg );

Good:

var betainc = require( '@stdlib/math/base/special/betainc' );

Examples

var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/no-dynamic-require' );

var linter = new Linter();
var result;
var code;

code = [
    'var pkg = \'@stdlib/math/base/special/betainc\';',
    'var betainc = require( pkg );'
].join( '\n' );

linter.defineRule( 'no-dynamic-require', rule );

result = linter.verify( code, {
    'rules': {
        'no-dynamic-require': 'error'
    }
});
/* returns
    [
        {
            ruleId: 'no-dynamic-require',
            severity: 2,
            message: 'require() calls should only use string literals',
            line: 2,
            column: 15,
            nodeType: 'CallExpression',
            source: 'var betainc = require( pkg );',
            endLine: 2,
            endColumn: 29
        }
    ]
*/