Repository navigation
Expand file tree
/
Copy patheslint.config.mjs
More file actions
286 lines (280 loc) · 11.5 KB
/
Copy patheslint.config.mjs
File metadata and controls
286 lines (280 loc) · 11.5 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import { globalIgnores } from 'eslint/config';
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import eslintPluginImport from 'eslint-plugin-import';
import eslintPluginPromise from 'eslint-plugin-promise';
import eslintPluginSecurity from 'eslint-plugin-security';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import vitest from '@vitest/eslint-plugin';
export default tseslint.config([
globalIgnores([
'build/',
'bundle/',
'coverage/',
'out/',
'node_modules/',
'eslint.config.mjs',
'webpack.*.js',
'vitest.*',
'**/*.json',
'**/*.yaml',
'**/*.zip',
'**/.DS_Store',
'**/.tsbuildinfo',
'**/*.md',
'src/services/guard/assets/**',
'sbom/',
'vendor/',
'tmp/'
]),
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginImport.flatConfigs.recommended,
eslintPluginImport.flatConfigs.typescript,
eslintPluginPromise.configs['flat/recommended'],
eslintPluginUnicorn.configs['flat/recommended'],
eslintPluginSecurity.configs.recommended,
{
languageOptions: {
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import/resolver': {
typescript: {
project: 'tsconfig.json',
},
},
},
rules: {
// --- General Code Quality & Best Practices ---
'no-console': 'error',
'no-debugger': 'error',
eqeqeq: ['error', 'always'],
'require-atomic-updates': 'error',
// --- TypeScript-ESLint Rules (Strict & Quality) ---
'@typescript-eslint/no-unused-vars': ['error', { caughtErrors: 'none', argsIgnorePattern: '^_' }],
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/consistent-type-assertions': ['error', { assertionStyle: 'as' }],
'no-return-await': 'off',
'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'prefer-const': 'error',
// --- Import Plugin Rules (Organization & Quality) ---
'import/order': [
'error',
{
groups: [
'builtin', // Node.js built-in modules (fs, path, etc.)
'external', // npm packages
'internal', // Internal modules (configured via settings)
'parent', // Parent directory imports (../)
'sibling', // Same directory imports (./)
'index', // Index file imports (./index)
],
'newlines-between': 'never',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'import/no-self-import': 'error',
'import/no-useless-path-segments': 'error',
'import/no-deprecated': 'error',
'import/first': 'error',
'import/no-duplicates': ['error', { 'prefer-inline': true }],
'import/no-namespace': 'error',
'import/no-named-as-default-member': 'error',
// --- Code Quality Plugin Overrides ---
'unicorn/filename-case': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/prefer-at': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prefer-node-protocol': 'off',
'unicorn/prefer-ternary': 'off',
'unicorn/catch-error-name': 'off',
'unicorn/prefer-string-raw': 'off',
'unicorn/import-style': [
'error',
{
styles: {
path: {
named: true,
},
},
},
],
'unicorn/prefer-string-replace-all': 'warn',
'unicorn/prefer-split-limit': 'off',
'unicorn/better-dom-traversing': 'off',
'unicorn/consistent-compound-words': 'off',
'unicorn/prefer-includes-over-repeated-comparisons': 'off',
'security/detect-object-injection': 'off',
'security/detect-non-literal-fs-filename': 'off',
'promise/always-return': 'off',
'promise/catch-or-return': 'off',
},
},
{
files: ['src/**'],
rules: {
'no-restricted-syntax': [
'error',
{
selector: 'CallExpression[callee.property.name="logRecord"]',
message:
'Usage of logRecord() function is restricted in src code. This is meant for debugging purposes only',
},
{
selector: 'MemberExpression[property.name="entityType"]',
message:
'Usage of entityType property is restricted in src code. This call is an expensive operations, use getEntityType from Context instead',
},
{
selector:
'Literal[value=/^(Resources|Parameters|Outputs|Mappings|Metadata|Rules|Conditions|Transform|AWSTemplateFormatVersion)$/]',
message:
'Usage of raw TopLevelSection strings is restricted in src code. Use TopLevelSection enum instead',
},
{
selector:
'Literal[value=/^(Output|Mapping|Metadata|Rule|Transform|AWSTemplateFormatVersion|ForEachResource)$/]',
message: 'Usage of raw EntityType strings is restricted in src code. Use EntityType enum instead',
},
{
selector:
'Literal[value=/^Fn::(Base64|Cidr|FindInMap|ForEach|GetAtt|GetAZs|ImportValue|Join|Length|Select|Split|Sub|ToJsonString|Transform|And|Equals|If|Not|Or|Contains|EachMemberEquals|EachMemberIn|RefAll|ValueOf|ValueOfAll|Implies)$/]',
message:
'Usage of raw IntrinsicFunction strings is restricted in src code. Use IntrinsicFunction enum instead',
},
{
selector:
'Literal[value=/^AWS::(AccountId|Region|StackId|StackName|NotificationARNs|NoValue|Partition|URLSuffix)$/]',
message:
'Usage of raw PseudoParameter strings is restricted in src code. Use PseudoParameter enum instead',
},
{
selector:
'Literal[value=/^(CreationPolicy|DeletionPolicy|UpdatePolicy|UpdateReplacePolicy|DependsOn|Metadata)$/]',
message:
'Usage of raw ResourceAttribute strings is restricted in src code. Use ResourceAttribute enum instead',
},
],
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'os',
importNames: ['userInfo'],
message: 'userInfo is not supported in sandbox Linux environments',
},
{
name: 'fs',
importNames: ['readFileSync', 'readFile'],
message: 'Use methods in File.ts',
},
{
name: 'fs/promises',
importNames: ['readFile'],
message: 'Use methods in File.ts',
},
],
patterns: [
{
group: ['**/ArtifactsDir'],
message: 'Use Storage.ts instead. ArtifactsDir is deprecated.',
},
{
group: [
'vscode-languageserver/*',
'vscode-languageserver-protocol/*',
'vscode-languageserver-textdocument/*',
],
message: 'Import from main package only, not subpaths.',
},
],
},
],
},
},
{
files: ['tools/**', 'tst/**'],
rules: {
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'import/no-namespace': 'off',
'import/order': 'off',
'unicorn/no-null': 'off',
'unicorn/switch-case-braces': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/numeric-separators-style': 'off',
'no-restricted-imports': [
'error',
{
patterns: [
{
group: [
'vscode-languageserver/*',
'vscode-languageserver-protocol/*',
'vscode-languageserver-textdocument/*',
],
message: 'Import from main package only, not subpaths.',
},
],
},
],
},
},
{
files: ['tst/e2e/**', 'tst/integration/**', 'tst/resources/**', 'tst/unit/**'],
plugins: {
vitest,
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
rules: {
...vitest.configs.recommended.rules,
'vitest/no-disabled-tests': 'error',
'vitest/no-conditional-expect': 'off',
'unicorn/consistent-function-scoping': 'off',
},
},
{
files: ['tst/integration/**'],
rules: {
'vitest/expect-expect': 'off',
},
},
{
files: ['tools/**'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'no-console': 'off',
'import/first': 'off',
'unicorn/import-style': 'off',
'unicorn/prefer-string-replace-all': 'off',
'unicorn/prefer-top-level-await': 'off',
},
},
eslintPluginPrettierRecommended, // Must be last to override other configs
]);