noConvexOldRegisteredFunctionSyntax (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noConvexOldRegisteredFunctionSyntax - This rule has an unsafe fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noConvexOldRegisteredFunctionSyntax": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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 }); },});Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.