From f3cb35c103c520abd38484e5bd076b86f880b832 Mon Sep 17 00:00:00 2001 From: Jorge Zreik Date: Wed, 10 Apr 2024 17:57:50 -0400 Subject: [PATCH] Ignore generators --- lib/rules/async-server-action.js | 3 ++- tests/lib/rules/async-server-action.js | 28 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/rules/async-server-action.js b/lib/rules/async-server-action.js index c6e0d6749a..c1ace58f47 100644 --- a/lib/rules/async-server-action.js +++ b/lib/rules/async-server-action.js @@ -17,6 +17,7 @@ const messages = { suggestAsync: 'Make {{functionName}} async', }; +/** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { docs: { @@ -36,7 +37,7 @@ module.exports = { create(context) { return { - ':function[async=false]>BlockStatement>:first-child[expression.value="use server"]'(node) { + ':function[async=false][generator=false]>BlockStatement>:first-child[expression.value="use server"]'(node) { const currentFunction = node.parent.parent; const functionName = currentFunction.id ? `\`${currentFunction.id.name}\`` : 'this function'; report(context, messages.asyncServerAction, 'asyncServerAction', { diff --git a/tests/lib/rules/async-server-action.js b/tests/lib/rules/async-server-action.js index 1378a38165..381defbc1e 100644 --- a/tests/lib/rules/async-server-action.js +++ b/tests/lib/rules/async-server-action.js @@ -255,6 +255,34 @@ ruleTester.run('async-server-action', rule, { } `, }, + { + code: ` + const addToCart = async function* (data) { + 'use server'; + } + `, + }, + { + code: ` + const addToCart = async function* (data) { + "use server"; + } + `, + }, + { + code: ` + const addToCart = function* (data) { + 'use server'; + } + `, + }, + { + code: ` + const addToCart = function* (data) { + "use server"; + } + `, + }, ]), invalid: parsers.all([