useConvexArgsValidator (JavaScript)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useConvexArgsValidator - 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": { "useConvexArgsValidator": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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(); },});Options
Section titled “Options”ignoreUnusedArguments
Section titled “ignoreUnusedArguments”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.
{ "linter": { "rules": { "nursery": { "useConvexArgsValidator": { "level": "on", "options": { "ignoreUnusedArguments": true } } } } }}Invalid
Section titled “Invalid”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(); },});Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.