Skip to content

noConvexOldRegisteredFunctionSyntax (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noConvexOldRegisteredFunctionSyntax": "error"
}
}
}
}

Require the object syntax when registering Convex queries, mutations, and actions.

Passing the handler directly, as in query(async (ctx) => {}), leaves no place for an args validator, so Convex can’t check the arguments that clients send. Pass an object with args and handler properties instead.

export const list = query(async (ctx) => {
return await ctx.db.query("messages").collect();
});
code-block.js:1:21 lint/nursery/noConvexOldRegisteredFunctionSyntax  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

✖ This Convex function is registered with a plain function instead of an object.

> 1 │ export const list = query(async (ctx) => {
│ ^^^^^
2 │ return await ctx.db.query("messages").collect();
3 │ });

ℹ This syntax has no place for an args validator, so Convex can't check the arguments that clients send.

ℹ Pass an object instead, with the function in its handler property and the expected arguments in its args property.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Move the function into the handler property of an object.

1 │ - export·const·list·=·query(async·(ctx)·=>·{
1 │ + export·const·list·=·query({·args:·{},·handler:·async·(ctx)·=>·{
2 2 │ return await ctx.db.query("messages").collect();
3 │ - });
3 │ + }·});
4 4 │

export const send = mutation(async (ctx, { body }) => {
await ctx.db.insert("messages", { body });
});
code-block.js:1:21 lint/nursery/noConvexOldRegisteredFunctionSyntax  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

✖ This Convex function is registered with a plain function instead of an object.

> 1 │ export const send = mutation(async (ctx, { body }) => {
│ ^^^^^^^^
2 │ await ctx.db.insert("messages", { body });
3 │ });

ℹ This syntax has no place for an args validator, so Convex can't check the arguments that clients send.

ℹ Pass an object instead, with the function in its handler property and the expected arguments in its args property.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Move the function into the handler property of an object.

1 │ - export·const·send·=·mutation(async·(ctx,·{·body·})·=>·{
1 │ + export·const·send·=·mutation({·handler:·async·(ctx,·{·body·})·=>·{
2 2 │ await ctx.db.insert("messages", { body });
3 │ - });
3 │ + }·});
4 4 │

export const list = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("messages").collect();
},
});
export const send = mutation({
args: { body: v.string() },
handler: async (ctx, { body }) => {
await ctx.db.insert("messages", { body });
},
});