Skip to content

Commit f3cb35c

Browse files
committed
Ignore generators
1 parent 7f9a2bd commit f3cb35c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/rules/async-server-action.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const messages = {
1717
suggestAsync: 'Make {{functionName}} async',
1818
};
1919

20+
/** @type {import('eslint').Rule.RuleModule} */
2021
module.exports = {
2122
meta: {
2223
docs: {
@@ -36,7 +37,7 @@ module.exports = {
3637

3738
create(context) {
3839
return {
39-
':function[async=false]>BlockStatement>:first-child[expression.value="use server"]'(node) {
40+
':function[async=false][generator=false]>BlockStatement>:first-child[expression.value="use server"]'(node) {
4041
const currentFunction = node.parent.parent;
4142
const functionName = currentFunction.id ? `\`${currentFunction.id.name}\`` : 'this function';
4243
report(context, messages.asyncServerAction, 'asyncServerAction', {

tests/lib/rules/async-server-action.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,34 @@ ruleTester.run('async-server-action', rule, {
255255
}
256256
`,
257257
},
258+
{
259+
code: `
260+
const addToCart = async function* (data) {
261+
'use server';
262+
}
263+
`,
264+
},
265+
{
266+
code: `
267+
const addToCart = async function* (data) {
268+
"use server";
269+
}
270+
`,
271+
},
272+
{
273+
code: `
274+
const addToCart = function* (data) {
275+
'use server';
276+
}
277+
`,
278+
},
279+
{
280+
code: `
281+
const addToCart = function* (data) {
282+
"use server";
283+
}
284+
`,
285+
},
258286
]),
259287

260288
invalid: parsers.all([

0 commit comments

Comments
 (0)