#13387 00e98fc Thanks @dyc3! - Added the nursery rule noAmd, which reports AMD define() and require() calls that load modules from a list, so they can be replaced with import statements.
define(["a", "b"], function (a, b) {});
#13357 9407920 Thanks @dyc3! - Added the nursery rule noArrayReduce, which disallows the reduce() and reduceRight() array methods in favor of loops and methods such as map() and filter(). Calls whose function only returns a single arithmetic, comparison, or bitwise operation, such as (total, item) => total + item, are allowed.
const counts = words.reduce((counts, word) => {
counts[word] = (counts[word] ?? 0) + 1;
return counts;
}, {});
#13358 d82324e Thanks @dyc3! - Added the nursery rule noBreakInNestedLoop, which reports break statements without a label inside nested loops and inside switch statements in loops. Enable the checkContinue option to also report continue statements without a label.
for (const item of items) {
for (const child of item.children) {
break; // reported
}
}
#13488 674687a Thanks @dyc3! - Added the nursery rule noCollectionBracketAccess. It reports square brackets used on a Map, Set, WeakMap, or WeakSet, which read or change a property of the object instead of one of its entries.
const map = new Map();
map["foo"] = "bar";
#13477 de81ca9 Thanks @dyc3! - Added the nursery rule noConvexCollectInQuery, which reports Convex database queries that load every matching document with .collect(). Use .take() or .paginate() instead.
const messages = await ctx.db.query("messages").collect();
#13323 fae973f Thanks @dyc3! - Added the nursery rule noConvexDuplicateIndexes, which reports Convex database indexes whose fields are the first fields of another index on the same table. The rule is part of the convex domain.
defineTable({ author: v.string(), channel: v.string() })
.index("by_author", ["author"]) // reported
.index("by_author_and_channel", ["author", "channel"]);
#13481 4de1a09 Thanks @dyc3! - Added the nursery rule noConvexOldRegisteredFunctionSyntax, which reports Convex queries, mutations, and actions registered with a plain function instead of an object. The object syntax lets you declare an args validator.
export const list = query(async (ctx) => {
return await ctx.db.query("messages").collect();
});
#13325 e7dab31 Thanks @dyc3! - Added the new nursery rule noConvexProcessEnv to the convex domain. It reports uses of process.env in the convex folder of a package, and recommends reading environment variables from the typed env object exported by _generated/server instead. Its unsafe fix replaces process.env with env and adds the import.
// convex/giphy.ts
const apiKey = process.env.GIPHY_KEY;
#13324 6609054 Thanks @dyc3! - Added the nursery rule noConvexQueryFilter, which reports .filter() calls on Convex database queries. The database reads every document in the query before .filter() drops the ones that don't match, so .withIndex() or filtering the collected results in code is preferred. The rule belongs to the convex domain.
const messages = await ctx.db
.query("messages")
.filter((q) => q.eq(q.field("author"), args.author))
.collect();
#13476 cfec26a Thanks @dyc3! - Added the nursery rule noConvexTimeOrRandomInQueries, which reports Convex queries that read the current time or generate random values. Convex caches query results, so these values can be outdated or stay the same between calls.
export const pickWinner = query({
handler: async (ctx) => {
const entries = await ctx.db.query("entries").collect();
return entries[Math.floor(Math.random() * entries.length)];
},
});
#13300 1001924 Thanks @dyc3! - Added the nursery rule noConvexTopOfHourCrons, which reports Convex cron jobs scheduled at the start of the hour, the busiest time for most apps.
crons.hourly("cleanup", { minuteUTC: 0 }, internal.tasks.cleanup);
#13482 0466735 Thanks @dyc3! - Added the nursery rule noConvexWrongRuntimeImports, which reports files in a Convex convex folder that run in the Convex runtime but import a file with the "use node" directive.
// convex/payments.ts, where convex/stripe.ts starts with "use node"
import { formatAmount } from "./stripe";
#13371 adae706 Thanks @dyc3! - Added the nursery rule noDuplicateExports. It reports a module or TypeScript namespace that exports the same name more than once, or has more than one default export. It also reports two export * from statements that export the same name from different declarations. The rule belongs to the project domain.
export const foo = 1;
function bar() {}
export { bar as foo };
#13395 3f1f7ce Thanks @dyc3! - Added the nursery rule noDuplicateIfBranches, which reports branches of an if statement that run the same code as the branch right before them.
if (value === "a") {
doThing();
} else if (value === "b") {
doThing();
}
#13504 ae4791f Thanks @dyc3! - Added the nursery rule noMixedReturns, which reports functions where some return statements return a value and others don't, including functions that can reach the end of their body after returning a value elsewhere.
function doSomething(condition) {
if (condition) {
return true;
}
}
#13366 48da9c2 Thanks @dyc3! - Added the nursery rule noMutableExports. It reports exported variables declared with let or var, which other modules see change whenever they are reassigned.
export let count = 1;
#13505 72c3a7e Thanks @dyc3! - Added the nursery rule noNegatedComparison, which reports equality comparisons that are negated as a whole and suggests the opposite operator instead.
const isDifferent = !(a === b); // use a !== b instead
#13282 5201ae5 Thanks @dyc3! - Added the nursery rule noOuterScopeInIsolatedFunctions, which reports uses of variables, this, and super from outside a function that runs apart from the code around it, such as a function passed to makeSynchronous() or marked with an @isolated comment.
const url = "https://example.com";
makeSynchronous(async () => {
const response = await fetch(url); // url doesn't exist where the function runs
return response.text();
});
#13474 100d4d7 Thanks @dyc3! - Added the nursery rule noTailwindLegacyImportant for JavaScript and HTML. It reports Tailwind CSS classes that put the ! important modifier at the start, as Tailwind CSS v3 did, and moves the ! to the end of the class name.; // use `flex!` and `hover:bg-red-500!`
#13224 19fb503 Thanks @dyc3! - Added the new nursery rule noTanstackQueryUnstableDeps, which reports the object returned by a TanStack Query hook, such as useQuery or useMutation, when it is used directly as a dependency of useEffect, useMemo, or useCallback. This object can be a new object on every render, so React treats the dependencies as changed on every render.
const mutation = useMutation({ mutationFn });
const callback = useCallback(() => mutation.mutate("hello"), [mutation]);
#13371 adae706 Thanks @dyc3! - Added the nursery rule noUselessReExportAll. It reports export * from a module that has no named exports, which exports nothing. The rule belongs to the project domain.
// foo.js only has a default export.
export * from "./foo.js";
#12560 1413bf8 Thanks @dyc3! - Added the nursery rule noVueComputedPropertyCall, which disallows calling a Vue computed property whose value is not a function. Calling such a value throws an error when the code runs.
#13322 025c012 Thanks @dyc3! - Added the nursery rule noVueContentOutsideBlock, which reports text and code placed outside of the top-level blocks of a Vue component. Vue drops this content, so it never renders or runs.
For example, console.log(1); below is reported:
Hello
console.log(1);
#13369 7940a3f Thanks @dyc3! - Added the nursery rule useConsistentDefaultExportStyle, which enforces whether default-exported functions and classes are declared inside the export default statement or declared separately and exported by name.
function foo() {}
export default foo; // reported
#13248 b7a3678 Thanks @dyc3! - Added the nursery rule useConsistentExistenceIndexCheck, which reports checks such as index < 0, index >= 0, and index > -1 on the result of indexOf(), lastIndexOf(), findIndex(), or findLastIndex(), and suggests comparing with -1 instead.
const index = list.indexOf(item);
if (index < 0) {}
#13305 4bcb0ee Thanks @dyc3! - Added the nursery rule useConvexAccessControl, which reports exported Convex queries, mutations and actions whose handler doesn't call an access control function, such as requireUser(ctx). The rule belongs to the convex domain.
import { mutation } from "./_generated/server";
export const send = mutation({
args: {},
handler: async (ctx) => {
await ctx.db.insert("messages", { body: "hello" });
},
});
#13475 1cb1e56 Thanks @dyc3! - Added the nursery rule useConvexArgsValidator, which requires Convex queries, mutations, and actions to define an args validator, so that Convex checks the arguments of every call before the handler runs.
export const list = query({
handler: async (ctx) => {
return await ctx.db.query("tasks").collect();
},
});
#13473 88aa8a5 Thanks @dyc3! - Added the nursery rule useConvexExplicitTableIds, which reports Convex db.get(), db.patch(), db.replace(), and db.delete() calls that don't pass the table name as the first argument.
const message = await ctx.db.get(messageId);