ronantakizawa/codereview-bench huggingface dataset:
Repository: eslint/eslint
File: tests/lib/rules/one-var.js (JavaScript)

Code before:
				{
					messageId: "splitInitialized",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},
		{
			code: "var f, k /* test */, l;",
			output: "var f; var k /* test */; var l;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},
		{
			code: "var f,         /* test */ l;",
			output: "var f;         /* test */ var l;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},
		{
			code: "var f, k /* test \n some more comment \n even more */, l = 1, P;",
			output: "var f; var k /* test \n some more comment \n even more */; var l = 1; var P;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},

Review comment (suggestion):
```suggestion
			code: "var f,          /* test */ l;",
			output: "var f;          /* test */ var l;",
```

To avoid unnecessary diff.

Code after:
				{
					messageId: "splitInitialized",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},
		{
			code: "var f, k /* test */, l;",
			output: "var f; var k /* test */; var l;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},
		{
			code: "var f,          /* test */ l;",
			output: "var f;          /* test */ var l;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},
		{
			code: "var f, k /* test \n some more comment \n even more */, l = 1, P;",
			output: "var f; var k /* test \n some more comment \n even more */; var l = 1; var P;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
					line: 1,
					column: 1,
				},
			],
		},
Repository: eslint/eslint
File: docs/tools/markdown-it-rule-example.js (JavaScript)

Code before:
 *             // do something
 *         }
 *         close() {
 *             // do something
 *         }
 *     }))
 *     .render(text);
 *
 */
function markdownItRuleExample({ open, close }) {
	return {
		validate(info) {
			return /^\s*(?:in)?correct(?!\S)/u.test(info);
		},
		render(tokens, index, options, env) {
			const tagToken = tokens[index];

			if (tagToken.nesting < 0) {
				const text = close ? close() : void 0;

				// Return an empty string to avoid appending unexpected text to the output.
				return typeof text === "string" ? text : "";
			}

			const { type, languageOptionsJSON } =
				/^\s*(?<type>\S+)(?:\s+(?<languageOptionsJSON>\S(?:\s*\S)*))?\s*$/u.exec(
					tagToken.info,
				).groups;
			const languageOptions = languageOptionsJSON
				? JSON.parse(languageOptionsJSON)
				: void 0;
			const codeBlockToken = tokens[index + 1];

			// Remove trailing newline and presentational `⏎` characters (https://github.com/eslint/eslint/issues/17627):
			const code = docsExampleCodeToParsableCode(codeBlockToken.content);

			const text = open({
				type,
				code,
				languageOptions,
				codeBlockToken,
				env,
			});

			// Return an empty string to avoid appending unexpected text to the output.
			return typeof text === "string" ? text : "";
		},
	};
}

module.exports = markdownItRuleExample;

Review comment (suggestion):
I think this could be just:

```suggestion
				/^\s*(?<type>\S+)(?:\s+(?<languageOptionsJSON>\S(?:.*\S)?))?\s*$/u.exec(
```

to avoid the double repetition (`*`).

Code after:
 *             // do something
 *         }
 *         close() {
 *             // do something
 *         }
 *     }))
 *     .render(text);
 *
 */
function markdownItRuleExample({ open, close }) {
	return {
		validate(info) {
			return /^\s*(?:in)?correct(?!\S)/u.test(info);
		},
		render(tokens, index, options, env) {
			const tagToken = tokens[index];

			if (tagToken.nesting < 0) {
				const text = close ? close() : void 0;

				// Return an empty string to avoid appending unexpected text to the output.
				return typeof text === "string" ? text : "";
			}

			const { type, languageOptionsJSON } =
				/^\s*(?<type>\S+)(?:\s+(?<languageOptionsJSON>\S(?:.*\S)?))?/u.exec(
					tagToken.info,
				).groups;
			const languageOptions = languageOptionsJSON
				? JSON.parse(languageOptionsJSON)
				: void 0;
			const codeBlockToken = tokens[index + 1];

			// Remove trailing newline and presentational `⏎` characters (https://github.com/eslint/eslint/issues/17627):
			const code = docsExampleCodeToParsableCode(codeBlockToken.content);

			const text = open({
				type,
				code,
				languageOptions,
				codeBlockToken,
				env,
			});

			// Return an empty string to avoid appending unexpected text to the output.
			return typeof text === "string" ? text : "";
		},
	};
}

