ronantakizawa/codereview-bench huggingface dataset:
Repository: eslint/eslint
File: lib/types/index.d.ts (TypeScript)

Code before:
		| 2022
		| 2023
		| 2024
		| 2025
		| 2026
		| "latest";

	/**
	 * The type of JavaScript source code.
	 */
	type SourceType = "script" | "module" | "commonjs";

	/**
	 * ESLint legacy configuration.
	 *
	 * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/)
	 */
	interface BaseConfig<
		Rules extends RulesRecord = RulesRecord,
		OverrideRules extends RulesRecord = Rules,
	> extends HasRules<Rules> {
		$schema?: string | undefined;

		/**
		 * An environment provides predefined global variables.
		 *
		 * @see [Environments](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-environments)
		 */
		env?: { [name: string]: boolean } | undefined;

		/**
		 * Extending configuration files.
		 *
		 * @see [Extends](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#extending-configuration-files)
		 */
		extends?: string | string[] | undefined;

		/**
		 * Specifying globals.
		 *
		 * @see [Globals](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-globals)
		 */
		globals?: Linter.Globals | undefined;

		/**
		 * Disable processing of inline comments.
		 *
		 * @see [Disabling Inline Comments](https://eslint.org/docs/latest/use/configure/rules-deprecated#disabling-inline-comments)
		 */
		noInlineConfig?: boolean | undefined;


Review comment (suggestion):
`suggestions` also may be `null` or `false` as the rule tester checks for a [falsy value](https://github.com/eslint/eslint/blob/6b0c08b106aa66f2e9fa484282f0eb63c64a1215/lib/rule-tester/rule-tester.js#L1290)

Code after:
		only?: boolean;
		before?: () => void;
		after?: () => void;
	}

	interface SuggestionOutput {
		messageId?: string;
		desc?: string;
		data?: Record<string, unknown> | undefined;
		output: string;
	}

	interface InvalidTestCase extends ValidTestCase {
		errors: number | Array<TestCaseError | string | RegExp>;
		output?: string | null | undefined;
	}

	interface TestCaseError {
		message?: string | RegExp;
		messageId?: string;
		data?: any;
		line?: number | undefined;
		column?: number | undefined;
		endLine?: number | undefined;
		endColumn?: number | undefined;
		suggestions?: SuggestionOutput[] | number | undefined;
	}
}

// #endregion
Repository: eslint/eslint
File: lib/types/index.d.ts (TypeScript)

Code before:

	/**
	 * An array containing the rule severity level, followed by the rule options.
	 *
	 * @see [Rules](https://eslint.org/docs/latest/use/configure/rules)
	 */
	type RuleSeverityAndOptions<Options extends any[] = any[]> = [
		RuleSeverity,
		...Partial<Options>,
	];

	/**
	 * The severity level for the rule or an array containing the rule severity level, followed by the rule options.
	 *
	 * @see [Rules](https://eslint.org/docs/latest/use/configure/rules)
	 */
	type RuleEntry<Options extends any[] = any[]> =
		| RuleSeverity
		| RuleSeverityAndOptions<Options>;

	/**
	 * The rules config object is a key/value map of rule names and their severity and options.
	 */
	interface RulesRecord {
		[rule: string]: RuleEntry;
	}

	/**
	 * A configuration object that may have a `rules` block.
	 */
	interface HasRules<Rules extends RulesRecord = RulesRecord> {
		rules?: Partial<Rules> | undefined;
	}

	/**
	 * The ECMAScript version of the code being linted.
	 */
	type EcmaVersion =
		| 3
		| 5
		| 6
		| 7
		| 8
		| 9
		| 10
		| 11
		| 12
		| 13
		| 14
		| 15
		| 16

Review comment (suggestion):
I'm not sure if these methods should be included in the types because none of them is documented.

Code after:
	 * @return The formatter output.
	 */
	type FormatterFunction = (
		results: LintResult[],
		context: LintResultData,
	) => string | Promise<string>;

	// Docs reference the types by those name
	type EditInfo = Rule.Fix;
}

