Rules
function-definition
This rule is experimental and may change in the future or be removed. It is not recommended for use in production code at this time.
Full Name in @eslint-react/eslint-plugin
@eslint-react/rsc/function-definitionFull Name in eslint-plugin-react-rsc
react-rsc/function-definitionFeatures
๐ง ๐งช
Description
Validate and transform React Client/Server Function definitions.
It includes the following checks:
- If a file has a top-level
'use server'directive, exported functions must be async. Functions with their own'use server'directive must also be async.
Examples
Failing
'use server';
export function serverFunction1() {
// ...
}
export const serverFunction2 = function() {
// ...
};
export const serverFunction3 = () => {
// ...
};export function Component() {
function serverFunction1() {
'use server';
// ...
}
const serverFunction2 = function() {
'use server';
// ...
};
const serverFunction3 = () => {
'use server';
// ...
};
return <div>...</div>;
}Passing
'use server';
export async function serverFunction1() {
// ...
}
export const serverFunction2 = async function() {
// ...
};
export const serverFunction3 = async () => {
// ...
};export function Component() {
async function serverFunction1() {
'use server';
// ...
}
const serverFunction2 = async function() {
'use server';
// ...
};
const serverFunction3 = async () => {
'use server';
// ...
};
return <div>...</div>;
}