Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
258 lines (256 loc) · 8.35 KB
/
Copy patheslint.config.js
File metadata and controls
258 lines (256 loc) · 8.35 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import prettier from 'eslint-config-prettier';
import js from '@eslint/js';
import { includeIgnoreFile } from '@eslint/compat';
import { defineConfig } from 'eslint/config';
import svelte from 'eslint-plugin-svelte';
import betterTailwindcss from 'eslint-plugin-better-tailwindcss';
import security from 'eslint-plugin-security';
import importPlugin from 'eslint-plugin-import';
import checkFile from 'eslint-plugin-check-file';
import globals from 'globals';
import { fileURLToPath } from 'node:url';
import ts from 'typescript-eslint';
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
export default defineConfig(
includeIgnoreFile(gitignorePath),
{ ignores: ['src/lib/editor/generated/**'] },
js.configs.recommended,
...ts.configs.recommendedTypeChecked,
...svelte.configs.recommended,
{ ...security.configs.recommended, files: ['**/*.ts'] },
prettier,
...svelte.configs.prettier,
{
linterOptions: { reportUnusedDisableDirectives: 'error' },
languageOptions: {
globals: { ...globals.browser, ...globals.node }
},
rules: {
'no-undef': 'off',
// linterOptions.reportUnusedDisableDirectives does not cover comments in Svelte templates.
'svelte/comment-directive': ['error', { reportUnusedDisableDirectives: true }],
'no-console': 'error',
// It will currently also error on external links or links with query parameters.
// https://github.com/sveltejs/eslint-plugin-svelte/issues/1353
'svelte/no-navigation-without-resolve': 'error',
'svelte/no-restricted-html-elements': [
'error',
{ elements: ['dialog'], message: 'Use the shared Modal component instead of <dialog>.' }
],
// Flags every computed member access; nearly all hits are array indices or typed Record lookups.
'security/detect-object-injection': 'off'
}
},
{
languageOptions: {
parserOptions: {
projectService: {
// Root config files that no tsconfig includes.
allowDefaultProject: [
'drizzle.config.ts',
'playwright.config.ts',
'vitest.arch.config.ts'
]
},
extraFileExtensions: ['.svelte'],
parser: ts.parser
}
},
rules: {
// Untyped JSON, third-party data and test mocks make up nearly all of the ~1,000 hits;
// svelte-check with `strict` already covers the typed code. See #411.
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
// Mostly async functions that implement an async interface without awaiting; style, not bugs.
'@typescript-eslint/require-await': 'off'
}
},
{
// Plain JS files (root configs, server.js, CLI scripts) are outside every tsconfig.
files: ['**/*.js', '**/*.mjs'],
...ts.configs.disableTypeChecked
},
{
files: ['src/**/*.svelte'],
plugins: { 'better-tailwindcss': betterTailwindcss },
settings: {
'better-tailwindcss': {
entryPoint: 'src/app.css'
}
},
rules: {
'better-tailwindcss/no-unknown-classes': [
'warn',
{
detectComponentClasses: true,
ignore: [
'dropdown-content',
'dropdown-open',
'swap-on',
'swap-off',
'label-text',
'menu-disabled',
'tab-active',
'tab-strip',
'preview-scroll',
'modal-top-search',
'table-pin-rows'
]
}
],
'better-tailwindcss/no-restricted-classes': [
'error',
{
restrict: [
'^(bg-white|bg-black|text-(gray|slate|zinc)-\\d+|bg-(gray|slate|zinc)-\\d+|border-(gray|slate)-\\d+)$'
]
}
]
}
},
{
// CLI scripts and E2E helper processes that run without the app's logger.
files: ['e2e/support/**/*.ts', 'src/lib/editor/grammar/patch-generated.mjs'],
rules: { 'no-console': 'off' }
},
{
// Tests read and write fixtures and temp files they create themselves.
files: ['**/*.{test,spec}.ts', 'e2e/**/*.ts', 'src/architecture-tests/**/*.ts'],
rules: { 'security/detect-non-literal-fs-filename': 'off' }
},
{
files: ['**/*.{test,spec}.ts', '**/*.test-utils.ts'],
rules: {
// `expect(mock.method).toHaveBeenCalled()` passes methods around unbound by design.
'@typescript-eslint/unbound-method': 'off',
// Async `mockImplementation()`s for mocks typed with a void return.
'@typescript-eslint/no-misused-promises': [
'error',
{ checksVoidReturn: { arguments: false } }
]
}
},
{
files: ['src/**/*.ts'],
ignores: ['src/**/*.test.ts', 'src/**/*.spec.ts'],
rules: { 'max-lines': ['error', { max: 2400, skipBlankLines: false, skipComments: false }] }
},
{
files: ['src/**/*.svelte'],
rules: { 'max-lines': ['error', { max: 1200, skipBlankLines: false, skipComments: false }] }
},
{
files: ['src/**/*.{test,spec}.ts'],
rules: { 'max-lines': ['error', { max: 1000, skipBlankLines: false, skipComments: false }] }
},
{
files: [
'src/lib/stores/**/*.{ts,svelte.ts}',
'src/lib/components/**/*.svelte',
'src/lib/server/**/*.svelte.ts'
],
plugins: { 'check-file': checkFile },
rules: {
'check-file/filename-naming-convention': [
'error',
{
'src/lib/components/**/!(*.spec).svelte': 'PASCAL_CASE'
}
],
'check-file/filename-blocklist': [
'error',
{
'src/lib/stores/**/!(*.svelte|*.spec).ts': '*.svelte.ts',
'src/lib/server/**/*.svelte.ts': '*.ts'
}
]
}
},
{
files: ['src/lib/components/ui/Modal.svelte'],
rules: { 'svelte/no-restricted-html-elements': 'off' }
},
{
// Generic building blocks: everything comes in through props, so they must not depend on app
// state, routing or feature modules (see "Component Layers" in AGENTS.md).
files: ['src/lib/components/ui/**/*.{svelte,ts}'],
// Specs may load the global stylesheet to test against the real styles.
ignores: ['src/lib/components/ui/**/*.spec.ts'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['$lib/*', '!$lib/paraglide', '!$lib/types', '!$lib/components'],
message: 'ui/ components may only import Paraglide messages, shared types and ui/.'
},
{
group: ['$lib/components/*', '!$lib/components/ui'],
message: 'ui/ components must not import app or feature components.'
},
{
group: ['$app/*'],
message: 'ui/ components must not depend on SvelteKit app state.'
},
{ group: ['../*'], message: 'ui/ components must not import from outside ui/.' }
]
}
]
}
},
{
files: [
'src/lib/client/**/*.ts',
'src/lib/stores/**/*.ts',
'src/lib/storage/**/*.ts',
'src/lib/editor/**/*.ts',
'src/lib/types/**/*.ts'
],
plugins: { import: importPlugin },
settings: { 'import/resolver': { typescript: true } },
rules: {
'import/no-restricted-paths': [
'error',
{
zones: [
{
target: './src/lib',
from: './src/lib/server',
message: 'Client-side code must not import server code.'
}
]
}
]
}
},
{
files: ['src/lib/server/**/*.ts'],
plugins: { import: importPlugin },
settings: { 'import/resolver': { typescript: true } },
rules: {
'import/no-restricted-paths': [
'error',
{
zones: [
{
target: './src/lib/server',
from: './src/lib/client',
// The server re-exports the PUBLIC_ flags and config it enforces, so each is parsed once.
except: ['./feature-flags.ts', './config.ts'],
message: 'Server code must not import client-only utilities.'
},
{
target: './src/lib/server',
from: './src/lib/stores',
message: 'Server code must not import Svelte stores.'
}
]
}
]
}
}
);