ronantakizawa/codereview-bench huggingface dataset:
Repository: eslint/eslint
File: tests/lib/rules/no-const-assign.js (JavaScript)

Code before:
ruleTester.run("no-const-assign", rule, {
	valid: [
		"const x = 0; { let x; x = 1; }",
		"const x = 0; function a(x) { x = 1; }",
		"const x = 0; foo(x);",
		"for (const x in [1,2,3]) { foo(x); }",
		"for (const x of [1,2,3]) { foo(x); }",
		"const x = {key: 0}; x.key = 1;",

		// ignores non constant.
		"var x = 0; x = 1;",
		"let x = 0; x = 1;",
		{
			code: "using resource = fn();",
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		{
			code: "await using resource = fn();",
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		"function x() {} x = 1;",
		"function foo(x) { x = 1; }",
		"class X {} X = 1;",
		"try {} catch (x) { x = 1; }",
	],
	invalid: [
		{
			code: "const x = 0; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const {a: x} = {a: 0}; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ({x} = {x: 1});",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{

Review comment (suggestion):
It might be confusing that these tests are in the `// ignores non constant.` group, since the variables are constant but just not reassigned in the code.

Code after:
ruleTester.run("no-const-assign", rule, {
	valid: [
		"const x = 0; { let x; x = 1; }",
		"const x = 0; function a(x) { x = 1; }",
		"const x = 0; foo(x);",
		"for (const x in [1,2,3]) { foo(x); }",
		"for (const x of [1,2,3]) { foo(x); }",
		"const x = {key: 0}; x.key = 1;",

		// ignores non constant.
		"var x = 0; x = 1;",
		"let x = 0; x = 1;",
		"function x() {} x = 1;",
		"function foo(x) { x = 1; }",
		"class X {} X = 1;",
		"try {} catch (x) { x = 1; }",
	],
	invalid: [
		{
			code: "const x = 0; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const {a: x} = {a: 0}; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ({x} = {x: 1});",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ({a: x = 1} = {});",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; x += 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ++x;",
			errors: [
Repository: eslint/eslint
File: tests/lib/rules/curly.js (JavaScript)

Code before:
			code: "for (var foo in bar) { \n if (foo) console.log(1); \n else console.log(2) \n }",
			options: ["multi-or-nest"],
		},
		{
			code: "for (var foo of bar) \n console.log(foo)",
			options: ["multi-or-nest"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "for (var foo of bar) { \n if (foo) console.log(1); \n else console.log(2) \n }",
			options: ["multi-or-nest"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "if (foo) { const bar = 'baz'; }",
			options: ["multi"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "if (foo) { const bar = 'baz'; }",
			options: ["multi"],
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		{
			code: "while (foo) { let bar = 'baz'; }",
			options: ["multi"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "for(;;) { function foo() {} }",
			options: ["multi"],
		},
		{
			code: "for (foo in bar) { class Baz {} }",
			options: ["multi"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "if (foo) { let bar; } else { baz(); }",
			options: ["multi", "consistent"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "if (foo) { bar(); } else { const baz = 'quux'; }",
			options: ["multi", "consistent"],
			languageOptions: { ecmaVersion: 6 },
		},
		{

Review comment (suggestion):
```suggestion
		{
			code: "if (foo) { using bar = 'baz'; }",
			options: ["multi"],
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		{
			code: "if (foo) { await using bar = 'baz'; }",
			options: ["multi"],
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
```

I'm guessing this should have been tests with `using` and `await using` to verify changes in `astUtils.areBracesNecessary`.

Code after:
			code: "for (var foo in bar) { \n if (foo) console.log(1); \n else console.log(2) \n }",
			options: ["multi-or-nest"],
		},
		{
			code: "for (var foo of bar) \n console.log(foo)",
			options: ["multi-or-nest"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "for (var foo of bar) { \n if (foo) console.log(1); \n else console.log(2) \n }",
			options: ["multi-or-nest"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "if (foo) { const bar = 'baz'; }",
			options: ["multi"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "if (foo) { using bar = 'baz'; }",
			options: ["multi"],
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		{
			code: "if (foo) { await using bar = 'baz'; }",
			options: ["multi"],
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		{
			code: "while (foo) { let bar = 'baz'; }",
			options: ["multi"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "for(;;) { function foo() {} }",
			options: ["multi"],
		},
		{
			code: "for (foo in bar) { class Baz {} }",
			options: ["multi"],
			languageOptions: { ecmaVersion: 6 },
		},
		{
			code: "if (foo) { let bar; } else { baz(); }",
			options: ["multi", "consistent"],
Repository: eslint/eslint
File: tests/lib/rules/no-const-assign.js (JavaScript)

Code before:
ruleTester.run("no-const-assign", rule, {
	valid: [
		"const x = 0; { let x; x = 1; }",
		"const x = 0; function a(x) { x = 1; }",
		"const x = 0; foo(x);",
		"for (const x in [1,2,3]) { foo(x); }",
		"for (const x of [1,2,3]) { foo(x); }",
		"const x = {key: 0}; x.key = 1;",

		// ignores non constant.
		"var x = 0; x = 1;",
		"let x = 0; x = 1;",
		{
			code: "using resource = f(); resource = g();",
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		{
			code: "await using resource = f(); resource = g();",
			languageOptions: {
				sourceType: "module",
				ecmaVersion: 2026,
			},
		},
		"function x() {} x = 1;",
		"function foo(x) { x = 1; }",
		"class X {} X = 1;",
		"try {} catch (x) { x = 1; }",
	],
	invalid: [
		{
			code: "const x = 0; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const {a: x} = {a: 0}; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ({x} = {x: 1});",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{

Review comment (suggestion):
Per https://github.com/eslint/eslint/issues/19792#issuecomment-2922568363, these cases should be `invalid`. I prepared a separate PR for this rule (https://github.com/eslint/eslint/pull/19892) so we can remove these tests.

Code after:
ruleTester.run("no-const-assign", rule, {
	valid: [
		"const x = 0; { let x; x = 1; }",
		"const x = 0; function a(x) { x = 1; }",
		"const x = 0; foo(x);",
		"for (const x in [1,2,3]) { foo(x); }",
		"for (const x of [1,2,3]) { foo(x); }",
		"const x = {key: 0}; x.key = 1;",

		// ignores non constant.
		"var x = 0; x = 1;",
		"let x = 0; x = 1;",
		"function x() {} x = 1;",
		"function foo(x) { x = 1; }",
		"class X {} X = 1;",
		"try {} catch (x) { x = 1; }",
	],
	invalid: [
		{
			code: "const x = 0; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const {a: x} = {a: 0}; x = 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ({x} = {x: 1});",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ({a: x = 1} = {});",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; x += 1;",
			errors: [
				{ messageId: "const", data: { name: "x" }, type: "Identifier" },
			],
		},
		{
			code: "const x = 0; ++x;",
			errors: [
Repository: eslint/eslint
File: tests/lib/rules/one-var.js (JavaScript)

Code before:
		{
			code: "class C { static { let a; let b = 0; } }",
			options: [{ initialized: "consecutive" }],
			languageOptions: { ecmaVersion: 2022 },
		},
		{
			code: "class C { static { var a; var b = 0; } }",
			options: [{ initialized: "consecutive" }],
			languageOptions: { ecmaVersion: 2022 },
		},
		{
			code: "using a = 0; using b = 1;",
			options: ["consecutive"],
			languageOptions: {
				ecmaVersion: 2026,
				sourceType: "module",
			},
		},
		{
			code: "await using a = 0; await using b = 1;",
			options: ["consecutive"],
			languageOptions: {
				ecmaVersion: 2026,
				sourceType: "module",
			},
		},
	],
	invalid: [
		{
			code: "var bar = true, baz = false;",
			output: "var bar = true; var baz = false;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "function foo() { var bar = true, baz = false; }",
			output: "function foo() { var bar = true; var baz = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],

Review comment (suggestion):
I think these cases should be `invalid` for this rule. It might be best to remove tests for this rule and update it separately (https://github.com/eslint/eslint/issues/19792#issuecomment-3018032403).

Code after:
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "function foo() { var bar = true, baz = false; }",
			output: "function foo() { var bar = true; var baz = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "if (foo) { var bar = true, baz = false; }",
			output: "if (foo) { var bar = true; var baz = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "switch (foo) { case bar: var baz = true, quux = false; }",
			output: "switch (foo) { case bar: var baz = true; var quux = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "switch (foo) { default: var baz = true, quux = false; }",
			output: "switch (foo) { default: var baz = true; var quux = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
Repository: eslint/eslint
File: tests/lib/rules/one-var.js (JavaScript)

Code before:
		{
			code: "class C { static { let a; let b = 0; } }",
			options: [{ initialized: "consecutive" }],
			languageOptions: { ecmaVersion: 2022 },
		},
		{
			code: "class C { static { var a; var b = 0; } }",
			options: [{ initialized: "consecutive" }],
			languageOptions: { ecmaVersion: 2022 },
		},
		{
			code: "using a = 0; using b = 1;",
			options: ["consecutive"],
			languageOptions: {
				ecmaVersion: 2026,
				sourceType: "module",
			},
		},
		{
			code: "await using a = 0; await using b = 1;",
			options: ["consecutive"],
			languageOptions: {
				ecmaVersion: 2026,
				sourceType: "module",
			},
		},
	],
	invalid: [
		{
			code: "var bar = true, baz = false;",
			output: "var bar = true; var baz = false;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "function foo() { var bar = true, baz = false; }",
			output: "function foo() { var bar = true; var baz = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],

Review comment (suggestion):
It seems that `one-var` tests that should be `invalid` are still included in this PR as `valid`.

Code after:
		{
			code: "class C { static { let a; let b = 0; } }",
			options: [{ initialized: "consecutive" }],
			languageOptions: { ecmaVersion: 2022 },
		},
		{
			code: "class C { static { var a; var b = 0; } }",
			options: [{ initialized: "consecutive" }],
			languageOptions: { ecmaVersion: 2022 },
		},
	],
	invalid: [
		{
			code: "var bar = true, baz = false;",
			output: "var bar = true; var baz = false;",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "function foo() { var bar = true, baz = false; }",
			output: "function foo() { var bar = true; var baz = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "if (foo) { var bar = true, baz = false; }",
			output: "if (foo) { var bar = true; var baz = false; }",
			options: ["never"],
			errors: [
				{
					messageId: "split",
					data: { type: "var" },
					type: "VariableDeclaration",
				},
			],
		},
		{
			code: "switch (foo) { case bar: var baz = true, quux = false; }",
			output: "switch (foo) { case bar: var baz = true; var quux = false; }",
Repository: eslint/eslint
File: lib/shared/relative-module-resolver.js (JavaScript)

Code before:
const createRequire = Module.createRequire;

/**
 * Resolves a Node module relative to another module
 * @param {string} moduleName The name of a Node module, or a path to a Node module.
 * @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
 * a file rather than a directory, but the file need not actually exist.
 * @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
 * @throws {Error} When the module cannot be resolved.
 */
function resolve(moduleName, relativeToPath) {
	try {
		return createRequire(relativeToPath).resolve(moduleName);
	} catch (error) {
		// This `if` block is for older Node.js than 12.0.0. We can remove this block in the future.
		if (
			typeof error === "object" &&
			error !== null &&
			error.code === "MODULE_NOT_FOUND" &&
			!error.requireStack &&
			error.message.includes(moduleName)
		) {
			error.message += `\nRequire stack:\n- ${relativeToPath}`;
		}
		throw error;
	}
}

exports.resolve = resolve;


Review comment (suggestion):
It seems safe to remove the `if` block as the comment suggests. Maybe some old versions of Node.js did not include the `requireStack` property in the error object, but this should be fixed now.

```suggestion
	return createRequire(relativeToPath).resolve(moduleName);
```

Code after:
/**
 * Utility for resolving a module relative to another module
 * @author Teddy Katz
 */

"use strict";

const Module = require("node:module");

/*
 * `Module.createRequire` is added in v12.2.0. It supports URL as well.
 * We only support the case where the argument is a filepath, not a URL.
 */
const createRequire = Module.createRequire;

/**
 * Resolves a Node module relative to another module
 * @param {string} moduleName The name of a Node module, or a path to a Node module.
 * @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
 * a file rather than a directory, but the file need not actually exist.
 * @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
 * @throws {Error} When the module cannot be resolved.
 */
function resolve(moduleName, relativeToPath) {
	return createRequire(relativeToPath).resolve(moduleName);
}

exports.resolve = resolve;
Repository: eslint/eslint
File: lib/types/index.d.ts (TypeScript)

Code before:
		 * An object indicating which additional language features you'd like to use.
		 *
		 * @see https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options
		 */
		ecmaFeatures?:
			| {
					globalReturn?: boolean | undefined;
					impliedStrict?: boolean | undefined;
					jsx?: boolean | undefined;
					experimentalObjectRestSpread?: boolean | undefined;
					[key: string]: any;
			  }
			| undefined;
		[key: string]: any;
	}

	interface LintOptions {
		filename?: string | undefined;
		preprocess?: ((code: string) => string[]) | undefined;
		postprocess?:
			| ((problemLists: LintMessage[][]) => LintMessage[])
			| undefined;
		filterCodeBlock?: (
			filename: string,
			text: string,
		) => boolean | undefined;
		disableFixes?: boolean | undefined;
		allowInlineConfig?: boolean | undefined;
		reportUnusedDisableDirectives?: boolean | undefined;
	}

	interface LintSuggestion {
		/** A short description. */
		desc: string;

		/** Fix result info. */
		fix: Rule.Fix;

		/** Id referencing a message for the description. */
		messageId?: string | undefined;
	}

	interface LintMessage {
		/** The 1-based column number. */
		column: number;

		/** The 1-based line number. */
		line: number;

		/** The 1-based column number of the end location. */
		endColumn?: number | undefined;

Review comment (suggestion):
```suggestion
		filterCodeBlock?: ((
			filename: string,
			text: string,
		) => boolean) | undefined;
```

Maybe there should be a test to ensure that `filterCodeBlock` can be set to `undefined`. This is not the same as a function returning `boolean | undefined`.

Code after:
		 * An object indicating which additional language features you'd like to use.
		 *
		 * @see https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options
		 */
		ecmaFeatures?:
			| {
					globalReturn?: boolean | undefined;
					impliedStrict?: boolean | undefined;
					jsx?: boolean | undefined;
					experimentalObjectRestSpread?: boolean | undefined;
					[key: string]: any;
			  }
			| undefined;
		[key: string]: any;
	}

	interface LintOptions {
		filename?: string | undefined;
		preprocess?: ((code: string) => string[]) | undefined;
		postprocess?:
			| ((problemLists: LintMessage[][]) => LintMessage[])
			| undefined;
		filterCodeBlock?:
			| ((filename: string, text: string) => boolean)
			| undefined;
		disableFixes?: boolean | undefined;
		allowInlineConfig?: boolean | undefined;
		reportUnusedDisableDirectives?: boolean | undefined;
	}

	interface LintSuggestion {
		/** A short description. */
		desc: string;

		/** Fix result info. */
		fix: Rule.Fix;

		/** Id referencing a message for the description. */
		messageId?: string | undefined;
	}

	interface LintMessage {
		/** The 1-based column number. */
		column: number;

		/** The 1-based line number. */
		line: number;

		/** The 1-based column number of the end location. */
		endColumn?: number | undefined;
Repository: eslint/eslint
File: lib/rules/no-restricted-properties.js (JavaScript)

Code before:
					? ` ${matchedObjectProperty.message}`
					: "";
				const allowedPropertiesMessage =
					matchedObjectProperty.allowProperties
						? ` Only allowed properties can be used - ${matchedObjectProperty.allowProperties.join(", ")}.`
						: "";

				context.report({
					node,
					messageId: "restrictedObjectProperty",
					data: {
						objectName,
						propertyName,
						message,
						allowedPropertiesMessage,
					},
				});
			} else if (
				globalMatchedProperty &&
				!isAllowed(objectName, globalMatchedProperty.allowObjects)
			) {
				const message = globalMatchedProperty.message
					? ` ${globalMatchedProperty.message}`
					: "";
				const allowedObjectsMessage = globalMatchedProperty.allowObjects
					? ` It can be used only in allowed objects - ${globalMatchedProperty.allowObjects.join(", ")}.`
					: "";

				context.report({
					node,
					messageId: "restrictedProperty",
					data: {
						propertyName,
						message,
						allowedObjectsMessage,
					},
				});
			}
		}

		return {
			MemberExpression(node) {
				checkPropertyAccess(
					node,
					node.object && node.object.name,
					astUtils.getStaticPropertyName(node),
				);
			},
			ObjectPattern(node) {
				let objectName = null;


Review comment (suggestion):
For clarity.
```suggestion
					? ` Property ${propertyName} is only allowed on these objects: ${globalMatchedProperty.allowObjects.join(", ")}.`
```

Code after:
					? ` ${matchedObjectProperty.message}`
					: "";
				const allowedPropertiesMessage =
					matchedObjectProperty.allowProperties
						? ` Only these properties are allowed: ${matchedObjectProperty.allowProperties.join(", ")}.`
						: "";

				context.report({
					node,
					messageId: "restrictedObjectProperty",
					data: {
						objectName,
						propertyName,
						message,
						allowedPropertiesMessage,
					},
				});
			} else if (
				globalMatchedProperty &&
				!isAllowed(objectName, globalMatchedProperty.allowObjects)
			) {
				const message = globalMatchedProperty.message
					? ` ${globalMatchedProperty.message}`
					: "";
				const allowedObjectsMessage = globalMatchedProperty.allowObjects
					? ` Property '${propertyName}' is only allowed on these objects: ${globalMatchedProperty.allowObjects.join(", ")}.`
					: "";

				context.report({
					node,
					messageId: "restrictedProperty",
					data: {
						propertyName,
						message,
						allowedObjectsMessage,
					},
				});
			}
		}

		return {
			MemberExpression(node) {
				checkPropertyAccess(
					node,
					node.object && node.object.name,
					astUtils.getStaticPropertyName(node),
				);
			},
			ObjectPattern(node) {
				let objectName = null;