-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
217 lines (201 loc) · 7.24 KB
/
eslint.config.js
File metadata and controls
217 lines (201 loc) · 7.24 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
import { fixupPluginRules } from '@eslint/compat';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import boundariesPlugin from 'eslint-plugin-boundaries';
import prettierConfig from 'eslint-config-prettier';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import prettierPlugin from 'eslint-plugin-prettier';
import securityPlugin from 'eslint-plugin-security';
import sonarjsPlugin from 'eslint-plugin-sonarjs';
export default [
// Ignore patterns
{
ignores: ['node_modules/**', 'dist/**', 'coverage/**', '*.config.js', '*.config.ts'],
},
// TypeScript files
{
files: ['src/**/*.ts'],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
project: './tsconfig.json',
},
globals: {
// Browser globals
window: 'readonly',
document: 'readonly',
localStorage: 'readonly',
sessionStorage: 'readonly',
console: 'readonly',
URL: 'readonly',
Blob: 'readonly',
crypto: 'readonly',
KeyboardEvent: 'readonly',
Element: 'readonly',
HTMLElement: 'readonly',
HTMLAnchorElement: 'readonly',
},
},
plugins: {
'@typescript-eslint': tsPlugin,
boundaries: boundariesPlugin,
jsdoc: jsdocPlugin,
prettier: prettierPlugin,
security: fixupPluginRules(securityPlugin),
sonarjs: fixupPluginRules(sonarjsPlugin),
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
'boundaries/elements': [
{ type: 'entry', pattern: 'src/index.ts', mode: 'file' },
{ type: 'core', pattern: 'src/core' },
{ type: 'module', pattern: 'src/*', capture: ['family'] },
],
},
rules: {
// TypeScript recommended rules
...tsPlugin.configs['recommended'].rules,
...tsPlugin.configs['recommended-requiring-type-checking'].rules,
// Prettier integration
'prettier/prettier': 'error',
// Security rules
'security/detect-bidi-characters': 'error',
'security/detect-eval-with-expression': 'error',
'security/detect-unsafe-regex': 'error',
'security/detect-non-literal-regexp': 'warn',
'security/detect-possible-timing-attacks': 'warn',
'security/detect-object-injection': 'off',
// SonarJS - Code quality
'sonarjs/prefer-immediate-return': 'warn',
'sonarjs/no-identical-functions': 'warn',
'sonarjs/no-duplicated-branches': 'warn',
'sonarjs/no-redundant-jump': 'warn',
'sonarjs/no-useless-catch': 'warn',
'sonarjs/no-small-switch': 'warn',
'sonarjs/prefer-single-boolean-return': 'warn',
'sonarjs/cognitive-complexity': ['warn', 15],
// TypeScript specific rules
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/strict-boolean-expressions': 'warn',
// Redundant code detection
'@typescript-eslint/no-unnecessary-condition': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-useless-empty-export': 'warn',
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
'@typescript-eslint/prefer-optional-chain': 'warn',
// Code quality rules
'no-console': ['warn', { allow: ['warn', 'error'] }],
'prefer-const': 'error',
'no-var': 'error',
eqeqeq: ['error', 'always', { null: 'ignore' }],
curly: ['error', 'all'],
// Prevent confusing patterns (PhpStorm warnings)
'no-sequences': ['error', { allowInParentheses: false }], // Disallow comma expressions
// Module boundary enforcement
'boundaries/dependencies': [
'error',
{
default: 'disallow',
rules: [
// Entry point can import any module
{
from: { type: 'entry' },
allow: [{ to: { type: 'core' } }, { to: { type: 'module' } }],
},
// Core can only import from core (internal)
{
from: { type: 'core' },
allow: [{ to: { type: 'core' } }],
},
// Domain modules can import from core and from themselves (same family)
{
from: { type: 'module' },
allow: [
{ to: { type: 'core' } },
{ to: { type: 'module', captured: { family: '{{ from.captured.family }}' } } },
],
},
// session extends BaseStorageManager from storage
{
from: { type: 'module', captured: { family: 'session' } },
allow: [{ to: { type: 'module', captured: { family: 'storage' } } }],
},
// offline integrates indexeddb persistence with network status
{
from: { type: 'module', captured: { family: 'offline' } },
allow: [
{ to: { type: 'module', captured: { family: 'indexeddb' } } },
{ to: { type: 'module', captured: { family: 'network' } } },
],
},
],
},
],
// JSDoc validation
'jsdoc/check-param-names': 'error', // @param names must match function parameters
'jsdoc/check-tag-names': 'error', // Only valid JSDoc tags
'jsdoc/no-types': 'error', // Don't use types in JSDoc (TypeScript handles this)
},
},
// Test files - relax some rules
{
files: ['tests/**/*.ts', '**/*.test.ts', '**/*.spec.ts'],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
project: './tsconfig.json',
},
globals: {
// Browser globals
window: 'readonly',
document: 'readonly',
localStorage: 'readonly',
console: 'readonly',
URL: 'readonly',
Blob: 'readonly',
KeyboardEvent: 'readonly',
},
},
plugins: {
'@typescript-eslint': tsPlugin,
prettier: prettierPlugin,
},
rules: {
...tsPlugin.configs['recommended'].rules,
// Prettier integration
'prettier/prettier': 'error',
// Relax rules for tests
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-explicit-any': 'off',
// Code quality
'prefer-const': 'error',
'no-var': 'error',
},
},
// Disable formatting rules that conflict with Prettier
prettierConfig,
];