async-server-action
Added in v0.9.4Configuration
Rule Details
Require functions whose first statement is "use server" to be async.
React Server Actions must be async even when they do not await anything or return a promise. This rule checks function declarations, function expressions, arrow functions, and methods.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Only the first statement is checked. A preceding statement, including another
directive such as "use strict", prevents a match. Generators and template
literals are ignored. A file-level "use server" directive does not cause this
rule to check all exported functions.
The rule offers an editor suggestion to insert async; it does not apply an
automatic fix.
Options
This rule has no options.
Differences from upstream
- For computed methods, rslint suggests
async [action]() { 'use server'; }. Upstream insertsasyncinside the brackets, which can produce invalid syntax or change the method name. - Constructors, getters, and setters are reported without suggestions because they cannot be async. Upstream offers edits that can produce invalid syntax or rename an accessor. Move the Server Action into an ordinary async function or method instead.
When Not To Use It
If you are not using React Server Components.
Original Documentation
This rule follows the upstream commit linked below; it is not included in upstream
release v7.37.5.