forked from flint-fyi/flint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.ts
More file actions
245 lines (238 loc) · 6.62 KB
/
Copy patheslint.config.ts
File metadata and controls
245 lines (238 loc) · 6.62 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
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs";
import eslint from "@eslint/js";
import eslintJson from "@eslint/json";
import markdown from "@eslint/markdown";
import vitest from "@vitest/eslint-plugin";
import jsdoc from "eslint-plugin-jsdoc";
import jsonc from "eslint-plugin-jsonc";
import n from "eslint-plugin-n";
import packageJson from "eslint-plugin-package-json/experimental";
import perfectionist from "eslint-plugin-perfectionist";
import * as regexp from "eslint-plugin-regexp";
import yml from "eslint-plugin-yml";
import { defineConfig, globalIgnores } from "eslint/config";
import tseslint from "typescript-eslint";
// https://typescript-eslint.io/troubleshooting/typed-linting/performance#importextensions-enforcing-extensions-are-not-used
function banJsImportExtension() {
const message = `Unexpected use of .js file extension (.js) in import; please use .ts`;
const literalAttributeMatcher = `Literal[value=/\\..+\\.js$/]`;
return [
{
message,
// import foo from 'bar.js';
selector: `ImportDeclaration > ${literalAttributeMatcher}.source`,
},
{
message,
// export { foo } from 'bar.js';
selector: `ExportNamedDeclaration > ${literalAttributeMatcher}.source`,
},
{
message,
// type Foo = typeof import('bar.js');
selector: `TSImportType > TSLiteralType > ${literalAttributeMatcher}`,
},
];
}
export default defineConfig(
globalIgnores([
"**/*.snap",
"**/node_modules",
"packages/*/.astro",
"packages/*/dist",
"packages/*/lib",
"packages/fixtures",
"packages/e2e/tests/**/fixtures/**",
"pnpm-lock.yaml",
"coverage",
]),
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
{
extends: [
comments.recommended,
eslint.configs.recommended,
jsdoc.configs["flat/contents-typescript-error"],
jsdoc.configs["flat/logical-typescript-error"],
jsdoc.configs["flat/stylistic-typescript-error"],
n.configs["flat/recommended"],
perfectionist.configs["recommended-natural"],
regexp.configs["flat/recommended"],
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
],
files: ["**/*.{js,ts}"],
languageOptions: {
parserOptions: {
projectService: true,
},
},
rules: {
"@eslint-community/eslint-comments/disable-enable-pair": [
"error",
{ allowWholeFile: true },
],
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/no-unnecessary-condition": [
"error",
{ allowConstantLoopConditions: true },
],
"@typescript-eslint/no-unused-vars": [
"error",
{
enableAutofixRemoval: {
imports: true,
},
ignoreUsingDeclarations: true,
},
],
"@typescript-eslint/prefer-nullish-coalescing": [
"error",
{ ignorePrimitives: true },
],
"@typescript-eslint/restrict-template-expressions": [
"error",
{ allowNumber: true },
],
eqeqeq: ["error", "always", { null: "ignore" }],
"jsdoc/check-tag-names": [
"error",
// https://tsdoc.org/pages/tags/remarks
{ definedTags: ["remarks"], typed: true },
],
"n/no-missing-import": "off",
"n/no-unsupported-features/node-builtins": [
"error",
{ allowExperimental: true },
],
// Stylistic concerns that don't interfere with Prettier
"logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
],
"no-useless-rename": "error",
"object-shorthand": "error",
"operator-assignment": "error",
// https://github.com/eslint-community/eslint-plugin-n/issues/472
"n/no-unpublished-bin": "off",
// Covered by knip
"n/no-extraneous-import": "off",
"n/no-extraneous-require": "off",
"n/no-unpublished-import": "off",
"n/no-unpublished-require": "off",
// Restrict imports
"@typescript-eslint/no-restricted-imports": [
"error",
{
message: "Use zod/v4 for the modern v4 API instead.",
name: "zod",
},
],
// Use no-restricted-syntax to target e.g. `type Foo = typeof import('foo.js')` as well.
"no-restricted-syntax": ["error", ...banJsImportExtension()],
// Covered by Prettier plugin
"perfectionist/sort-imports": "off",
"perfectionist/sort-named-imports": "off",
},
settings: {
perfectionist: { partitionByComment: true, type: "natural" },
},
},
{
files: ["packages/core/**/*.ts"],
ignores: ["packages/core/**/*.test.ts"],
rules: {
"@typescript-eslint/no-restricted-imports": [
"error",
{
message:
"Use Standard Schema for abstractions or Zod Core for parsing.",
name: "zod",
},
{
message:
"Use Standard Schema for abstractions or Zod Core for parsing.",
name: "zod/v4",
},
],
},
},
{
files: ["packages/site/**/*.ts"],
rules: {
"@typescript-eslint/no-restricted-imports": [
"error",
{
paths: [
{
message: "Use astro/zod instead of the main Zod package.",
name: "zod",
},
],
patterns: [
{
group: ["zod/*"],
message: "Use astro/zod instead of the main Zod package.",
},
],
},
],
},
},
{
extends: [jsonc.configs["flat/recommended-with-json"]],
files: ["**/*.json"],
ignores: ["**/tsconfig.json", "**/tsconfig.*.json"],
},
{
extends: [jsonc.configs["flat/recommended-with-jsonc"]],
files: ["**/tsconfig.json", "**/tsconfig.*.json", "**/*.jsonc"],
},
{
extends: [markdown.configs.recommended],
files: ["**/*.md"],
rules: {
// https://github.com/eslint/markdown/issues/294
"markdown/no-missing-label-refs": "off",
},
},
{
extends: [tseslint.configs.disableTypeChecked],
files: ["**/*.md/*.ts"],
rules: { "n/no-missing-import": "off" },
},
{
extends: [vitest.configs.recommended],
files: ["**/*.test.*"],
rules: { "@typescript-eslint/no-unsafe-assignment": "off" },
settings: { vitest: { typecheck: true } },
},
// E2E tests and configs live next to fixture package.json (no vitest/execa/@flint.fyi/ts); allow packages/e2e devDependencies
// E2E runs on Node >=24 (see packages/e2e/package.json engines), so import.meta.dirname is supported
{
files: ["packages/e2e/tests/**/*.ts"],
rules: {
"n/no-unsupported-features/node-builtins": "off",
},
},
{
extends: [yml.configs["flat/standard"], yml.configs["flat/prettier"]],
files: ["**/*.{yml,yaml}"],
rules: {
"yml/file-extension": "error",
"yml/sort-sequence-values": [
"error",
{ order: { type: "asc" }, pathPattern: "^.*$" },
],
},
},
{
extends: [packageJson.configs.recommended, packageJson.configs.stylistic],
files: ["**/package.json"],
ignores: ["packages/e2e/tests/**/package.json"],
plugins: { json: eslintJson },
rules: {
"package-json/require-homepage": "error",
},
},
);