// #endregion

export function loadESLint(options?: {
	useFlatConfig?: boolean | undefined;
}): Promise<typeof ESLint>;

// #region RuleTester

export class RuleTester {
	static describe: ((...args: any) => any) | null;
	static it: ((...args: any) => any) | null;
	static itOnly: ((...args: any) => any) | null;
	static setDefaultConfig(config: Linter.Config): void;
	static getDefaultConfig(): Linter.Config;
	static resetDefaultConfig(): void;

	constructor(config?: Linter.Config);

	run(
		name: string,
		rule: RuleDefinition,
		tests: {
			valid: Array<string | RuleTester.ValidTestCase>;
			invalid: RuleTester.InvalidTestCase[];
		},
	): void;

	static only(
		item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
	): RuleTester.ValidTestCase | RuleTester.InvalidTestCase;
}

export namespace RuleTester {
	interface ValidTestCase
		extends Omit<
			Linter.Config,
			| "name"
			| "basePath"
			| "files"
			| "ignores"
Repository: eslint/eslint
File: lib/types/index.d.ts (TypeScript)

Code before:
	static describe: ((...args: any) => any) | null;
	static it: ((...args: any) => any) | null;
	static itOnly: ((...args: any) => any) | null;
	static setDefaultConfig(config: Linter.Config): void;
	static getDefaultConfig(): Linter.Config;
	static resetDefaultConfig(): void;

	constructor(config?: Linter.Config);

	run(
		name: string,
		rule: RuleDefinition,
		tests: {
			valid: Array<string | RuleTester.ValidTestCase>;
			invalid: RuleTester.InvalidTestCase[];
		},
	): void;

	static only(
		item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
	): RuleTester.ValidTestCase | RuleTester.InvalidTestCase;
}

export namespace RuleTester {
	interface ValidTestCase
		extends Omit<Linter.Config, "name" | "basePath" | "files" | "ignores"> {
		name?: string;
		code: string;
		options?: any[];
		filename?: string | undefined;
		only?: boolean;
		before?: () => void;
		after?: () => void;
	}

	interface SuggestionOutput {
		messageId?: string;
		desc?: string;
		data?: Record<string, unknown> | undefined;
		output: string;
	}

	interface InvalidTestCase extends ValidTestCase {
		errors: number | Array<TestCaseError | string | RegExp>;
		output?: string | null | undefined;
	}

	interface TestCaseError {
		message?: string | RegExp;
		messageId?: string;
		data?: any;

Review comment (bug):
The following `Linter.Config` properties maybe should also be excluded:
- `linterOptions`: this would only make sense for rules for inline configuration
- `plugins`: only if we want to address a `language` or `processor` by its name instead of passing it in directly
- `rules`: we want to test the rule in isolation (an edge case would be rules which have a side-effect like `context.markVariableAsUsed`)

Code after:
	static describe: ((...args: any) => any) | null;
	static it: ((...args: any) => any) | null;
	static itOnly: ((...args: any) => any) | null;
	static setDefaultConfig(config: Linter.Config): void;
	static getDefaultConfig(): Linter.Config;
	static resetDefaultConfig(): void;

	constructor(config?: Linter.Config);

	run(
		name: string,
		rule: RuleDefinition,
		tests: {
			valid: Array<string | RuleTester.ValidTestCase>;
			invalid: RuleTester.InvalidTestCase[];
		},
	): void;

	static only(
		item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
	): RuleTester.ValidTestCase | RuleTester.InvalidTestCase;
}

export namespace RuleTester {
	interface ValidTestCase
		extends Omit<
			Linter.Config,
			| "name"
			| "basePath"
			| "files"
			| "ignores"
			| "linterOptions"
			| "plugins"
			| "rules"
		> {
		name?: string;
		code: string;
		options?: any[];
		filename?: string | undefined;
		only?: boolean;
		before?: () => void;
		after?: () => void;
	}

