Skip to content

Conversation

@lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Oct 22, 2025

Prerequisites checklist

What is the purpose of this pull request?

In this PR, I've replaced leche helper function with native forEach.

This PR was motivated by #78, since leche was the only blocker preventing the update of mocha. (leche was last updated 6 years ago and hasn't been updated since.)

https://github.com/eslint/eslint-release/actions/runs/18691775165/job/53299023443?pr=78

image

I've looked into the original implementation of leche.withData, and it was as follows:

	/**
	 * A data provider for use with Mocha. Use this around a call to it() to run
	 * the test over a series of data.
	 * @param {Object|Array} dataset The data to test.
	 * @param {Function} testFunction The function to call for each piece of data.
	 * @returns {void}
	 * @throws {Error} If dataset is missing or an empty array.
	 */
	withData: function(dataset, testFunction) {

		// check for missing or null argument
		if (typeof dataset !== 'object' || dataset === null) {
			throw new Error('First argument must be an object or non-empty array.');
		}

		/*
		 * The dataset needs to be normalized so it looks like:
		 * {
		 *      "name1": [ "data1", "data2" ],
		 *      "name2": [ "data3", "data4" ],
		 * }
		 */
		var namedDataset = dataset;
		if (dataset instanceof Array) {

			// arrays must have at least one item
			if (dataset.length) {
				namedDataset = createNamedDataset(dataset);
			} else {
				throw new Error('First argument must be an object or non-empty array.');
			}
		}

		/*
		 * For each name, create a new describe() block containing the name.
		 * This causes the dataset info to be output into the console, making
		 * it easier to determine which dataset caused a problem when there's an
		 * error.
		 */
		for (var name in namedDataset) {
			if (namedDataset.hasOwnProperty(name)) {
				/*eslint-disable no-loop-func*/

				describe('with ' + name, (function(dataName) {
					return function() {

						var args = namedDataset[dataName];

						if (!(args instanceof Array)) {
							args = [args];
						}

						testFunction.apply(this, args);
					};
				}(name)));

				/*eslint-enable no-loop-func*/
			}
		}
	}

I thought it would be safe to replace the above function with forEach, so I went ahead.

What changes did you make? (Give an overview)

In this PR, I've replaced leche helper function with native forEach.

Related Issues

N/A

Is there anything you'd like reviewers to focus on?

N/A

@eslintbot eslintbot added this to Triage Oct 22, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 22, 2025
@lumirlumir lumirlumir marked this pull request as ready for review October 22, 2025 05:32
@aladdin-add aladdin-add merged commit d8c4b90 into main Oct 22, 2025
9 checks passed
@github-project-automation github-project-automation bot moved this from Needs Triage to Complete in Triage Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants