Skip to content

Commit 96c2bd5

Browse files
Merge pull request #51 from get-convex/ian/convex-linter
use convex linter
2 parents 480bb8b + 88d2594 commit 96c2bd5

7 files changed

Lines changed: 42 additions & 35 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ jobs:
3434
npm i
3535
npm run build
3636
- name: Publish package for testing branch
37-
run:
38-
npx pkg-pr-new publish || echo "Have you set up pkg-pr-new for this
39-
repo?"
37+
run: npx pkg-pr-new publish || echo "pkg-pr-new failed"
4038
- name: Test
4139
run: |
4240
npm run test

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
{
@@ -38,7 +39,12 @@ export default [
3839
languageOptions: {
3940
globals: globals.worker,
4041
},
42+
plugins: {
43+
"@convex-dev": convexPlugin,
44+
},
4145
rules: {
46+
...convexPlugin.configs.recommended[0].rules,
47+
4248
"@typescript-eslint/no-floating-promises": "error",
4349
"@typescript-eslint/no-explicit-any": "off",
4450
"no-unused-vars": "off",

example/convex/stripe.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ export const getCustomerPortalUrl = action({
452452
}),
453453
v.null(),
454454
),
455-
handler: async (ctx, args) => {
455+
handler: async (ctx) => {
456456
const identity = await ctx.auth.getUserIdentity();
457457
if (!identity) throw new Error("Not authenticated");
458458

@@ -577,7 +577,7 @@ export const getUserSubscriptions = query({
577577
orgId: v.optional(v.string()),
578578
}),
579579
),
580-
handler: async (ctx, args) => {
580+
handler: async (ctx) => {
581581
const identity = await ctx.auth.getUserIdentity();
582582
if (!identity) return [];
583583

@@ -606,7 +606,7 @@ export const getUserPayments = query({
606606
orgId: v.optional(v.string()),
607607
}),
608608
),
609-
handler: async (ctx, args) => {
609+
handler: async (ctx) => {
610610
const identity = await ctx.auth.getUserIdentity();
611611
if (!identity) return [];
612612

@@ -629,7 +629,7 @@ export const getFailedPaymentSubscriptions = query({
629629
currentPeriodEnd: v.number(),
630630
}),
631631
),
632-
handler: async (ctx, args) => {
632+
handler: async (ctx) => {
633633
const identity = await ctx.auth.getUserIdentity();
634634
if (!identity) return [];
635635

example/src/App.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,8 @@ function ProfilePage({
891891
// TEAM BILLING PAGE (#4 - Organization-Based Lookups)
892892
// ============================================================================
893893

894-
function TeamBillingPage({
895-
setCurrentPage,
896-
}: {
897-
setCurrentPage: (page: Page) => void;
898-
}) {
899-
const { isSignedIn, user } = useUser();
894+
function TeamBillingPage() {
895+
const { isSignedIn } = useUser();
900896
const [orgId, setOrgId] = useState("demo-org-123");
901897

902898
// Using the org-based queries
@@ -1308,9 +1304,7 @@ function App() {
13081304
{currentPage === "profile" && (
13091305
<ProfilePage setCurrentPage={setCurrentPage} />
13101306
)}
1311-
{currentPage === "team" && (
1312-
<TeamBillingPage setCurrentPage={setCurrentPage} />
1313-
)}
1307+
{currentPage === "team" && <TeamBillingPage />}
13141308
</>
13151309
);
13161310
}

src/component/private.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const updateSubscriptionQuantityInternal = mutation({
5050
.unique();
5151

5252
if (subscription) {
53-
await ctx.db.patch(subscription._id, {
53+
await ctx.db.patch("subscriptions", subscription._id, {
5454
quantity: args.quantity,
5555
});
5656
}
@@ -108,7 +108,7 @@ export const handleCustomerUpdated = mutation({
108108
.unique();
109109

110110
if (customer) {
111-
await ctx.db.patch(customer._id, {
111+
await ctx.db.patch("customers", customer._id, {
112112
email: args.email,
113113
name: args.name,
114114
metadata: args.metadata,
@@ -187,7 +187,7 @@ export const handleSubscriptionCreated = mutation({
187187

188188
for (const invoice of invoices) {
189189
if (!invoice.orgId || !invoice.userId) {
190-
await ctx.db.patch(invoice._id, {
190+
await ctx.db.patch("invoices", invoice._id, {
191191
...(orgId && !invoice.orgId && { orgId }),
192192
...(userId && !invoice.userId && { userId }),
193193
});
@@ -228,7 +228,7 @@ export const handleSubscriptionUpdated = mutation({
228228
const cancelAtPeriodEnd = args.cancelAtPeriodEnd ||
229229
deriveCancelAtPeriodEnd(args.cancelAt, args.currentPeriodEnd);
230230

231-
await ctx.db.patch(subscription._id, {
231+
await ctx.db.patch("subscriptions", subscription._id, {
232232
status: args.status,
233233
currentPeriodEnd: args.currentPeriodEnd,
234234
cancelAtPeriodEnd: cancelAtPeriodEnd,
@@ -263,7 +263,7 @@ export const handleSubscriptionDeleted = mutation({
263263
.unique();
264264

265265
if (subscription) {
266-
await ctx.db.patch(subscription._id, {
266+
await ctx.db.patch("subscriptions", subscription._id, {
267267
status: "canceled",
268268
...(args.cancelAtPeriodEnd !== undefined && {
269269
cancelAtPeriodEnd: args.cancelAtPeriodEnd,
@@ -296,7 +296,7 @@ export const handleCheckoutSessionCompleted = mutation({
296296
.unique();
297297

298298
if (existing) {
299-
await ctx.db.patch(existing._id, {
299+
await ctx.db.patch("checkout_sessions", existing._id, {
300300
status: "complete",
301301
stripeCustomerId: args.stripeCustomerId,
302302
});
@@ -384,7 +384,7 @@ export const handleInvoicePaid = mutation({
384384
.unique();
385385

386386
if (invoice) {
387-
await ctx.db.patch(invoice._id, {
387+
await ctx.db.patch("invoices", invoice._id, {
388388
status: "paid",
389389
amountPaid: args.amountPaid,
390390
});
@@ -408,7 +408,7 @@ export const handleInvoicePaymentFailed = mutation({
408408
.unique();
409409

410410
if (invoice) {
411-
await ctx.db.patch(invoice._id, {
411+
await ctx.db.patch("invoices", invoice._id, {
412412
status: "open",
413413
});
414414
}
@@ -455,7 +455,7 @@ export const handlePaymentIntentSucceeded = mutation({
455455
});
456456
} else if (args.stripeCustomerId && !existing.stripeCustomerId) {
457457
// Update customer ID if it wasn't set initially (webhook timing issue)
458-
await ctx.db.patch(existing._id, {
458+
await ctx.db.patch("payments", existing._id, {
459459
stripeCustomerId: args.stripeCustomerId,
460460
});
461461
}
@@ -479,7 +479,7 @@ export const updatePaymentCustomer = mutation({
479479
.unique();
480480

481481
if (payment && !payment.stripeCustomerId) {
482-
await ctx.db.patch(payment._id, {
482+
await ctx.db.patch("payments", payment._id, {
483483
stripeCustomerId: args.stripeCustomerId,
484484
});
485485
}

src/component/public.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { convexTest } from "convex-test";
22
import { expect, test } from "vitest";
3-
import { api, internal } from "./_generated/api.js";
3+
import { api } from "./_generated/api.js";
44
import schema from "./schema.js";
55
import { modules } from "./setup.test.js";
66

@@ -123,8 +123,12 @@ test("list subscriptions for customer", async () => {
123123
});
124124

125125
expect(subscriptions).toHaveLength(2);
126-
expect(subscriptions.map((s: any) => s.stripeSubscriptionId)).toContain("sub_1");
127-
expect(subscriptions.map((s: any) => s.stripeSubscriptionId)).toContain("sub_2");
126+
expect(subscriptions.map((s: any) => s.stripeSubscriptionId)).toContain(
127+
"sub_1",
128+
);
129+
expect(subscriptions.map((s: any) => s.stripeSubscriptionId)).toContain(
130+
"sub_2",
131+
);
128132
});
129133

130134
test("update subscription metadata for custom lookups", async () => {
@@ -403,8 +407,12 @@ test("list payments by customer ID", async () => {
403407
});
404408

405409
expect(payments).toHaveLength(2);
406-
expect(payments?.map((p: any) => p.stripePaymentIntentId)).toContain("pi_cust1");
407-
expect(payments?.map((p: any) => p.stripePaymentIntentId)).toContain("pi_cust2");
410+
expect(payments?.map((p: any) => p.stripePaymentIntentId)).toContain(
411+
"pi_cust1",
412+
);
413+
expect(payments?.map((p: any) => p.stripePaymentIntentId)).toContain(
414+
"pi_cust2",
415+
);
408416
});
409417

410418
test("list payments by user ID", async () => {
@@ -447,7 +455,9 @@ test("list payments by user ID", async () => {
447455
});
448456

449457
expect(alicePayments).toHaveLength(2);
450-
expect(alicePayments?.every((p: any) => p.userId === "user_alice")).toBe(true);
458+
expect(alicePayments?.every((p: any) => p.userId === "user_alice")).toBe(
459+
true,
460+
);
451461
});
452462

453463
test("list payments by org ID", async () => {
@@ -587,4 +597,3 @@ test("handlePaymentIntentSucceeded updates existing payment with customer", asyn
587597

588598
expect(payment?.stripeCustomerId).toBe("cus_idempotent");
589599
});
590-

src/component/public.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export const createOrUpdateCustomer = mutation({
334334
const userId = metadata.userId as string | undefined;
335335

336336
if (existing) {
337-
await ctx.db.patch(existing._id, {
337+
await ctx.db.patch("customers", existing._id, {
338338
...(args.email !== undefined && { email: args.email }),
339339
...(args.name !== undefined && { name: args.name }),
340340
...(args.metadata !== undefined && { metadata: args.metadata }),
@@ -380,7 +380,7 @@ export const updateSubscriptionMetadata = mutation({
380380
);
381381
}
382382

383-
await ctx.db.patch(subscription._id, {
383+
await ctx.db.patch("subscriptions", subscription._id, {
384384
metadata: args.metadata,
385385
...(args.orgId !== undefined && { orgId: args.orgId }),
386386
...(args.userId !== undefined && { userId: args.userId }),

0 commit comments

Comments
 (0)