Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
150 lines (144 loc) · 4.25 KB
/
Copy pathvite.config.ts
File metadata and controls
150 lines (144 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { defineConfig } from 'vite-plus';
// Workspace-wide lint + format. `vp check` only reads this root block, so
// package differences live in `overrides` instead of per-package configs.
type TRestrictedImports = [
'warn',
{ patterns: { group: string[]; message: string }[] }
];
const unusedIgnoringUnderscore: [
'error',
{
vars: 'all';
varsIgnorePattern: string;
args: 'after-used';
argsIgnorePattern: string;
}
] = [
'error',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_'
}
];
const avoidDeepRelative = (
alias: string,
example: string
): TRestrictedImports => [
'warn',
{
patterns: [
{
group: ['../../*'],
message: `Avoid deep relative imports. Use the ${alias} alias (e.g. ${example}) instead.`
}
]
}
];
// Same set as eslint-plugin-react-hooks' recommended preset (v7.1.1);
// Oxlint implements the React Compiler rules natively under `react/`.
// config/gating only validate compiler options, which the client does not use.
const reactHooksRules = {
'react/rules-of-hooks': 'error',
'react/exhaustive-deps': 'error',
'react/static-components': 'error',
'react/use-memo': 'error',
// flags valid useCallback/useMemo the compiler would handle itself
'react/preserve-manual-memoization': 'warn',
'react/incompatible-library': 'warn',
'react/globals': 'error',
'react/refs': 'error',
'react/purity': 'error',
'react/immutability': 'error',
// valid sites (external-system sync, mirroring fetched data into form
// state, reset on prop change) carry an inline disable + reason
'react/set-state-in-effect': 'error',
'react/error-boundaries': 'error',
'react/set-state-in-render': 'error',
'react/unsupported-syntax': 'warn'
} as const;
export default defineConfig({
fmt: {
singleQuote: true,
printWidth: 80,
proseWrap: 'always',
tabWidth: 2,
useTabs: false,
trailingComma: 'none',
bracketSpacing: true,
semi: true,
// TypeScript's organizeImports order (what prettier-plugin-organize-
// imports applied): one alphabetical block for packages and aliases,
// relative paths after, blank lines start a new block.
sortImports: {
groups: [
['builtin', 'external', 'internal', 'subpath', 'unknown'],
['parent', 'sibling', 'index']
],
newlinesBetween: false,
partitionByNewline: true,
ignoreCase: true
},
// formatting covers TS/TSX only; docs, config and data stay hand-written
ignorePatterns: [
'*.md',
'*.json',
'*.yaml',
'*.yml',
'*.css',
'*.html',
'*.js',
'*.mjs',
'**/dist/**',
'**/build/**',
'**/.vite-devmaps/**',
'**/data*/**',
'**/drizzle/**',
'*.wiki/**'
],
overrides: [{ files: ['apps/client/**'], options: { tabWidth: 4 } }]
},
lint: {
plugins: ['eslint', 'typescript', 'unicorn', 'oxc', 'react'],
jsPlugins: [{ name: 'vite-plus', specifier: 'vite-plus/oxlint-plugin' }],
options: {
typeAware: true,
typeCheck: true,
reportUnusedDisableDirectives: 'error'
},
// public/ holds vendored, minified worklet builds
ignorePatterns: ['**/public/**'],
rules: {
'vite-plus/prefer-vite-plus-imports': 'error',
'no-unused-vars': unusedIgnoringUnderscore,
'typescript/no-explicit-any': 'warn',
// typescript-eslint recommended, off by default in Oxlint
'typescript/ban-ts-comment': 'error',
'typescript/no-empty-object-type': 'error',
// Node exits on an unhandled rejection (a publisher whose DB query
// fails is a crash); in the client it is a silently lost error.
'typescript/no-floating-promises': 'error'
},
overrides: [
{
files: ['apps/server/**/*.ts'],
rules: {
'no-restricted-imports': avoidDeepRelative('@server/', '@server/db')
}
},
{
files: ['apps/client/**/*.{ts,tsx}'],
rules: {
...reactHooksRules,
'react/only-export-components': 'warn',
'no-restricted-imports': avoidDeepRelative('@/', '@/components/foo')
}
},
{
files: ['**/__tests__/**/*.ts'],
rules: { 'typescript/no-explicit-any': 'off' }
}
]
}
});