Skip to content

Commit ba60af1

Browse files
committed
improve configs & fix bundler errors
1 parent bce2433 commit ba60af1

File tree

8 files changed

+75
-58
lines changed

8 files changed

+75
-58
lines changed

eslint.config.js

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
import globals from "globals";
22
import pluginJs from "@eslint/js";
33
import tseslint from "typescript-eslint";
4+
import reactHooks from "eslint-plugin-react-hooks";
5+
import reactRefresh from "eslint-plugin-react-refresh";
46

57
export default [
6-
{ files: ["src/**/*.{js,mjs,cjs,ts,tsx}"] },
78
{
89
ignores: [
910
"dist/**",
1011
"eslint.config.js",
12+
"vitest.config.ts",
1113
"**/_generated/",
1214
"node10stubs.mjs",
1315
],
1416
},
1517
{
18+
files: ["src/**/*.{js,mjs,cjs,ts,tsx}", "example/**/*.{js,mjs,cjs,ts,tsx}"],
1619
languageOptions: {
17-
globals: globals.worker,
1820
parser: tseslint.parser,
19-
2021
parserOptions: {
21-
project: true,
22-
tsconfigRootDir: ".",
22+
project: [
23+
"./tsconfig.json",
24+
"./example/tsconfig.json",
25+
"./example/convex/tsconfig.json",
26+
],
27+
tsconfigRootDir: import.meta.dirname,
2328
},
2429
},
2530
},
2631
pluginJs.configs.recommended,
2732
...tseslint.configs.recommended,
33+
// Convex code - Worker environment
2834
{
35+
files: ["src/**/*.{ts,tsx}", "example/convex/**/*.{ts,tsx}"],
36+
ignores: ["src/react/**"],
37+
languageOptions: {
38+
globals: globals.worker,
39+
},
2940
rules: {
3041
"@typescript-eslint/no-floating-promises": "error",
31-
"eslint-comments/no-unused-disable": "off",
32-
33-
// allow (_arg: number) => {} and const _foo = 1;
42+
"@typescript-eslint/no-explicit-any": "off",
3443
"no-unused-vars": "off",
3544
"@typescript-eslint/no-unused-vars": [
3645
"warn",
@@ -39,6 +48,52 @@ export default [
3948
varsIgnorePattern: "^_",
4049
},
4150
],
51+
"@typescript-eslint/no-unused-expressions": [
52+
"error",
53+
{
54+
allowShortCircuit: true,
55+
allowTernary: true,
56+
allowTaggedTemplates: true,
57+
},
58+
],
59+
},
60+
},
61+
// React app code - Browser environment
62+
{
63+
files: ["src/react/**/*.{ts,tsx}", "example/src/**/*.{ts,tsx}"],
64+
languageOptions: {
65+
ecmaVersion: 2020,
66+
globals: globals.browser,
67+
},
68+
plugins: {
69+
"react-hooks": reactHooks,
70+
"react-refresh": reactRefresh,
71+
},
72+
rules: {
73+
...reactHooks.configs.recommended.rules,
74+
"react-refresh/only-export-components": [
75+
"warn",
76+
{ allowConstantExport: true },
77+
],
78+
"@typescript-eslint/no-explicit-any": "off",
79+
"no-unused-vars": "off",
80+
"@typescript-eslint/no-unused-vars": [
81+
"warn",
82+
{
83+
argsIgnorePattern: "^_",
84+
varsIgnorePattern: "^_",
85+
},
86+
],
87+
},
88+
},
89+
// Example config files (vite.config.ts, etc.) - Node environment
90+
{
91+
files: ["example/vite.config.ts", "example/**/*.config.{js,ts}"],
92+
languageOptions: {
93+
globals: {
94+
...globals.node,
95+
...globals.browser,
96+
},
4297
},
4398
},
4499
];

example/eslint.config.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/client/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {
1+
import type {
22
Expand,
33
FunctionReference,
44
GenericDataModel,
55
GenericMutationCtx,
66
GenericQueryCtx,
77
} from "convex/server";
8-
import { GenericId } from "convex/values";
9-
import { NotificationFields } from "../component/schema.js";
10-
import { LogLevel } from "../logging/index.js";
8+
import type { GenericId } from "convex/values";
9+
import type { NotificationFields } from "../component/schema.js";
10+
import type { LogLevel } from "../logging/index.js";
1111
import type { ComponentApi } from "../component/_generated/component.js";
1212

1313
/**

src/component/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
customAction,
3-
CustomCtx,
3+
type CustomCtx,
44
customMutation,
55
customQuery,
66
} from "convex-helpers/server/customFunctions";

src/component/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { MutationCtx } from "./functions.js";
1+
import type { MutationCtx } from "./functions.js";
22
import { internal } from "./_generated/api.js";
3-
import { Doc } from "./_generated/dataModel.js";
3+
import type { Doc } from "./_generated/dataModel.js";
44

55
export async function ensureCoordinator(ctx: MutationCtx) {
66
ctx.logger.debug("Ensuring there's a notification coordinator");

src/component/internal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { JSONValue, v } from "convex/values";
1+
import { v, type JSONValue } from "convex/values";
22
import { internalAction, internalMutation } from "./functions.js";
33
import { internal } from "./_generated/api.js";
4-
import { Id } from "./_generated/dataModel.js";
4+
import type { Id } from "./_generated/dataModel.js";
55
import { ensureCoordinator } from "./helpers.js";
66
import { notificationFields } from "./schema.js";
77

src/component/public.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ConvexError, Infer, v } from "convex/values";
2-
import { mutation, MutationCtx, query } from "./functions.js";
1+
import { ConvexError, v, type Infer } from "convex/values";
2+
import { mutation, query, type MutationCtx } from "./functions.js";
33
import { notificationFields, notificationState } from "./schema.js";
44
import { ensureCoordinator, shutdownGracefully } from "./helpers.js";
55
import { api } from "./_generated/api.js";

src/logging/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Infer, v } from "convex/values";
1+
import { v, type Infer } from "convex/values";
22

33
export const logLevelValidator = v.union(
44
v.literal("DEBUG"),

0 commit comments

Comments
 (0)