Skip to content

Commit 8f23447

Browse files
authored
use convex linter (#51)
## Summary - Install and configure `@convex-dev/eslint-plugin` - Auto-fix `explicit-table-ids` violations (adds table name as first arg to `db.get`/`db.patch`/`db.delete`/`db.replace`) - Add eslint-disable annotations where table names are genuinely dynamic 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents 0c42603 + f42f5db commit 8f23447

8 files changed

Lines changed: 229 additions & 14 deletions

File tree

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import pluginJs from "@eslint/js";
33
import tseslint from "typescript-eslint";
44
import reactHooks from "eslint-plugin-react-hooks";
55
import reactRefresh from "eslint-plugin-react-refresh";
6+
import convexPlugin from "@convex-dev/eslint-plugin";
67

78
export default [
89
{
@@ -37,7 +38,12 @@ export default [
3738
languageOptions: {
3839
globals: globals.worker,
3940
},
41+
plugins: {
42+
"@convex-dev": convexPlugin,
43+
},
4044
rules: {
45+
...convexPlugin.configs.recommended[0].rules,
46+
4147
"@typescript-eslint/no-floating-promises": "error",
4248
"@typescript-eslint/no-explicit-any": "off",
4349
"no-unused-vars": "off",

example/convex/example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const nearestPoints = query({
3333
});
3434
return await Promise.all(
3535
results.map(async (result) => {
36-
const row = await ctx.db.get(result.key as Id<"locations">);
36+
const row = await ctx.db.get("locations", result.key as Id<"locations">);
3737
if (!row) {
3838
throw new Error("Invalid locationId");
3939
}
@@ -91,7 +91,7 @@ export const search = query({
9191
);
9292
const rows = await Promise.all(
9393
results.map(async (result) => {
94-
const row = await ctx.db.get(result.key);
94+
const row = await ctx.db.get("locations", result.key);
9595
if (!row) {
9696
throw new Error("Invalid locationId");
9797
}

package-lock.json

Lines changed: 211 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"convex": "^1.24.8"
7272
},
7373
"devDependencies": {
74+
"@convex-dev/eslint-plugin": "^2.0.0",
7475
"@edge-runtime/vm": "5.0.0",
7576
"@eslint/js": "9.39.2",
7677
"@fast-check/vitest": "0.2.4",

src/component/document.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async function removePointByKey(
135135
`Invariant failed: Missing cell ${cell} for point ${existing._id}`,
136136
);
137137
}
138-
await ctx.db.delete(existingCell._id);
138+
await ctx.db.delete("pointsByCell", existingCell._id);
139139
await approximateCounter.decrement(ctx, existing._id, cellCounterKey(cell));
140140
}
141141
for (const [filterKey, filterDoc] of Object.entries(existing.filterKeys)) {
@@ -155,14 +155,14 @@ async function removePointByKey(
155155
`Invariant failed: Missing filterKey ${filterKey}:${filterValue} for point ${existing._id}`,
156156
);
157157
}
158-
await ctx.db.delete(existingFilterKey._id);
158+
await ctx.db.delete("pointsByFilterKey", existingFilterKey._id);
159159
await approximateCounter.decrement(
160160
ctx,
161161
existing._id,
162162
filterCounterKey(filterKey, filterValue),
163163
);
164164
}
165165
}
166-
await ctx.db.delete(existing._id);
166+
await ctx.db.delete("points", existing._id);
167167
return true;
168168
}

src/component/lib/approximateCounter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function increment(
2424
.withIndex("key", (q) => q.eq("key", key))
2525
.first();
2626
if (existing) {
27-
await ctx.db.patch(existing._id, { count: existing.count + 1 });
27+
await ctx.db.patch("approximateCounters", existing._id, { count: existing.count + 1 });
2828
} else {
2929
await ctx.db.insert("approximateCounters", { key, count: 1 });
3030
}
@@ -46,9 +46,9 @@ export async function decrement(
4646
throw new Error(`Invariant failed: Missing counter for key ${key}`);
4747
}
4848
if (existing.count === 1) {
49-
await ctx.db.delete(existing._id);
49+
await ctx.db.delete("approximateCounters", existing._id);
5050
} else {
51-
await ctx.db.patch(existing._id, { count: existing.count - 1 });
51+
await ctx.db.patch("approximateCounters", existing._id, { count: existing.count - 1 });
5252
}
5353
}
5454

src/component/lib/pointQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class ClosestPointQuery {
123123
}
124124
continue;
125125
}
126-
const point = await ctx.db.get(pointId);
126+
const point = await ctx.db.get("points", pointId);
127127
if (!point) {
128128
throw new Error("Point not found");
129129
}
@@ -140,7 +140,7 @@ export class ClosestPointQuery {
140140
const entries = this.results
141141
.toArray()
142142
.sort((a, b) => a.distance - b.distance);
143-
const points = await Promise.all(entries.map((r) => ctx.db.get(r.pointID)));
143+
const points = await Promise.all(entries.map((r) => ctx.db.get("points", r.pointID)));
144144
const results = [];
145145
for (let i = 0; i < entries.length; i++) {
146146
const point = points[i];

src/component/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export const execute = query({
195195
}
196196
const { pointId } = decodeTupleKey(tupleKey);
197197
try {
198-
await channel.push({ tupleKey, docPromise: ctx.db.get(pointId) });
198+
await channel.push({ tupleKey, docPromise: ctx.db.get("points", pointId) });
199199
} catch (e) {
200200
if (e instanceof ChannelClosedError) {
201201
break;

0 commit comments

Comments
 (0)