	interface SuggestionOutput {
		messageId?: string;
		desc?: string;
		data?: Record<string, unknown> | undefined;
		output: string;
	}
Repository: eslint/eslint
File: tests/lib/rule-tester/rule-tester.js (JavaScript)

Code before:
				"Something happened in before()",
			);
			sinon.assert.calledOnce(hookBefore);
			sinon.assert.calledOnce(hookAfter);
			assert.throws(
				() =>
					ruleTester.run(ruleName, rule, {
						valid: [],
						invalid: [
							{
								code: "var onlyValid = 42;",
								errors: [/^Bad var/u],
								output: " onlyValid = 42;",
								before: hookBefore,
								after: hookAfter,
							},
						],
					}),
				"Something happened in before()",
			);
			sinon.assert.calledTwice(hookBefore);
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			runValidTests([{ code: "" }]);
			runValidTests([{ code: "", errors: [] }]);
			runValidTests([{ code: "", errors: 0 }]);

			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property`/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property`/u);

Review comment (suggestion):
Currently, it only includes the assertions added in the change. I plan to move more related tests here in another PR.

Code after:
				"Something happened in before()",
			);
			sinon.assert.calledOnce(hookBefore);
			sinon.assert.calledOnce(hookAfter);
			assert.throws(
				() =>
					ruleTester.run(ruleName, rule, {
						valid: [],
						invalid: [
							{
								code: "var onlyValid = 42;",
								errors: [/^Bad var/u],
								output: " onlyValid = 42;",
								before: hookBefore,
								after: hookAfter,
							},
						],
					}),
				"Something happened in before()",
			);
			sinon.assert.calledTwice(hookBefore);
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: 0 }]);
			}, /Valid test case must not have 'errors' property/u);
Repository: eslint/eslint
File: tests/lib/rule-tester/rule-tester.js (JavaScript)

Code before:
								after: hookAfter,
							},
						],
					}),
				"Something happened in before()",
			);
			sinon.assert.calledTwice(hookBefore);
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			runValidTests([{ code: "" }]);
			runValidTests([{ code: "", errors: [] }]);
			runValidTests([{ code: "", errors: 0 }]);

			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property`/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property`/u);
		});

		it("Valid test case must not have 'output' property", () => {
			runValidTests([{ code: "" }]);

			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", output: null }]);
			}, /Valid test case must not have 'output' property/u);
		});
	});

Review comment (bug):
Can you please the "valid" and "invalid" examples up in multiple test cases as this helps when debugging.
The same for the added tests for `output`.

Code after:
								after: hookAfter,
							},
						],
					}),
				"Something happened in before()",
			);
			sinon.assert.calledTwice(hookBefore);
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: 0 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [] }]);
			}, /Valid test case must not have 'errors' property/u);
		});

		it("Valid test case can have 'errors' property set to undefined", () => {
			runValidTests([{ code: "", errors: void 0 }]);
		});

		it("Valid test case must not have 'output' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);
Repository: eslint/eslint
File: tests/lib/rule-tester/rule-tester.js (JavaScript)

Code before:
					}),
				"Something happened in before()",
			);
			sinon.assert.calledTwice(hookBefore);
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property`/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property`/u);
		});

		it("Valid test case must not have 'output' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", output: null }]);
			}, /Valid test case must not have 'output' property/u);
		});
	});

	it("should not throw an error when everything passes", () => {
		ruleTester.run(
			"no-eval",
			require("../../fixtures/testers/rule-tester/no-eval"),
			{
				valid: ["Eval(foo)"],
				invalid: [
					{

Review comment (suggestion):
```suggestion
			}, /Valid test case must not have 'errors' property/u);
```

Code after:
					}),
				"Something happened in before()",
			);
			sinon.assert.calledTwice(hookBefore);
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: 0 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [] }]);
			}, /Valid test case must not have 'errors' property/u);
		});

		it("Valid test case can have 'errors' property set to undefined", () => {
			runValidTests([{ code: "", errors: void 0 }]);
		});

		it("Valid test case must not have 'output' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", output: null }]);
