require-globals

ESLint rule enforcing that specified global variables are explicitly required.

Usage

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

rule

ESLint rule enforcing that specified global variables are explicitly required. To specify a list of globals, provide a globals option.

Bad:

/*
    Options: [ 'error', {
        'globals': [
            'Float32Array'
        ]
    }]
*/
var arr = new Float32Array();

Good:

/*
    Options: [ 'error', {
        'globals': [
            'Float32Array'
        ]
    }]
*/
var Float32Array = require( '@stdlib/array/float32' );

var arr = new Float32Array();

arr = new Int32Array();

Examples

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

var linter = new Linter();
var result;

var code = 'var arr = new Int32Array( [1,2,3] );';

linter.defineRule( 'require-globals', rule );

result = linter.verify( code, {
    'rules': {
        'require-globals': [ 'error', {
            'globals': [
                'Int32Array'
            ]
        }]
    }
});
/* returns
    [
        {
            ruleId: 'require-globals',
            severity: 2,
            message: 'Int32Array is invoked without loading it beforehand via require()',
            line: 1,
            column: 11,
            nodeType: 'NewExpression',
            source: 'var arr = new Int32Array( [1,2,3] );',
            endLine: 1,
            endColumn: 36
        }
    ]
*/