module.exports = markdownItRuleExample;
Repository: eslint/eslint
File: lib/config/flat-config-schema.js (JavaScript)

Code before:
	}
}

/**
 * Validates that a value is valid rule severity.
 * @param {string} ruleId Rule name being configured.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {InvalidRuleSeverityError} If the value isn't a valid rule severity.
 */
function assertIsRuleSeverity(ruleId, value) {
	const severity = ruleSeverities.get(value);

	if (typeof severity === "undefined") {
		throw new InvalidRuleSeverityError(ruleId, value);
	}
}

/**
 * Validates that a given string is the form pluginName/objectName.
 * @param {string} value The string to check.
 * @returns {void}
 * @throws {TypeError} If the string isn't in the correct format.
 */
function assertIsPluginMemberName(value) {
	if (!/^[@\w][\w-]*(?:\/[\w-]+)+$/iu.test(value)) {
		throw new TypeError(
			`Expected string in the form "pluginName/objectName" but found "${value}".`,
		);
	}
}

/**
 * Validates that a value is an object.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {TypeError} If the value isn't an object.
 */
function assertIsObject(value) {
	if (!isNonNullObject(value)) {
		throw new TypeError("Expected an object.");
	}
}

/**
 * The error type when there's an eslintrc-style options in a flat config.
 */
class IncompatibleKeyError extends Error {
	/**
	 * @param {string} key The invalid key.
	 */

Review comment (suggestion):
Shouldn't this be more like:

```suggestion
	if (!/^[\w\-@$]+(?:\/[\w\-$]+)+$/iu.test(value)) {
```

to preserve the current behavior?

Note: not sure why Node.js wants `\-` instead of just `-` but it's the same.

Code after:
	}
}

/**
 * Validates that a value is valid rule severity.
 * @param {string} ruleId Rule name being configured.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {InvalidRuleSeverityError} If the value isn't a valid rule severity.
 */
function assertIsRuleSeverity(ruleId, value) {
	const severity = ruleSeverities.get(value);

	if (typeof severity === "undefined") {
		throw new InvalidRuleSeverityError(ruleId, value);
	}
}

/**
 * Validates that a given string is the form pluginName/objectName.
 * @param {string} value The string to check.
 * @returns {void}
 * @throws {TypeError} If the string isn't in the correct format.
 */
function assertIsPluginMemberName(value) {
	if (!/[\w\-@$]+(?:\/[\w\-$]+)+$/iu.test(value)) {
		throw new TypeError(
			`Expected string in the form "pluginName/objectName" but found "${value}".`,
		);
	}
}

/**
 * Validates that a value is an object.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {TypeError} If the value isn't an object.
 */
function assertIsObject(value) {
	if (!isNonNullObject(value)) {
		throw new TypeError("Expected an object.");
	}
}

/**
 * The error type when there's an eslintrc-style options in a flat config.
 */
class IncompatibleKeyError extends Error {
	/**
	 * @param {string} key The invalid key.
	 */
Repository: eslint/eslint
File: lib/rules/indent-legacy.js (JavaScript)

Code before:
				typeof providedSwitchIndent === "undefined"
					? getNodeIndent(switchNode).goodChar
					: providedSwitchIndent;
			let caseIndent;

			if (caseIndentStore[switchNode.loc.start.line]) {
				return caseIndentStore[switchNode.loc.start.line];
			}

			if (switchNode.cases.length > 0 && options.SwitchCase === 0) {
				caseIndent = switchIndent;
			} else {
				caseIndent = switchIndent + indentSize * options.SwitchCase;
			}

