This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
160 lines (158 loc) · 4.47 KB
/
Copy patheslint.config.js
File metadata and controls
160 lines (158 loc) · 4.47 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
import { fileURLToPath } from "node:url";
import { join } from "node:path";
import js from "@eslint/js";
import prettier from "eslint-config-prettier";
import astro from "eslint-plugin-astro";
import svelte from "eslint-plugin-svelte";
import globals from "globals";
import tseslint from "typescript-eslint";
const projectRootDir = fileURLToPath(new URL(".", import.meta.url));
const typeAwareParserOptions = {
project: "./tsconfig.json",
tsconfigRootDir: projectRootDir,
};
const testParserOptions = {
project: "./tsconfig.test.json",
tsconfigRootDir: projectRootDir,
};
const astroParserOptions = {
parser: tseslint.parser,
project: "./tsconfig.json",
extraFileExtensions: [".astro"],
tsconfigRootDir: projectRootDir,
};
const svelteParserOptions = {
parser: tseslint.parser,
project: "./tsconfig.json",
extraFileExtensions: [".svelte"],
svelteConfig: join(projectRootDir, "svelte.config.js"),
tsconfigRootDir: projectRootDir,
};
export default tseslint.config(
{
ignores: [
"dist/**",
".vercel/**",
"node_modules/**",
"src/layouts/Layout.astro",
],
},
{
files: ["**/*.{js,cjs,mjs,ts,tsx,cts,mts,astro,svelte}"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.browser,
...globals.node,
...globals.es2022,
},
},
},
{
files: ["**/*.{ts,tsx,cts,mts}"],
languageOptions: {
parserOptions: typeAwareParserOptions,
},
},
{
files: ["vitest.config.ts"],
languageOptions: {
parserOptions: {
project: "./tsconfig.node.json",
tsconfigRootDir: projectRootDir,
},
},
},
{
files: ["**/__tests__/**/*.ts", "**/*.test.ts"],
languageOptions: {
parserOptions: testParserOptions,
},
},
js.configs.recommended,
...tseslint.configs.recommended,
...astro.configs["flat/recommended"],
...svelte.configs["flat/recommended"],
{
files: ["**/*.{astro,svelte}"],
rules: {
"no-undef": "off",
},
},
{
files: ["**/*.astro"],
processor: "astro/client-side-ts",
languageOptions: {
parserOptions: {
...astroParserOptions,
},
},
},
{
files: ["**/*.svelte"],
languageOptions: {
parserOptions: {
...svelteParserOptions,
},
},
},
...svelte.configs["flat/prettier"],
{
rules: {
curly: ["error", "all"],
eqeqeq: ["warn", "always"],
"no-implicit-coercion": "error",
"prefer-const": "error",
"max-lines": [
"warn",
{ max: 1000, skipBlankLines: true, skipComments: true },
],
"max-lines-per-function": [
"warn",
{ max: 300, skipBlankLines: true, skipComments: true },
],
complexity: ["warn", { max: 15 }],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/triple-slash-reference": "warn",
},
},
{
files: ["**/*.{ts,tsx,cts,mts}"],
ignores: ["**/*.astro/*.ts", "*.astro/*.ts"],
rules: {
"@typescript-eslint/consistent-type-imports": [
"warn",
{ prefer: "type-imports", disallowTypeAnnotations: false },
],
},
},
{
files: ["**/*.astro", "**/*.svelte"],
rules: {
"@typescript-eslint/consistent-type-imports": [
"warn",
{ prefer: "type-imports", disallowTypeAnnotations: false },
],
},
},
{
files: [
"**/*.astro/*.js",
"*.astro/*.js",
"**/*.astro/*.ts",
"*.astro/*.ts",
],
rules: {
// define:vars 等 Astro 注入变量会映射到虚拟客户端脚本,
// 在这层关闭 no-undef,避免把模板注入值误报成未定义。
"no-undef": "off",
},
},
prettier,
);