<commit_before>/**
 * SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
 * SPDX-License-Identifier: MIT
 */

const path = require('path');

const DISALLOWED_EXTENSIONS = {
	'.babelrc.js': {
		messageId: 'noExplicitPreset',
		property: 'presets',
		values: new Set(['@babel/preset-env', '@babel/preset-react']),
	},
	'.eslintrc.js': {
		messageId: 'noExplicitExtend',
		property: 'extends',
		values: new Set(['liferay/portal', 'liferay/react']),
	},
};

const noExplicitExtend =
	'`liferay/portal` and `liferay/react` apply automatically and can be omitted';

const noExplicitPreset =
	'`@babel/preset-env` and `@babel/preset-react` apply automatically and can be omitted';

/**
 * Expects either:
 *
 * - a Set of literals to prune from an ArrayExpression; or:
 * - a Property to prune from an ObjectExpression.
 */
function fix(elementsOrProperty, context, fixer) {
	const source = context.getSourceCode();

	let items;

	if (elementsOrProperty instanceof Set) {
		// Removing elements from an ArrayExpression.
		let parent;

		for (const node of elementsOrProperty) {
			parent = node.parent;

			break;
		}

		items = parent.elements.slice();
	} else {
		// Removing property from an ObjectExpression.
		const parent = elementsOrProperty.parent;

		// Special case: when removing last property, kill all
		// internal whitespace.
		if (parent.properties.length === 1) {
			return fixer.replaceText(parent, '{}');
		}

		elementsOrProperty = new Set([elementsOrProperty]);
		items = parent.properties.slice();
	}

	const lastIndex = items.length - 1;
	const start = items[0].range[0];
	const end = items[lastIndex].range[1];

	const lastVisible = items.reduce((last, item, index) => {
		if (elementsOrProperty.has(item)) {
			return last;
		} else {
			return index;
		}
	}, NaN);

	// Remove array elements or an object property, preserving
	// whitespace between items.
	return fixer.replaceTextRange(
		[start, end],
		items.slice().reduce((text, item, index) => {
			const atEnd = index >= lastVisible;
			const itemText = source.getText(item);

			const trailingWhitespace = atEnd
				? ''
				: source
						.getText()
						.slice(item.range[1], items[index + 1].range[0]);

			// When removing last item, we eat preceding
			// whitespace. When removing other items we eat trailing
			// whitespace.
			if (elementsOrProperty.has(item)) {
				return text;
			} else if (index + 1 >= lastVisible) {
				return text + itemText;
			} else {
				return text + itemText + trailingWhitespace;
			}
		}, '')
	);
}

module.exports = {
	create(context) {
		const filename = path.basename(context.getFilename());

		const disallowed = DISALLOWED_EXTENSIONS[filename];

		if (!disallowed) {
			return {};<commit_msg>refactor: rename a variable for clarity<commit_after>/**
 * SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
 * SPDX-License-Identifier: MIT
 */

const path = require('path');

const DISALLOWED_EXTENSIONS = {
	'.babelrc.js': {
		messageId: 'noExplicitPreset',
		property: 'presets',
		values: new Set(['@babel/preset-env', '@babel/preset-react']),
	},
	'.eslintrc.js': {
		messageId: 'noExplicitExtend',
		property: 'extends',
		values: new Set(['liferay/portal', 'liferay/react']),
	},
};

const noExplicitExtend =
	'`liferay/portal` and `liferay/react` apply automatically and can be omitted';

const noExplicitPreset =
	'`@babel/preset-env` and `@babel/preset-react` apply automatically and can be omitted';

/**
 * Expects `nodesToRemove` to be either:
 *
 * - a Set of literals to prune from an ArrayExpression; or:
 * - a Property to prune from an ObjectExpression.
 */
function fix(nodesToRemove, context, fixer) {
	const source = context.getSourceCode();

	let items;

	if (nodesToRemove instanceof Set) {
		// Removing elements from an ArrayExpression.
		let parent;

		for (const node of nodesToRemove) {
			parent = node.parent;

			break;
		}

		items = parent.elements.slice();
	} else {
		// Removing property from an ObjectExpression.
		const parent = nodesToRemove.parent;

		// Special case: when removing last property, kill all
		// internal whitespace.
		if (parent.properties.length === 1) {
			return fixer.replaceText(parent, '{}');
		}

		nodesToRemove = new Set([nodesToRemove]);
		items = parent.properties.slice();
	}

	const lastIndex = items.length - 1;
	const start = items[0].range[0];
	const end = items[lastIndex].range[1];

	const lastVisible = items.reduce((last, item, index) => {
		if (nodesToRemove.has(item)) {
			return last;
		} else {
			return index;
		}
	}, NaN);

	// Remove array elements or an object property, preserving
	// whitespace between items.
	return fixer.replaceTextRange(
		[start, end],
		items.slice().reduce((text, item, index) => {
			const atEnd = index >= lastVisible;
			const itemText = source.getText(item);

			const trailingWhitespace = atEnd
				? ''
				: source
						.getText()
						.slice(item.range[1], items[index + 1].range[0]);

			// When removing last item, we eat preceding
			// whitespace. When removing other items we eat trailing
			// whitespace.
			if (nodesToRemove.has(item)) {
				return text;
			} else if (index + 1 >= lastVisible) {
				return text + itemText;
			} else {
				return text + itemText + trailingWhitespace;
			}
		}, '')
	);
}

module.exports = {
	create(context) {
		const filename = path.basename(context.getFilename());

		const disallowed = DISALLOWED_EXTENSIONS[filename];

		if (!disallowed) {
			return {};
{'fraction_non_alphanumeric': 0.13755937157471684, 'fraction_numerical': 0.0047497259773474606, 'mean_word_length': 3.6124684077506317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '2497714', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1748, 'n_words': 472}