Skip to content

Commit

Permalink
Ignore generators
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgezreik committed Apr 10, 2024
1 parent 7f9a2bd commit f3cb35c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/async-server-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const messages = {
suggestAsync: 'Make {{functionName}} async',
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
docs: {
Expand All @@ -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', {
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/rules/async-server-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit f3cb35c

Please sign in to comment.