			caseIndentStore[switchNode.loc.start.line] = caseIndent;
			return caseIndent;
		}

		/**
		 * Checks whether a return statement is wrapped in ()
		 * @param {ASTNode} node node to examine
		 * @returns {boolean} the result
		 */
		function isWrappedInParenthesis(node) {
			const regex = /^return\s*\(\s*\);*/u;

			const statementWithoutArgument = sourceCode
				.getText(node)
				.replace(sourceCode.getText(node.argument), "");

			return regex.test(statementWithoutArgument);
		}

		return {
			Program(node) {
				if (node.body.length > 0) {
					// Root nodes should have no indent
					checkNodesIndent(node.body, getNodeIndent(node).goodChar);
				}
			},

			ClassBody: blockIndentationCheck,

			BlockStatement: blockIndentationCheck,

			WhileStatement: blockLessNodes,

			ForStatement: blockLessNodes,

			ForInStatement: blockLessNodes,

Review comment (suggestion):
I think that `regexp/no-lazy-ends` is suggesting to remove the `;*?` part altogether:

>     1165:38  warning  The quantifier and the quantified element can be removed because the quantifier is lazy and has a minimum of 0                         regexp/no-lazy-ends

```suggestion
			const regex = /^return\s*\(\s*\)/u;
```

Code after:
				typeof providedSwitchIndent === "undefined"
					? getNodeIndent(switchNode).goodChar
					: providedSwitchIndent;
			let caseIndent;

			if (caseIndentStore[switchNode.loc.start.line]) {
				return caseIndentStore[switchNode.loc.start.line];
			}

			if (switchNode.cases.length > 0 && options.SwitchCase === 0) {
				caseIndent = switchIndent;
			} else {
				caseIndent = switchIndent + indentSize * options.SwitchCase;
			}

			caseIndentStore[switchNode.loc.start.line] = caseIndent;
			return caseIndent;
		}

		/**
		 * Checks whether a return statement is wrapped in ()
		 * @param {ASTNode} node node to examine
		 * @returns {boolean} the result
		 */
		function isWrappedInParenthesis(node) {
			const regex = /^return\s*\(\s*\)/u;

			const statementWithoutArgument = sourceCode
				.getText(node)
				.replace(sourceCode.getText(node.argument), "");

			return regex.test(statementWithoutArgument);
		}

		return {
			Program(node) {
				if (node.body.length > 0) {
					// Root nodes should have no indent
					checkNodesIndent(node.body, getNodeIndent(node).goodChar);
				}
			},

			ClassBody: blockIndentationCheck,

			BlockStatement: blockIndentationCheck,

			WhileStatement: blockLessNodes,

			ForStatement: blockLessNodes,

			ForInStatement: blockLessNodes,
Repository: eslint/eslint
File: lib/config/flat-config-schema.js (JavaScript)

Code before:
	}
}

/**
 * Validates that a value is valid rule severity.
 * @param {string} ruleId Rule name being configured.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {InvalidRuleSeverityError} If the value isn't a valid rule severity.
 */
function assertIsRuleSeverity(ruleId, value) {
	const severity = ruleSeverities.get(value);

	if (typeof severity === "undefined") {
		throw new InvalidRuleSeverityError(ruleId, value);
	}
}

/**
 * Validates that a given string is the form pluginName/objectName.
 * @param {string} value The string to check.
 * @returns {void}
 * @throws {TypeError} If the string isn't in the correct format.
 */
function assertIsPluginMemberName(value) {
	if (!/^[\w\-@$]+(?:\/[\w\-$]+)+$/iu.test(value)) {
		throw new TypeError(
			`Expected string in the form "pluginName/objectName" but found "${value}".`,
		);
	}
}

/**
 * Validates that a value is an object.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {TypeError} If the value isn't an object.
 */
function assertIsObject(value) {
	if (!isNonNullObject(value)) {
		throw new TypeError("Expected an object.");
	}
}

/**
 * The error type when there's an eslintrc-style options in a flat config.
 */
class IncompatibleKeyError extends Error {
	/**
	 * @param {string} key The invalid key.
	 */

Review comment (suggestion):
The added `^` changes the behavior of the regex. Most likely to the intended one, but I'm not sure if we want to make such changes in this PR or evaluate this separately as it might be a breaking change.

Code after:
	}
}

/**
 * Validates that a value is valid rule severity.
 * @param {string} ruleId Rule name being configured.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {InvalidRuleSeverityError} If the value isn't a valid rule severity.
 */
function assertIsRuleSeverity(ruleId, value) {
	const severity = ruleSeverities.get(value);

	if (typeof severity === "undefined") {
		throw new InvalidRuleSeverityError(ruleId, value);
	}
}

/**
 * Validates that a given string is the form pluginName/objectName.
 * @param {string} value The string to check.
 * @returns {void}
 * @throws {TypeError} If the string isn't in the correct format.
 */
