Skip to content

Commit cb4af15

Browse files
committed
improved eslint config, refactoring and documentation
1 parent 39187ae commit cb4af15

385 files changed

Lines changed: 11649 additions & 4005 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: Check formatting
3838
run: npm run format:check
3939

40+
- name: Check dead code
41+
run: npm run knip
42+
4043
- name: Run lint
4144
run: npm run lint
4245

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ supabase/.temp/
4545
# typescript
4646
*.tsbuildinfo
4747
next-env.d.ts
48+
49+
# temp/scratch scripts and outputs
50+
/scratch/
51+
knip.txt
52+
knip.out.json
53+
lint.json
54+
fix_*.mjs
55+
fix_*.js

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Before opening a PR, run:
103103

104104
```bash
105105
npm run format:check
106+
npm run knip
106107
npm run lint
107108
npm run test
108109
npm run build

eslint.config.mjs

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,139 @@
11
import { defineConfig, globalIgnores } from "eslint/config";
22
import nextVitals from "eslint-config-next/core-web-vitals";
33
import nextTs from "eslint-config-next/typescript";
4+
import importPlugin from "eslint-plugin-import";
45

56
const eslintConfig = defineConfig([
67
...nextVitals,
78
...nextTs,
8-
// Override default ignores of eslint-config-next.
9+
{
10+
linterOptions: {
11+
reportUnusedDisableDirectives: "error",
12+
},
13+
},
14+
{
15+
files: ["src/**/*.{ts,tsx,mts}", "supabase/functions/**/*.ts"],
16+
plugins: {
17+
import: importPlugin,
18+
},
19+
rules: {
20+
"@typescript-eslint/consistent-type-imports": [
21+
"error",
22+
{
23+
prefer: "type-imports",
24+
fixStyle: "separate-type-imports",
25+
disallowTypeAnnotations: false,
26+
},
27+
],
28+
"@typescript-eslint/no-unused-vars": [
29+
"error",
30+
{
31+
argsIgnorePattern: "^_",
32+
varsIgnorePattern: "^_",
33+
caughtErrorsIgnorePattern: "^_",
34+
},
35+
],
36+
curly: ["error", "all"],
37+
eqeqeq: ["error", "always"],
38+
"import/first": "error",
39+
"import/no-duplicates": "error",
40+
"no-console": ["error", { allow: ["warn", "error"] }],
41+
"no-else-return": "error",
42+
"no-nested-ternary": "error",
43+
"no-unneeded-ternary": "error",
44+
"prefer-template": "error",
45+
},
46+
},
47+
{
48+
files: ["src/**/*.{ts,tsx,mts}"],
49+
ignores: ["src/**/*.test.ts", "src/content/**"],
50+
rules: {
51+
"no-restricted-imports": [
52+
"error",
53+
{
54+
patterns: [
55+
{
56+
group: ["../../../*", "../../../../*", "../../../../../*"],
57+
message:
58+
"Prefer @/ aliases or feature-local imports over deep parent-relative paths.",
59+
},
60+
],
61+
},
62+
],
63+
},
64+
},
65+
{
66+
files: ["src/**/*.{ts,tsx,mts}", "supabase/functions/**/*.ts"],
67+
rules: {
68+
"import/order": [
69+
"error",
70+
{
71+
groups: [
72+
"builtin",
73+
"external",
74+
"internal",
75+
["parent", "sibling", "index"],
76+
"type",
77+
],
78+
"newlines-between": "always",
79+
alphabetize: {
80+
order: "asc",
81+
caseInsensitive: true,
82+
},
83+
pathGroups: [
84+
{
85+
pattern: "@/**",
86+
group: "internal",
87+
position: "before",
88+
},
89+
],
90+
pathGroupsExcludedImportTypes: ["builtin"],
91+
},
92+
],
93+
},
94+
},
95+
{
96+
files: ["src/actions/**/*.{ts,tsx,mts}"],
97+
ignores: ["src/**/*.test.ts", "src/**/*.test-helpers.ts"],
98+
rules: {
99+
"@typescript-eslint/explicit-module-boundary-types": [
100+
"warn",
101+
{
102+
allowArgumentsExplicitlyTypedAsAny: true,
103+
},
104+
],
105+
},
106+
},
107+
{
108+
files: [
109+
"src/actions/**/*.{ts,tsx,mts}",
110+
"src/lib/**/*.{ts,tsx,mts}",
111+
"supabase/functions/**/*.ts",
112+
],
113+
ignores: ["src/**/*.test.ts", "src/**/*.test-helpers.ts"],
114+
rules: {
115+
complexity: ["warn", 10],
116+
"max-depth": ["warn", 3],
117+
"max-lines-per-function": [
118+
"warn",
119+
{
120+
max: 80,
121+
skipBlankLines: true,
122+
skipComments: true,
123+
},
124+
],
125+
"max-nested-callbacks": ["warn", 2],
126+
},
127+
},
128+
/**
129+
* Preserve Next's default generated-file ignores and extend them with the
130+
* artifacts created by test and coverage tooling.
131+
*/
9132
globalIgnores([
10-
// Default ignores of eslint-config-next:
11133
".next/**",
12134
"out/**",
13135
"build/**",
14136
"next-env.d.ts",
15-
// Generated test artifacts:
16137
"playwright-report/**",
17138
"test-results/**",
18139
"coverage/**",

knip.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema-json",
3+
"entry": [
4+
"src/app/**/{page,layout,loading,not-found,error,route}.ts?(x)",
5+
"supabase/functions/**/index.ts",
6+
"scripts/**/*.mts"
7+
],
8+
"project": [
9+
"src/**/*.{ts,tsx}",
10+
"supabase/functions/**/*.ts",
11+
"scripts/**/*.mts"
12+
],
13+
"ignoreDependencies": ["tailwindcss"]
14+
}

0 commit comments

Comments
 (0)