Skip to content

useConvexArgsValidator (JavaScript)

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

Require an args validator in Convex queries, mutations, and actions.

Convex checks the arguments of every call against the args validator before the handler runs. Without it, callers can pass any value, because TypeScript types aren’t checked at runtime. A function without arguments should use args: {}.

This rule checks exported query, mutation, action, internalQuery, internalMutation, and internalAction functions, including the older syntax query(async (ctx) => {}), which can’t define args.

export const get = query({
handler: async (ctx, { id }: { id: Id<"tasks"> }) => {
return await ctx.db.get(id);
},
});
code-block.ts:1:20 lint/nursery/useConvexArgsValidator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This Convex function doesn't have an args validator.

> 1 │ export const get = query({
│ ^^^^^
2 │ handler: async (ctx, { id }: { id: Id<"tasks"> }) => {
3 │ return await ctx.db.get(id);

ℹ Without an args validator, Convex doesn't check the arguments of a call before the handler runs, so the handler can receive values of any type.

ℹ Add an args property that describes each argument, for example args: { id: v.id("tasks") }.

ℹ 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.

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

✖ This Convex function doesn't have an args validator.

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

ℹ Without an args validator, Convex doesn't check the arguments of a call before the handler runs, so the handler can receive values of any type.

ℹ Add args: {} so that Convex rejects calls that pass arguments.

ℹ 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: Add an empty args validator.

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

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

✖ This Convex function doesn't have an args validator.

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

ℹ Without an args validator, Convex doesn't check the arguments of a call before the handler runs, so the handler can receive values of any type.

ℹ Replace the handler with an object that has the properties args: {} and handler, so that Convex rejects calls that pass arguments.

ℹ 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: Add an empty args validator.

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

export const get = query({
args: { id: v.id("tasks") },
handler: async (ctx, { id }) => {
return await ctx.db.get(id);
},
});
export const list = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("tasks").collect();
},
});

Type: boolean

Default: false

When set to true, the rule allows a function without args if its handler doesn’t take an arguments parameter. Functions whose handler takes arguments are still reported.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useConvexArgsValidator": {
"level": "on",
"options": {
"ignoreUnusedArguments": true
}
}
}
}
}
}
export const get = query({
handler: async (ctx, { id }) => {
return await ctx.db.get(id);
},
});
code-block.js:1:20 lint/nursery/useConvexArgsValidator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This Convex function doesn't have an args validator.

> 1 │ export const get = query({
│ ^^^^^
2 │ handler: async (ctx, { id }) => {
3 │ return await ctx.db.get(id);

ℹ Without an args validator, Convex doesn't check the arguments of a call before the handler runs, so the handler can receive values of any type.

ℹ Add an args property that describes each argument, for example args: { id: v.id("tasks") }.

ℹ 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.

export const list = query({
handler: async (ctx) => {
return await ctx.db.query("tasks").collect();
},
});