function assertIsPluginMemberName(value) {
	if (!/[\w\-@$]+(?:\/[\w\-$]+)+$/iu.test(value)) {
		throw new TypeError(
			`Expected string in the form "pluginName/objectName" but found "${value}".`,
		);
	}
}

/**
 * Validates that a value is an object.
 * @param {any} value The value to check.
 * @returns {void}
 * @throws {TypeError} If the value isn't an object.
 */
function assertIsObject(value) {
	if (!isNonNullObject(value)) {
		throw new TypeError("Expected an object.");
	}
}

/**
 * The error type when there's an eslintrc-style options in a flat config.
 */
class IncompatibleKeyError extends Error {
	/**
	 * @param {string} key The invalid key.
	 */
Repository: eslint/eslint
File: packages/js/src/configs/eslint-recommended.js (JavaScript)

Code before:
/*
 * WARNING: This file is autogenerated using the tools/update-eslint-recommended.js
 * script. Do not edit manually.
 */
"use strict";

module.exports = Object.freeze({
	name: "@eslint/js/recommended",
	rules: Object.freeze({
        "constructor-super": "error",
        "for-direction": "error",
        "getter-return": "error",
        "no-async-promise-executor": "error",
        "no-case-declarations": "error",
        "no-class-assign": "error",
        "no-compare-neg-zero": "error",
        "no-cond-assign": "error",
        "no-const-assign": "error",
        "no-constant-binary-expression": "error",
        "no-constant-condition": "error",
        "no-control-regex": "error",
        "no-debugger": "error",
        "no-delete-var": "error",
        "no-dupe-args": "error",
        "no-dupe-class-members": "error",
        "no-dupe-else-if": "error",
        "no-dupe-keys": "error",
        "no-duplicate-case": "error",
        "no-empty": "error",
        "no-empty-character-class": "error",
        "no-empty-pattern": "error",
        "no-empty-static-block": "error",
        "no-ex-assign": "error",
        "no-extra-boolean-cast": "error",

Review comment (suggestion):
```suggestion
    name: "@eslint/js/recommended",
    rules: Object.freeze({
```

Code after:
/*
 * WARNING: This file is autogenerated using the tools/update-eslint-recommended.js
 * script. Do not edit manually.
 */
"use strict";

module.exports = Object.freeze({
    name: "@eslint/js/recommended",
    rules: Object.freeze({
        "constructor-super": "error",
        "for-direction": "error",
        "getter-return": "error",
        "no-async-promise-executor": "error",
        "no-case-declarations": "error",
        "no-class-assign": "error",
        "no-compare-neg-zero": "error",
        "no-cond-assign": "error",
        "no-const-assign": "error",
        "no-constant-binary-expression": "error",
        "no-constant-condition": "error",
        "no-control-regex": "error",
        "no-debugger": "error",
        "no-delete-var": "error",
        "no-dupe-args": "error",
        "no-dupe-class-members": "error",
        "no-dupe-else-if": "error",
        "no-dupe-keys": "error",
        "no-duplicate-case": "error",
        "no-empty": "error",
        "no-empty-character-class": "error",
        "no-empty-pattern": "error",
        "no-empty-static-block": "error",
        "no-ex-assign": "error",
        "no-extra-boolean-cast": "error",
Repository: eslint/eslint
File: tools/update-eslint-recommended.js (JavaScript)

Code before:
	if (!rule.meta.deprecated) {
		if (rule.meta.docs.recommended === true) {
			recommendedRule[ruleId] = "error";
		}
	}
}

const recommendedRulesText = JSON.stringify(
	recommendedRule,
	null,
	4,
).replaceAll("\n", "\n    ");

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------

const code = `/*
 * WARNING: This file is autogenerated using the tools/update-eslint-recommended.js
 * script. Do not edit manually.
 */
"use strict";

module.exports = Object.freeze({
	name: "@eslint/js/recommended",
	rules: Object.freeze(${recommendedRulesText}),
});
`;

fs.writeFileSync(
	"./packages/js/src/configs/eslint-recommended.js",
	code,
	"utf8",
);


Review comment (suggestion):
```suggestion
    name: "@eslint/js/recommended",
    rules: Object.freeze(${recommendedRulesText}),
```

Code after:
	if (!rule.meta.deprecated) {
		if (rule.meta.docs.recommended === true) {
			recommendedRule[ruleId] = "error";
		}
	}
}

const recommendedRulesText = JSON.stringify(
	recommendedRule,
	null,
	4,
).replaceAll("\n", "\n    ");

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------

const code = `/*
 * WARNING: This file is autogenerated using the tools/update-eslint-recommended.js
 * script. Do not edit manually.
 */
"use strict";

module.exports = Object.freeze({
    name: "@eslint/js/recommended",
    rules: Object.freeze(${recommendedRulesText}),
});
`;

fs.writeFileSync(
	"./packages/js/src/configs/eslint-recommended.js",
	code,
	"utf8",
);
Repository: eslint/eslint
File: lib/rules/no-empty.js (JavaScript)

Code before:

					if (
						sourceCode.commentsExistBetween(
							openingBrace,
							closingBrace,
						)
					) {
						return;
					}

					context.report({
						node,
						loc: {
							start: openingBrace.loc.start,
							end: closingBrace.loc.end,
						},
						messageId: "unexpected",
						data: { type: "switch" },
						suggest: [
							{
								messageId: "suggestComment",
								data: { type: "switch" },
								fix(fixer) {
									const range = [
										openingBrace.range[1],
										closingBrace.range[1] - 1,
									];

									return fixer.replaceTextRange(
										range,
										" /* empty */ ",
									);
								},
							},
						],
					});
				}
			},
		};
	},
};


Review comment (refactor):
```suggestion
										closingBrace.range[0],
```

To simplify a bit.

Code after:

					if (
						sourceCode.commentsExistBetween(
							openingBrace,
							closingBrace,
						)
					) {
						return;
					}

					context.report({
						node,
						loc: {
							start: openingBrace.loc.start,
							end: closingBrace.loc.end,
						},
						messageId: "unexpected",
						data: { type: "switch" },
						suggest: [
							{
								messageId: "suggestComment",
								data: { type: "switch" },
								fix(fixer) {
									const range = [
										openingBrace.range[1],
										closingBrace.range[0],
									];

									return fixer.replaceTextRange(
										range,
										" /* empty */ ",
									);
								},
							},
						],
					});
				}
			},
		};
	},
};
Repository: eslint/eslint
File: tools/internal-rules/multiline-comment-style.js (JavaScript)

