require-file-extensions

ESLint rule enforcing that require() calls of files end with a whitelisted file extension.

Usage

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

rule

ESLint rule enforcing that require() calls of files end with a whitelisted file extension.

Bad:

// Invalid file extension:
var readme = require( '@stdlib/array/int32/README.md' );

// Missing file extension:
var debug = require( 'debug/src/browser' );

Good:

var Int32Array = require( '@stdlib/array/int32' );

var debug = require( 'debug/src/browser.js' );

Examples

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

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

var opts = {
    'rules': {
        'require-file-extensions': 'error'
    }
};

linter.defineRule( 'require-file-extensions', rule );

code = 'var readme = require( \'debug/README.md\' )';
result = linter.verify( code, opts );
/* returns
    [
        {
            ruleId: 'require-file-extensions',
            severity: 2,
            message: 'require statement of file does not end with one of the whitelisted file extensions (.js,.json,.node). Value: debug/README.md',
            line: 1,
            column: 14,
            nodeType: 'CallExpression',
            source: 'var readme = require( \'debug/README.md\' )',
            endLine: 1,
            endColumn: 42
        }
    ]
*/

code = 'var beep = require( \'@stdlib/beep\' )';
result = linter.verify( code, opts );
/* returns
    [
        {
            ruleId: 'require-file-extensions',
            severity: 2,
            message: 'cannot resolve module: "@stdlib/beep"',
            line: 1,
            column: 12,
            nodeType: 'CallExpression',
            source: 'var beep = require( \'@stdlib/beep\' )',
            endLine: 1,
            endColumn: 37
        }
    ]
*/