nursery/noConvexTimeOrRandomInQueries
nursery · since 2.6.10
No autofixRecommended
biome.json
{
"linter": {
"rules": {
"nursery": {
"noConvexTimeOrRandomInQueries": "error"
}
}
}
}Disallow reading the current time or generating random values in Convex queries.
export const listRecentPosts = query({
args: {},
handler: async (ctx) => {
const since = Date.now() - 24 * 60 * 60 * 1000;
return await ctx.db
.query("posts")
.withIndex("by_creation_time", (q) => q.gt("_creationTime", since))
.collect();
},
});export const pickWinner = query({
args: {},
handler: async (ctx) => {
const entries = await ctx.db.query("entries").collect();
return entries[Math.floor(Math.random() * entries.length)];
},
});function isExpired(session) {
return session.expiresAt < Date.now();
}
export const getSession = query({
args: {},
handler: async (ctx, args) => {
const session = await ctx.db.get(args.sessionId);
return isExpired(session) ? null : session;
},
});export const listRecentPosts = query({
args: { since: v.number() },
handler: async (ctx, args) => {
return await ctx.db
.query("posts")
.withIndex("by_creation_time", (q) => q.gt("_creationTime", args.since))
.collect();
},
});
export const formatDate = query({
args: { timestamp: v.number() },
handler: async (ctx, args) => new Date(args.timestamp).toISOString(),
});
export const createPost = mutation({
args: { body: v.string() },
handler: async (ctx, args) => {
await ctx.db.insert("posts", { body: args.body, publishedAt: Date.now() });
},
});Examples from the Biome documentation.
ESLint does not have this rule.
Oxlint does not have this rule.
nursery/noConvexTimeOrRandomInQueries
nursery · since 2.6.10
{
"linter": {
"rules": {
"nursery": {
"noConvexTimeOrRandomInQueries": "error"
}
}
}
}Disallow calling .filter() on a Convex database query.
Disallow scheduling Convex cron jobs at the start of the hour.
Require the object syntax when registering Convex queries, mutations, and actions.
Disallow lower-specificity selectors after higher-specificity selectors.