forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
162 lines (160 loc) · 5.25 KB
/
eslint.config.mjs
File metadata and controls
162 lines (160 loc) · 5.25 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
import eslint from '@eslint/js';
import prettier from 'eslint-config-prettier';
import importPlugin from 'eslint-plugin-import';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import security from 'eslint-plugin-security';
import tseslint from 'typescript-eslint';
/** @type {import('eslint').ESLint.Plugin} */
const partitionPlugin = {
rules: {
'no-hardcoded-arn-partition': {
meta: {
type: 'problem',
docs: { description: 'Disallow hardcoded arn:aws: partition in ARN construction. Use arnPrefix(region) instead.' },
schema: [],
},
create(context) {
function checkForHardcodedArn(node, value) {
if (/arn:aws:/.test(value)) {
context.report({ node, message: 'Hardcoded "arn:aws:" detected. Use arnPrefix(region) from src/cli/aws/partition.ts for multi-partition support.' });
}
}
return {
TemplateLiteral(node) {
for (const quasi of node.quasis) {
checkForHardcodedArn(node, quasi.value.raw);
}
},
};
},
},
'no-hardcoded-endpoint-tld': {
meta: {
type: 'problem',
docs: { description: 'Disallow hardcoded amazonaws.com in endpoint URL construction. Use serviceEndpoint() or dnsSuffix() instead.' },
schema: [],
},
create(context) {
const REGION_PATTERN = /[a-z]{2}(-[a-z]+-\d+)/;
function hasHardcodedEndpoint(value) {
return /\.amazonaws\.com/.test(value);
}
function hasHardcodedEndpointWithRegion(value) {
return hasHardcodedEndpoint(value) && REGION_PATTERN.test(value);
}
return {
TemplateLiteral(node) {
for (const quasi of node.quasis) {
if (hasHardcodedEndpoint(quasi.value.raw)) {
context.report({ node, message: 'Hardcoded ".amazonaws.com" in template literal. Use serviceEndpoint() or dnsSuffix() from src/cli/aws/partition.ts for multi-partition support.' });
}
}
},
Literal(node) {
if (typeof node.value === 'string' && hasHardcodedEndpointWithRegion(node.value)) {
context.report({ node, message: 'Hardcoded endpoint with region detected. Use serviceEndpoint() or dnsSuffix() from src/cli/aws/partition.ts for multi-partition support.' });
}
},
};
},
},
},
};
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
'@typescript-eslint': tseslint.plugin,
import: importPlugin,
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
security,
partition: partitionPlugin,
},
rules: {
'partition/no-hardcoded-arn-partition': 'error',
'partition/no-hardcoded-endpoint-tld': 'error',
...importPlugin.configs.recommended.rules,
...react.configs.recommended.rules,
...security.configs.recommended.rules,
// CLI inherently works with dynamic file paths and Record lookups — these are false positives
'security/detect-non-literal-fs-filename': 'off',
'security/detect-object-injection': 'off',
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react-hooks/preserve-manual-memoization': 'warn',
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'import/no-unresolved': 'off', // TypeScript handles this
// Allow intentional unused placeholders like `_unused`
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
settings: {
react: {
version: 'detect',
},
'import/resolver': {
typescript: true,
node: true,
},
},
},
prettier,
// Relaxed rules for test files
{
files: ['**/*.test.ts', '**/*.test.tsx', '**/test-utils/**', 'integ-tests/**'],
rules: {
'partition/no-hardcoded-arn-partition': 'off',
'partition/no-hardcoded-endpoint-tld': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
},
},
{
ignores: [
'dist',
'node_modules',
'src/assets',
'src/schema/llm-compacted',
'.agentcore',
'**/.agentcore/**',
'.venv',
'**/.venv/**',
'*.config.js',
'.idea',
'.vscode',
'.kiro',
'.amazonq',
'coverage',
'*.log',
'*.tsbuildinfo',
],
}
);