-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mts
More file actions
185 lines (180 loc) · 6.34 KB
/
Copy patheslint.config.mts
File metadata and controls
185 lines (180 loc) · 6.34 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
// eslint.config.mjs
// @ts-check
import eslint from '@eslint/js';
import type { Linter } from 'eslint';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import vitest from "eslint-plugin-vitest";
import suggestMembers from "@ton-ai-core/eslint-plugin-suggest-members";
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import globals from "globals";
import eslintComments from "@eslint-community/eslint-plugin-eslint-comments";
// CHANGE: Типобезопасно инкапсулируем правила eslint-comments вместо устаревшей legacy-конфигурации
// WHY: Штатная recommended-конфигурация использует строковые severity и нарушает RuleConfig типы в flat-config
// QUOTE(ТЗ): "ТИПОВАЯ БЕЗОПАСНОСТЬ ... Всегда: исчерпывающий анализ union types"
// REF: User TypeScript diagnostic TS2345
// SOURCE: https://eslint-community.github.io/eslint-plugin-eslint-comments/
// FORMAT THEOREМ: ∀ rule ∈ eslint-comments: legacy(rule) → typed(rule) ≡ ["error"]
// PURITY: CORE
// INVARIANT: Enabled comment rules always emit Effect-free diagnostics
// COMPLEXITY: O(1)/O(1)
const eslintCommentsRecommended = {
name: "eslint-comments/recommended",
plugins: {
"@eslint-community/eslint-comments": eslintComments,
},
rules: {
"@eslint-community/eslint-comments/disable-enable-pair": ["error"],
"@eslint-community/eslint-comments/no-aggregating-enable": ["error"],
"@eslint-community/eslint-comments/no-duplicate-disable": ["error"],
"@eslint-community/eslint-comments/no-unlimited-disable": ["error"],
"@eslint-community/eslint-comments/no-unused-enable": ["error"],
},
} satisfies Linter.Config;
export default defineConfig(
eslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
tseslint.configs.strictTypeChecked,
suggestMembers.configs.recommended,
eslintCommentsRecommended,
{
languageOptions: {
parser: tseslint.parser,
globals: { ...globals.node, ...globals.browser },
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
files: ["**/*.{ts,tsx}"],
rules: {
complexity: ["error", 8],
"max-lines-per-function": [
"error",
{ max: 50, skipBlankLines: true, skipComments: true },
],
"max-params": ["error", 5],
"max-depth": ["error", 4],
"max-lines": [
"error",
{ max: 300, skipBlankLines: true, skipComments: true },
],
"@typescript-eslint/restrict-template-expressions": ["error", {
allowNumber: true,
allowBoolean: true,
allowNullish: false,
allowAny: false,
allowRegExp: false
}],
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": true,
"ts-nocheck": true,
"ts-expect-error": true,
"ts-check": true,
},
],
"@eslint-community/eslint-comments/no-use": "error",
"@eslint-community/eslint-comments/no-unlimited-disable": "error",
"@eslint-community/eslint-comments/disable-enable-pair": "error",
"@eslint-community/eslint-comments/no-unused-disable": "error",
"no-restricted-syntax": [
"error",
{
selector: "TSUnknownKeyword",
message: "Запрещено 'unknown'.",
},
{
selector: "SwitchStatement",
message: [
"Switch statements are forbidden in functional programming paradigm.",
"How to fix: Use ts-pattern match() instead.",
"Example:",
" import { match } from 'ts-pattern';",
" type Item = { type: 'this' } | { type: 'that' };",
" const result = match(item)",
" .with({ type: 'this' }, (it) => processThis(it))",
" .with({ type: 'that' }, (it) => processThat(it))",
" .exhaustive();",
].join("\n"),
},
{
selector: 'CallExpression[callee.name="require"]',
message: "Avoid using require(). Use ES6 imports instead.",
},
{
selector: "ThrowStatement > Literal:not([value=/^\\w+Error:/])",
message:
'Do not throw string literals or non-Error objects. Throw new Error("...") instead.',
},
{
selector:
"FunctionDeclaration[async=true], FunctionExpression[async=true], ArrowFunctionExpression[async=true]",
message:
"Запрещён async/await — используй Effect.gen / Effect.tryPromise.",
},
{
selector: "NewExpression[callee.name='Promise']",
message:
"Запрещён new Promise — используй Effect.async / Effect.tryPromise.",
},
{
selector: "CallExpression[callee.object.name='Promise']",
message:
"Запрещены Promise.* — используй комбинаторы Effect (all, forEach, etc.).",
},
],
"@typescript-eslint/no-restricted-types": [
"error",
{
types: {
unknown: {
message:
"Не используем 'unknown'. Уточни тип или наведи порядок в источнике данных.",
},
Promise: {
message: "Запрещён Promise — используй Effect.Effect<A, E, R>.",
suggest: ["Effect.Effect"],
},
"Promise<*>": {
message:
"Запрещён Promise<T> — используй Effect.Effect<T, E, R>.",
suggest: ["Effect.Effect<T, E, R>"],
},
},
},
],
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
"no-throw-literal": "off",
"@typescript-eslint/only-throw-error": [
"error",
{ allowThrowingUnknown: false, allowThrowingAny: false },
],
}
},
{
files: ['**/*.{test,spec}.{ts,tsx}', 'tests/**', '**/__tests__/**'],
...vitest.configs.all,
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
rules: {
// Allow eslint-disable/enable comments in test files for fine-grained control
'@eslint-community/eslint-comments/no-use': 'off',
// Disable line count limit for E2E tests that contain multiple test cases
'max-lines-per-function': 'off',
},
},
// 3) Для JS-файлов отключим типо-зависимые проверки
{
files: ['**/*.{js,cjs,mjs}'],
extends: [tseslint.configs.disableTypeChecked],
},
// 4) Глобальные игноры
{ ignores: ['dist/**', 'build/**', 'coverage/**'] },
);