new-cap-regexp

ESLint rule enforcing that the RegExp constructor is invoked with the new keyword.

Usage

var rule = require( '@stdlib/_tools/eslint/rules/new-cap-regexp' );

rule

ESLint rule enforcing that the RegExp constructor is invoked with the new keyword.

Bad:

var re = RegExp( '[0-9]' );

Good:

var re = new RegExp( '[0-9]' );

Examples

var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/new-cap-regexp' );

var linter = new Linter();
var result;

var code = 'var re = RegExp( \'ab+c\', \'i\' );';

linter.defineRule( 'new-cap-regexp', rule );

result = linter.verify( code, {
    'rules': {
        'new-cap-regexp': 'error'
    }
});
/* returns
    [
        {
            ruleId: 'new-cap-regexp',
            severity: 2,
            message: '`RegExp` constructor is invoked without the `new` keyword',
            line: 1,
            column: 10,
            nodeType: 'CallExpression',
            source: 'var re = RegExp( \'ab+c\', \'i\' );',
            endLine: 1,
            endColumn: 31
        }
    ]
*/