Skip to content

Commit c0dc53b

Browse files
authored
Add @convex-dev/eslint-plugin to the convex-helpers repo (#829)
2 parents a84667c + aa52d95 commit c0dc53b

File tree

6 files changed

+280
-63
lines changed

6 files changed

+280
-63
lines changed

convex/counter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ export const getCountersPaginated = query({
3030
},
3131
});
3232

33-
export const getCounterOrThrow = query(
34-
async (ctx, { counterName }: { counterName: string }): Promise<number> => {
33+
export const getCounterOrThrow = query({
34+
args: {
35+
counterName: v.string(),
36+
},
37+
handler: async (ctx, { counterName }): Promise<number> => {
3538
const counterDoc = await ctx.db
3639
.query("counter_table")
3740
.filter((q) => q.eq(q.field("name"), counterName))
@@ -41,7 +44,7 @@ export const getCounterOrThrow = query(
4144
}
4245
return counterDoc.counter;
4346
},
44-
);
47+
});
4548

4649
export const upload = action({
4750
args: { data: v.any() },

convex/migrationsExample.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ const standardMigrations = [
5555
internal.migrationsExample.cleanUpBrokenRefs,
5656
];
5757

58-
export const status = internalQuery(
59-
async (ctx): Promise<MigrationStatus<"migrations">[]> => {
58+
export const status = internalQuery({
59+
args: {},
60+
handler: async (ctx): Promise<MigrationStatus<"migrations">[]> => {
6061
return await getStatus(ctx, { migrationTable: "migrations" });
6162
},
62-
);
63+
});
6364

6465
export const cancel = internalMutation({
6566
args: { fn: v.string() },

convex/presence.ts

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* - Use Convex `auth` to authenticate users rather than passing up a "user"
88
* - Check that the user is allowed to be in a given room.
99
*/
10+
import { v } from "convex/values";
1011
import { query, mutation } from "./_generated/server";
1112

1213
const LIST_LIMIT = 20;
@@ -21,11 +22,13 @@ const LIST_LIMIT = 20;
2122
* page, chat channel, game instance.
2223
* @param user - The user associated with the presence data.
2324
*/
24-
export const update = mutation(
25-
async (
26-
{ db },
27-
{ room, user, data }: { room: string; user: string; data: any },
28-
) => {
25+
export const update = mutation({
26+
args: {
27+
room: v.string(),
28+
user: v.string(),
29+
data: v.any(),
30+
},
31+
handler: async ({ db }, { room, user, data }) => {
2932
const existing = await db
3033
.query("presence")
3134
.withIndex("user_room", (q) => q.eq("user", user).eq("room", room))
@@ -41,7 +44,7 @@ export const update = mutation(
4144
});
4245
}
4346
},
44-
);
47+
});
4548

4649
/**
4750
* Updates the "updated" timestamp for a given user's presence in a room.
@@ -50,8 +53,12 @@ export const update = mutation(
5053
* page, chat channel, game instance.
5154
* @param user - The user associated with the presence data.
5255
*/
53-
export const heartbeat = mutation(
54-
async ({ db }, { room, user }: { room: string; user: string }) => {
56+
export const heartbeat = mutation({
57+
args: {
58+
room: v.string(),
59+
user: v.string(),
60+
},
61+
handler: async ({ db }, { room, user }) => {
5562
const existing = await db
5663
.query("presence")
5764
.withIndex("user_room", (q) => q.eq("user", user).eq("room", room))
@@ -60,7 +67,7 @@ export const heartbeat = mutation(
6067
await db.patch(existing._id, { updated: Date.now() });
6168
}
6269
},
63-
);
70+
});
6471

6572
/**
6673
* Lists the presence data for N users in a room, ordered by recent update.
@@ -70,16 +77,21 @@ export const heartbeat = mutation(
7077
* @returns A list of presence objects, ordered by recent update, limited to
7178
* the most recent N.
7279
*/
73-
export const list = query(async ({ db }, { room }: { room: string }) => {
74-
const presence = await db
75-
.query("presence")
76-
.withIndex("room_updated", (q) => q.eq("room", room))
77-
.order("desc")
78-
.take(LIST_LIMIT);
79-
return presence.map(({ _creationTime, updated, user, data }) => ({
80-
created: _creationTime,
81-
updated,
82-
user,
83-
data,
84-
}));
80+
export const list = query({
81+
args: {
82+
room: v.string(),
83+
},
84+
handler: async ({ db }, { room }) => {
85+
const presence = await db
86+
.query("presence")
87+
.withIndex("room_updated", (q) => q.eq("room", room))
88+
.order("desc")
89+
.take(LIST_LIMIT);
90+
return presence.map(({ _creationTime, updated, user, data }) => ({
91+
created: _creationTime,
92+
updated,
93+
user,
94+
data,
95+
}));
96+
},
8597
});

eslint.config.mjs

Lines changed: 9 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 reactPlugin from "eslint-plugin-react";
55
import reactHooks from "eslint-plugin-react-hooks";
6+
import convexPlugin from "@convex-dev/eslint-plugin";
67

78
export default [
89
{ files: ["src/**/*.{js,mjs,cjs,ts,tsx}", "convex/**/*.{ts,tsx}"] },
@@ -21,6 +22,14 @@ export default [
2122
"vitest.workspace.ts",
2223
],
2324
},
25+
{
26+
files: ["convex/**/*.ts", "packages/convex-helpers/server/**/*.ts"],
27+
ignores: ["packages/convex-helpers/server/_generated/**/*"],
28+
plugins: {
29+
"@convex-dev": convexPlugin,
30+
},
31+
rules: convexPlugin.configs.recommended[0].rules,
32+
},
2433
{
2534
languageOptions: {
2635
globals: globals.worker,

0 commit comments

Comments
 (0)