<commit_before>'use strict';

// MODULES //

var parse = require( 'path' ).parse;
var resolve = require( 'resolve' ).sync;
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var isString = require( '@stdlib/assert/is-string' );
var contains = require( '@stdlib/assert/contains' );


// VARIABLES //

var EXTENSIONS_WHITELIST = [
	'.js',
	'.json',
	'.node'
];


// MAIN //

/**
* Rule for enforcing that require statements of files end with a whitelisted file extension.
*
* @param {Object} context - ESLint context
* @returns {Object} validators
*/
function main( context ) {
	var whitelist;
	var options;

	options = context.options[ 0 ];
	if ( hasOwnProp( options, 'extensionsWhitelist' ) ) {
		whitelist = options.extensionsWhitelist;
	} else {
		whitelist = EXTENSIONS_WHITELIST;
	}

	/**
	* Reports the error message.
	*
	* @private
	* @param {ASTNode} node - node to report
	* @param {string} msg - message to report
	*/
	function report( node, msg ) {
		context.report({
			'node': node,
			'message': msg
		});
	} // end FUNCTION report()

	/**
	* Checks whether a require statement of a file ends with a whitelisted file extension.
	*
	* @private
	* @param {ASTNode} node - node to examine
	*/
	function validate( node ) {
		var requirePath;
		var resolved;
		var parts;
		var msg;

		if ( node.callee.name === 'require' ) {
			requirePath = node.arguments[ 0 ].value;
			if ( isString( requirePath ) ) {
				try {
					resolved = parse( resolve( requirePath, {
						'paths': process.env.NODE_PATH // eslint-disable-line no-process-env
					}) );
					parts = parse( requirePath );
					if ( resolved.name === parts.name ) {
						// Path denotes a file or internal module...
						if ( parts.ext && !contains( whitelist, parts.ext ) ) {
							msg = 'require statement of file does not end with one of the whitelisted file extensions (' + whitelist.join( ',' ) + '). Value: '+ requirePath;
							report( node, msg );
						} else if ( resolved.ext && !parts.ext ) {
							msg = 'require statement of file is missing a file extension. Value: '+ requirePath;
							report( node, msg );
						}
					}
				} catch ( err ) { // eslint-disable-line no-unused-vars
					report( node, 'Cannot resolve module: "'+requirePath+'"' );
				}
			}
		}
	} // end FUNCTION validate()

	return {
		'CallExpression': validate
	};
} // end FUNCTION main()


// EXPORTS //

module.exports = {
	'meta': {
		'docs': {
			'description': 'enforce that require statements of files end with a whitelisted file extension'
		},
		'schema': [
			{
				'type': 'object',
				'properties': {
					'extensionsWhitelist': {
						'type': 'array'
					}
				},
				'additionalProperties': false
			}
		]
	},<commit_msg>Uncapitalize to be consistent with other messages<commit_after>'use strict';

// MODULES //

var parse = require( 'path' ).parse;
var resolve = require( 'resolve' ).sync;
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var isString = require( '@stdlib/assert/is-string' );
var contains = require( '@stdlib/assert/contains' );


// VARIABLES //

var EXTENSIONS_WHITELIST = [
	'.js',
	'.json',
	'.node'
];


// MAIN //

/**
* Rule for enforcing that require statements of files end with a whitelisted file extension.
*
* @param {Object} context - ESLint context
* @returns {Object} validators
*/
function main( context ) {
	var whitelist;
	var options;

	options = context.options[ 0 ];
	if ( hasOwnProp( options, 'extensionsWhitelist' ) ) {
		whitelist = options.extensionsWhitelist;
	} else {
		whitelist = EXTENSIONS_WHITELIST;
	}

	/**
	* Reports the error message.
	*
	* @private
	* @param {ASTNode} node - node to report
	* @param {string} msg - message to report
	*/
	function report( node, msg ) {
		context.report({
			'node': node,
			'message': msg
		});
	} // end FUNCTION report()

	/**
	* Checks whether a require statement of a file ends with a whitelisted file extension.
	*
	* @private
	* @param {ASTNode} node - node to examine
	*/
	function validate( node ) {
		var requirePath;
		var resolved;
		var parts;
		var msg;

		if ( node.callee.name === 'require' ) {
			requirePath = node.arguments[ 0 ].value;
			if ( isString( requirePath ) ) {
				try {
					resolved = parse( resolve( requirePath, {
						'paths': process.env.NODE_PATH // eslint-disable-line no-process-env
					}) );
					parts = parse( requirePath );
					if ( resolved.name === parts.name ) {
						// Path denotes a file or internal module...
						if ( parts.ext && !contains( whitelist, parts.ext ) ) {
							msg = 'require statement of file does not end with one of the whitelisted file extensions (' + whitelist.join( ',' ) + '). Value: '+ requirePath;
							report( node, msg );
						} else if ( resolved.ext && !parts.ext ) {
							msg = 'require statement of file is missing a file extension. Value: '+ requirePath;
							report( node, msg );
						}
					}
				} catch ( err ) { // eslint-disable-line no-unused-vars
					report( node, 'cannot resolve module: "'+requirePath+'"' );
				}
			}
		}
	} // end FUNCTION validate()

	return {
		'CallExpression': validate
	};
} // end FUNCTION main()


// EXPORTS //

module.exports = {
	'meta': {
		'docs': {
			'description': 'enforce that require statements of files end with a whitelisted file extension'
		},
		'schema': [
			{
				'type': 'object',
				'properties': {
					'extensionsWhitelist': {
						'type': 'array'
					}
				},
				'additionalProperties': false
			}
		]
	},
{'fraction_non_alphanumeric': 0.14542124542124543, 'fraction_numerical': 0.0007326007326007326, 'mean_word_length': 2.832280701754386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3439854', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1746, 'n_words': 520}