Repository: eslint/eslint
File: tests/lib/rule-tester/rule-tester.js (JavaScript)

Code before:
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property`/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property`/u);
		});

		it("Valid test case must not have 'output' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", output: null }]);
			}, /Valid test case must not have 'output' property/u);
		});
	});

	it("should not throw an error when everything passes", () => {
		ruleTester.run(
			"no-eval",
			require("../../fixtures/testers/rule-tester/no-eval"),
			{
				valid: ["Eval(foo)"],
				invalid: [
					{
						code: "eval(foo)",
						errors: [{ message: "eval sucks." }],
					},
				],

Review comment (suggestion):
```suggestion
			}, /Valid test case must not have 'errors' property/u);
```

Code after:
			sinon.assert.calledTwice(hookAfter);
		});
	});

	describe("assert valid test cases", () => {
		/**
		 * Runs valid tests
		 * @param {Array<string|object>} valid Valid tests
		 * @returns {void}
		 */
		function runValidTests(valid) {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: 0 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [] }]);
			}, /Valid test case must not have 'errors' property/u);
		});

		it("Valid test case can have 'errors' property set to undefined", () => {
			runValidTests([{ code: "", errors: void 0 }]);
		});

		it("Valid test case must not have 'output' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", output: null }]);
			}, /Valid test case must not have 'output' property/u);
		});

		it("Valid test case can have 'output' property set to undefined", () => {
Repository: eslint/eslint
File: tests/lib/rule-tester/rule-tester.js (JavaScript)

Code before:
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property`/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property`/u);
		});

		it("Valid test case must not have 'output' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", output: null }]);
			}, /Valid test case must not have 'output' property/u);
		});
	});

	it("should not throw an error when everything passes", () => {
		ruleTester.run(
			"no-eval",
			require("../../fixtures/testers/rule-tester/no-eval"),
			{
				valid: ["Eval(foo)"],
				invalid: [
					{
						code: "eval(foo)",
						errors: [{ message: "eval sucks." }],
					},
				],
			},
		);
	});

	it("should throw correct error when valid code is invalid and enables other core rule", () => {
		assert.throws(() => {
			ruleTester.run(
				"no-eval",
				require("../../fixtures/testers/rule-tester/no-eval"),
				{
					valid: ["/*eslint semi: 2*/ eval(foo);"],
					invalid: [
						{

Review comment (bug):
It would be good to also add tests with `errors: 0` (fails) and `errors: void 0` (passes).

Code after:
				require("../../fixtures/testers/rule-tester/no-eval"),
				{ valid, invalid: [] },
			);
		}

		it("Valid test case must not have 'errors' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", errors: 1 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [{ message: "foo" }] }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: 0 }]);
			}, /Valid test case must not have 'errors' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", errors: [] }]);
			}, /Valid test case must not have 'errors' property/u);
		});

		it("Valid test case can have 'errors' property set to undefined", () => {
			runValidTests([{ code: "", errors: void 0 }]);
		});

		it("Valid test case must not have 'output' property", () => {
			assert.throws(() => {
				runValidTests([{ code: "", output: "" }]);
			}, /Valid test case must not have 'output' property/u);

			assert.throws(() => {
				runValidTests([{ code: "", output: null }]);
			}, /Valid test case must not have 'output' property/u);
		});

		it("Valid test case can have 'output' property set to undefined", () => {
			runValidTests([{ code: "", output: void 0 }]);
		});
	});

	it("should not throw an error when everything passes", () => {
		ruleTester.run(
			"no-eval",
			require("../../fixtures/testers/rule-tester/no-eval"),
			{
				valid: ["Eval(foo)"],
				invalid: [
					{
						code: "eval(foo)",