nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: avajs/eslint-plugin-ava
Pull request #303 (2020-06-21 22:12:09)

Support assertion message in `t.timeout()
Updating the eslint plugin to support the new `t.timeout(ms, message?)` custom assertion message as described by https://github.com/avajs/ava/pull/2524.

Tried to update existing tests to accommodate existing tests with similar conditions, but please let me know If additional work is required. 


Patch:
diff --git a/rules/assertion-arguments.js b/rules/assertion-arguments.js
index e79cd43..171ce24 100644
--- a/rules/assertion-arguments.js
+++ b/rules/assertion-arguments.js
@@ -78,7 +78,7 @@ const expectedNbArguments = {
 	},
 	timeout: {
 		min: 1,
-		max: 1
+		max: 2
 	}
 };
 


Test patch:
diff --git a/test/assertion-arguments.js b/test/assertion-arguments.js
index ed59a51..1bd446b 100644
--- a/test/assertion-arguments.js
+++ b/test/assertion-arguments.js
@@ -55,7 +55,7 @@ ruleTester.run('assertion-arguments', rule, {
 		testCase(false, 't.snapshot(value, \'message\');'),
 		testCase(false, 't.context.plan();'),
 		testCase(false, 't.teardown(() => {});'),
-		testCase(false, 't.timeout(100);'),
+		testCase(false, 't.timeout(100, \'message\');'),
 		testCase(false, 'foo.t.plan();'),
 		// Shouldn't be triggered since it's not a test file
 		testCase(false, 't.true(true);', false, false),
@@ -106,7 +106,7 @@ ruleTester.run('assertion-arguments', rule, {
 		testCase('always', 't.is.skip(\'same\', \'same\', \'message\');'),
 		testCase('always', 't.snapshot(value, \'message\');'),
 		testCase('always', 't.teardown(() => {});'),
-		testCase('always', 't.timeout(100);'),
+		testCase('always', 't.timeout(100, \'message\');'),
 		testCase('always', 't.try(tt => tt.pass());'),
 		testCase('always', 't.try(tt => tt.pass(), 1, 2);'),
 		testCase('always', 't.try(\'title\', tt => tt.pass(), 1, 2);'),
@@ -215,7 +215,7 @@ ruleTester.run('assertion-arguments', rule, {
 		testCase(false, 't.is.skip(\'same\', \'same\', \'message\', \'extra argument\');', tooManyError(3)),
 		testCase(false, 't.snapshot(value, \'message\', \'extra argument\');', tooManyError(2)),
 		testCase(false, 't.teardown(() => {}, \'extra argument\');', tooManyError(1)),
-		testCase(false, 't.timeout(1, \'extra argument\');', tooManyError(1)),
+		testCase(false, 't.timeout(1, \'message\', \'extra argument\');', tooManyError(2)),
 
 		testCase('always', 't.pass();', missingError),
 		testCase('always', 't.fail();', missingError),
Repository: avajs/eslint-plugin-ava
Pull request #350 (2023-01-16 23:20:26)

fix: guard against type errors in prefer-t-regex
fixes some of the prefer-t-regex issues. #346 #347


spence-s: Updated for @sindresorhus preferences. 

Note the added test cases that currently cause this rule to throw 😅.
sindresorhus: I think you misunderstood me in https://github.com/avajs/eslint-plugin-ava/pull/350/files#r1072500429. I meant `if (!lookup) { return false }`. Because the current check will allow undefined to continue in the function.
spence-s: yes - ha did misunderstand, but good call!

Patch:
diff --git a/rules/prefer-t-regex.js b/rules/prefer-t-regex.js
index 5cf4dc9..6d103cf 100644
--- a/rules/prefer-t-regex.js
+++ b/rules/prefer-t-regex.js
@@ -51,6 +51,10 @@ const create = context => {
 	```
 	*/
 	const findRootReference = node => {
+		if (!node) {
+			return;
+		}
+
 		if (node.type === 'Identifier') {
 			const reference = findReference(node.name);
 
@@ -80,18 +84,31 @@ const create = context => {
 	2. `RegExp` class can't be looked up so the function just checks for the name `RegExp`.
 	*/
 	const isRegExp = lookup => {
+		if (!lookup) {
+			return false;
+		}
+
 		if (lookup.regex) {
 			return true;
 		}
 
 		// Look up references in case it's a variable or RegExp declaration.
 		const reference = findRootReference(lookup);
+
+		if (!reference) {
+			return false;
+		}
+
 		return reference.regex ?? reference.name === 'RegExp';
 	};
 
 	const booleanHandler = node => {
 		const firstArg = node.arguments[0];
 
+		if (!firstArg) {
+			return;
+		}
+
 		const isFunctionCall = firstArg.type === 'CallExpression';
 		if (!isFunctionCall || !firstArg.callee.property) {
 			return;
@@ -144,6 +161,11 @@ const create = context => {
 		}
 
 		const matchee = secondArgumentIsRegex ? firstArg : secondArg;
+
+		if (!matchee) {
+			return;
+		}
+
 		const regex = secondArgumentIsRegex ? secondArg : firstArg;
 
 		const booleanFixer = assertion => fixer => {
@@ -179,7 +201,12 @@ const create = context => {
 		CallExpression: visitIf([
 			ava.isInTestFile,
 			ava.isInTestNode,
-		])(node => {
+		],
+		)(node => {
+			if (!node?.callee?.property) {
+				return;
+			}
+
 			const isAssertion = node.callee.type === 'MemberExpression'
 				&& util.getNameOfRootNodeObject(node.callee) === 't';
 


Test patch:
diff --git a/test/prefer-t-regex.js b/test/prefer-t-regex.js
index f1cc44c..cd9de1e 100644
--- a/test/prefer-t-regex.js
+++ b/test/prefer-t-regex.js
@@ -36,8 +36,16 @@ ruleTester.run('prefer-t-regex', rule, {
 		header + 'test(t => t.regex(foo, RegExp(/\\d+/)));',
 		// Shouldn't be triggered since it's not a test file
 		'test(t => t.true(/\\d+/.test("foo")));',
-		// Not valid, but it shouldn't cause errors
 		'test(t => t.true());',
+		// These shouldn't cause errors as this rule affects them.
+		// This rule would crash on the following.
+		header + 'test(t => t.true());',
+		header + 'test(t => t.is(true))',
+		header + 'test(t => t.is())',
+		header + 'test(t => t.false())',
+		header + 'test(t => t.falsy())',
+		header + 'test(t => t.truthy())',
+		header + 'test(t => t.deepEqual(true))',
 	],
 	invalid: [
 		{