From 05e9c32f9534c6cb551a5d2557837f44010657bf Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Fri, 15 May 2026 21:01:51 +0200 Subject: [PATCH 1/2] Update assertion-arguments rule to handle formatAsCodeBlock snapshot argument --- rules/assertion-arguments.js | 25 ++++++++++++++++++++++++- test/assertion-arguments.js | 10 ++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/rules/assertion-arguments.js b/rules/assertion-arguments.js index 9266819..fd4b182 100644 --- a/rules/assertion-arguments.js +++ b/rules/assertion-arguments.js @@ -81,7 +81,7 @@ const expectedNbArguments = { }, snapshot: { min: 1, - max: 2, + max: 3, }, teardown: { min: 1, @@ -267,6 +267,29 @@ const create = context => { return; } + if (firstNonSkipMember === 'snapshot') { + if (gottenArguments < 1) { + context.report({node, messageId: MESSAGE_ID_TOO_FEW, data: {min: 1}}); + return; + } + + const hasOptionsArg = gottenArguments >= 2 && !isString(node.arguments[1]); + const effectiveMax = hasOptionsArg ? 3 : 2; + + if (gottenArguments > effectiveMax) { + context.report({node, messageId: MESSAGE_ID_TOO_MANY, data: {max: effectiveMax}}); + } else if (enforcesMessage) { + const hasMessage = hasOptionsArg ? gottenArguments === 3 : gottenArguments === 2; + if (!hasMessage && shouldHaveMessage) { + context.report({node, messageId: MESSAGE_ID_MISSING_MESSAGE}); + } else if (hasMessage && !shouldHaveMessage) { + context.report({node, messageId: MESSAGE_ID_FOUND_MESSAGE}); + } + } + + return; + } + const nArguments = expectedNbArguments[firstNonSkipMember]; if (!nArguments) { diff --git a/test/assertion-arguments.js b/test/assertion-arguments.js index 8cc8e22..7081db6 100644 --- a/test/assertion-arguments.js +++ b/test/assertion-arguments.js @@ -181,6 +181,10 @@ ruleTester.run('assertion-arguments', rule, { testCase(false, 't.true(true, \'message\');'), testCase(false, 't.truthy(\'unicorn\', \'message\');'), testCase(false, 't.snapshot(value, \'message\');'), + testCase(false, 't.snapshot(value, { formatAsCodeBlock: true });'), + testCase(false, 't.snapshot(value, { formatAsCodeBlock: true }, \'message\');'), + testCase(false, 't.snapshot(value, opts);'), + testCase(false, 't.snapshot(value, opts, \'message\');'), testCase(false, 't.context.plan();'), testCase(false, 't.teardown(() => {});'), testCase(false, 't.timeout(100, \'message\');'), @@ -242,6 +246,8 @@ ruleTester.run('assertion-arguments', rule, { testCase('always', 't.skip.is(\'same\', \'same\', \'message\');'), testCase('always', 't.is.skip(\'same\', \'same\', \'message\');'), testCase('always', 't.snapshot(value, \'message\');'), + testCase('always', 't.snapshot(value, { formatAsCodeBlock: true }, \'message\');'), + testCase('always', 't.snapshot(value, opts, \'message\');'), testCase('always', 't.teardown(() => {});'), testCase('always', 't.timeout(100, \'message\');'), testCase('always', 't.try(tt => tt.pass(\'ok\'));'), @@ -280,6 +286,8 @@ ruleTester.run('assertion-arguments', rule, { testCase('never', 't.skip.is(\'same\', \'same\');'), testCase('never', 't.is.skip(\'same\', \'same\');'), testCase('never', 't.snapshot(value);'), + testCase('never', 't.snapshot(value, { formatAsCodeBlock: true });'), + testCase('never', 't.snapshot(value, opts);'), testCase('never', 't.teardown(() => {});'), testCase('never', 't.timeout(100);'), testCase('never', 't.try(tt => tt.pass());'), @@ -439,6 +447,7 @@ ruleTester.run('assertion-arguments', rule, { testCase('always', 't.skip.is(\'same\', \'same\');', missingError), testCase('always', 't.is.skip(\'same\', \'same\');', missingError), testCase('always', 't.snapshot(value);', missingError), + testCase('always', 't.snapshot(value, { formatAsCodeBlock: true });', missingError), testCase('never', 't.assert(true, \'message\');', foundError), testCase('never', 't.pass(\'message\');', foundError), @@ -462,6 +471,7 @@ ruleTester.run('assertion-arguments', rule, { testCase('never', 't.skip.is(\'same\', \'same\', \'message\');', foundError), testCase('never', 't.is.skip(\'same\', \'same\', \'message\');', foundError), testCase('never', 't.snapshot(value, \'message\');', foundError), + testCase('never', 't.snapshot(value, { formatAsCodeBlock: true }, \'message\');', foundError), testCase(false, 't.end(\'too many\', \'arguments\');', tooManyError()), testCase(false, 't.skip.end(\'too many\', \'arguments\');', tooManyError()), From 2441478a68b4baf567ace62c53f438afcb3c1c72 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Fri, 15 May 2026 21:02:47 +0200 Subject: [PATCH 2/2] Update (unrelated) docs --- docs/rules/no-duplicate-modifiers.md | 2 +- docs/rules/no-unknown-modifiers.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/rules/no-duplicate-modifiers.md b/docs/rules/no-duplicate-modifiers.md index e02bd8b..9784a90 100644 --- a/docs/rules/no-duplicate-modifiers.md +++ b/docs/rules/no-duplicate-modifiers.md @@ -2,7 +2,7 @@ 📝 Disallow duplicate test modifiers. -❌ This rule is [deprecated](https://github.com/avajs/eslint-plugin-ava/blob/v16.0.0/docs/rules/no-duplicate-modifiers.md). Replaced by `ava/no-invalid-modifier-chain` which covers more cases. +❌ This rule is [deprecated](https://github.com/avajs/eslint-plugin-ava/blob/v16.0.1/docs/rules/no-duplicate-modifiers.md). Replaced by `ava/no-invalid-modifier-chain` which covers more cases. 🚫 This rule is _disabled_ in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). diff --git a/docs/rules/no-unknown-modifiers.md b/docs/rules/no-unknown-modifiers.md index b73af80..73abeb0 100644 --- a/docs/rules/no-unknown-modifiers.md +++ b/docs/rules/no-unknown-modifiers.md @@ -2,7 +2,7 @@ 📝 Disallow unknown test modifiers. -❌ This rule is [deprecated](https://github.com/avajs/eslint-plugin-ava/blob/v16.0.0/docs/rules/no-unknown-modifiers.md). Replaced by `ava/no-invalid-modifier-chain` which covers more cases. +❌ This rule is [deprecated](https://github.com/avajs/eslint-plugin-ava/blob/v16.0.1/docs/rules/no-unknown-modifiers.md). Replaced by `ava/no-invalid-modifier-chain` which covers more cases. 🚫 This rule is _disabled_ in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).