<commit_before>var grunt = require( 'grunt' );

/**
 * Replaces file names in the passed file_path with the file names in the file_mappings.
 *
 * @param file_path The path to the file where the filenames should be replaced.
 * @param file_mappings The file names to replace and the file names they should be replaced with.
 *
 * @returns {void}
 */
function map_old_to_new_file_path ( file_path, file_mappings ) {
	var body = grunt.file.read( file_path ), new_body;
	for ( var old_path in file_mappings ) {

		// Ensure only own properties are looped over.
		if ( !file_mappings.hasOwnProperty( old_path ) ) {
			continue;
		}

		// Regex to match the second filename of the diff header.
		var header_regex = new RegExp( "((diff \\-\\-git .* )(" + old_path + ")(\\n))", "ig" );

		// Regex to match the old and new file name of the chunks within the diff.
		var chunk_filename_regex = new RegExp( "((-{3}|\\+{3})( " + old_path + "))", "ig" );

		if ( !body.match( chunk_filename_regex ) ) {
			continue;
		}

		var new_path = file_mappings[ old_path ];

		new_body = body.replace( chunk_filename_regex, "$2 " + new_path );
		new_body = new_body.replace( header_regex, "$2" + new_path + "$4" );

		// Logs the mapping.
		if ( body !== new_body ) {
			grunt.log.writeln( "Old file path " + old_path + " found in patch. This path has been automatically replaced by " + new_path + "." );
		}
	}

	// new_body only has a value when there was a match.
	if ( new_body ) {
		grunt.file.write( file_path, new_body );
	}
}

module.exports = map_old_to_new_file_path;
<commit_msg>fix formating of lib/map_old_to_new_file_path.js<commit_after>var grunt = require( 'grunt' );

/**
 * Replaces file names in the passed filePath with the file names in the fileMappings.
 *
 * @param filePath The path to the file where the filenames should be replaced.
 * @param fileMappings The file names to replace and the file names they should be replaced with.
 *
 * @returns {void}
 */
function mapOldToNewFilePath( filePath, fileMappings ) {
	var body = grunt.file.read( filePath ),
		newBody,
		oldPath;
	for ( oldPath in fileMappings ) {

		// Ensure only own properties are looped over.
		if ( ! fileMappings.hasOwnProperty( oldPath ) ) {
			continue;
		}

		// Regex to match the second filename of the diff header.
		const headerRegex = new RegExp( '((diff \\-\\-git .* )(' + oldPath + ')(\\n))', 'ig' );

		// Regex to match the old and new file name of the chunks within the diff.
		const chunkFilenameRegex = new RegExp( '((-{3}|\\+{3})( ' + oldPath + '))', 'ig' );

		if ( ! body.match( chunkFilenameRegex ) ) {
			continue;
		}

		const newPath = fileMappings[ oldPath ];

		newBody = body.replace( chunkFilenameRegex, '$2 ' + newPath );
		newBody = newBody.replace( headerRegex, '$2' + newPath + '$4' );

		// Logs the mapping.
		if ( body !== newBody ) {
			grunt.log.writeln( 'Old file path ' + oldPath + ' found in patch. This path has been automatically replaced by ' + newPath + '.' );
		}
	}

	// newBody only has a value when there was a match.
	if ( newBody ) {
		grunt.file.write( filePath, newBody );
	}
}

module.exports = mapOldToNewFilePath;

{'fraction_non_alphanumeric': 0.12881679389312978, 'fraction_numerical': 0.0031806615776081423, 'mean_word_length': 3.3141289437585733, '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': '2112598', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1041, 'n_words': 349}