Code before:
/**
 * @fileoverview A modified version of the `multiline-comment-style` rule that ignores banner comments.
 * @author Teddy Katz
 */

"use strict";

const ruleExtender = require("eslint-rule-extender");
const multilineCommentStyle = require("../../lib/rules/multiline-comment-style");

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

// The `no-invalid-meta` internal rule has a false positive here.
// eslint-disable-next-line internal-rules/no-invalid-meta -- Using rule composer
module.exports = ruleExtender(multilineCommentStyle, {
	reportOverrides(meta, context) {
		const sourceCode = context.sourceCode;
		const problemIndex = sourceCode.getIndexFromLoc(meta.loc.start);
		const reportedToken = sourceCode.getTokenByRangeStart(problemIndex, {
			includeComments: true,
		});

		if (
			reportedToken &&
			reportedToken.type === "Line" &&
			/^-{2,}$/u.test(reportedToken.value)
		) {
			return false; // filter out banner comments
		}

		return true;
	},
});


Review comment (suggestion):
```suggestion
// eslint-disable-next-line internal-rules/no-invalid-meta -- Using `ruleExtender`
```

Code after:
/**
 * @fileoverview A modified version of the `multiline-comment-style` rule that ignores banner comments.
 * @author Teddy Katz
 */

"use strict";

const ruleExtender = require("eslint-rule-extender");
const multilineCommentStyle = require("../../lib/rules/multiline-comment-style");

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

// The `no-invalid-meta` internal rule has a false positive here.
// eslint-disable-next-line internal-rules/no-invalid-meta -- Using `ruleExtender`
module.exports = ruleExtender(multilineCommentStyle, {
	reportOverrides(meta, context) {
		const sourceCode = context.sourceCode;
		const problemIndex = sourceCode.getIndexFromLoc(meta.loc.start);
		const reportedToken = sourceCode.getTokenByRangeStart(problemIndex, {
			includeComments: true,
		});

		if (
			reportedToken &&
			reportedToken.type === "Line" &&
			/^-{2,}$/u.test(reportedToken.value)
		) {
			return false; // filter out banner comments
		}

		return true;
	},
});