Repository: eslint/eslint
File: lib/rule-tester/rule-tester.js (JavaScript)

Code before:
	);
}

const metaSchemaDescription = `
\t- If the rule has options, set \`meta.schema\` to an array or non-empty object to enable options validation.
\t- If the rule doesn't have options, omit \`meta.schema\` to enforce that no options can be passed to the rule.
\t- You can also set \`meta.schema\` to \`false\` to opt-out of options validation (not recommended).

\thttps://eslint.org/docs/latest/extend/custom-rules#options-schemas
`;

/*
 * Ignored test case properties when checking for test case duplicates.
 */
const duplicationIgnoredParameters = new Set(["name", "errors", "output"]);

/**
 * Asserts that a value is a string or undefined.
 * If the value is not a string or undefined, it throws an assertion error
 * @param {any} value The value to check.
 * @param {string?} message The error message to display if the value is not a string or undefined.
 * @returns {void}
 */
function assertStringOrUndefined(
	value,
	message = "Value must be a string or undefined",
) {
	assert.ok(
		typeof value === "string" || typeof value === "undefined",
		message,
	);
}

/**
 * Asserts that a value is an object.
 * If the value is not an object, it throws an assertion error.
 * @param {any} value The value to check.
 * @param {string?} message The error message to display if the value is not an object.
 * @returns {void}
 */
function assertObject(value, message = "Value must be an object") {
	assert.ok(value && typeof value === "object", message);
}

/**
 * Asserts that a value is a string.
 * If the value is not a string, it throws an assertion error.
 * @param {any} value The value to check.
 * @param {string?} message The error message to display if the value is not a string.
 * @returns {void}
 */

Review comment (suggestion):
I do not think this function should have a parameter with a default value.
It is currently unused and the message should be unique to the checked test case property

Code after:

const metaSchemaDescription = `
\t- If the rule has options, set \`meta.schema\` to an array or non-empty object to enable options validation.
\t- If the rule doesn't have options, omit \`meta.schema\` to enforce that no options can be passed to the rule.
\t- You can also set \`meta.schema\` to \`false\` to opt-out of options validation (not recommended).

\thttps://eslint.org/docs/latest/extend/custom-rules#options-schemas
`;

/*
 * Ignored test case properties when checking for test case duplicates.
 */
const duplicationIgnoredParameters = new Set(["name", "errors", "output"]);

/**
 * Normalizes a test case item, ensuring it is an object with a 'code' property.
 * If the item is not an object, it returns an object with the 'code' property set to the item.
 * @param {any} item The test case item to normalize.
 * @returns {Object} The normalized test case object.
 */
function normalizeTestCase(item) {
	return item && typeof item === "object" ? item : { code: item };
}

/**
 * Asserts that the `errors` property of an invalid test case is valid.
 * @param {number | string[]} errors The `errors` property of the invalid test case.
 * @param {string} ruleName The name of the rule being tested.
 * @returns {void}
 */
function assertErrorsProperty(errors, ruleName) {
	const isNumber = typeof errors === "number";
	const isArray = Array.isArray(errors);

	if (!isNumber && !isArray) {
		if (errors === void 0) {
			assert.fail(
				`Did not specify errors for an invalid test of ${ruleName}`,
			);
		} else {
			assert.fail(
				`Invalid 'errors' property for invalid test of ${ruleName}: expected a number or an array but got ${
					errors === null ? "null" : typeof errors
				}`,
			);
		}
	}

	if (isArray) {
		assert.ok(
			errors.length !== 0,