@agentpulselabs/eslint-config 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/testing.js +58 -5
package/package.json
CHANGED
package/src/testing.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
1
3
|
const TEST_CALL_NAMES = new Set(['test', 'it']);
|
|
2
4
|
const ASSERTION_METHODS = new Set([
|
|
3
5
|
'ok',
|
|
@@ -112,21 +114,76 @@ const requireAssertionRule = {
|
|
|
112
114
|
},
|
|
113
115
|
};
|
|
114
116
|
|
|
117
|
+
const noRepoEscapeImportRule = {
|
|
118
|
+
meta: {
|
|
119
|
+
type: 'problem',
|
|
120
|
+
docs: {
|
|
121
|
+
description: 'Disallow relative imports that resolve outside the repository root',
|
|
122
|
+
},
|
|
123
|
+
schema: [],
|
|
124
|
+
},
|
|
125
|
+
create(context) {
|
|
126
|
+
const cwd = path.resolve(context.cwd || process.cwd());
|
|
127
|
+
const fileDir = context.filename && path.isAbsolute(context.filename)
|
|
128
|
+
? path.dirname(context.filename)
|
|
129
|
+
: cwd;
|
|
130
|
+
|
|
131
|
+
function checkSource(sourceNode) {
|
|
132
|
+
const spec = sourceNode?.value;
|
|
133
|
+
if (typeof spec !== 'string' || !spec.startsWith('.')) return;
|
|
134
|
+
const resolved = path.resolve(fileDir, spec);
|
|
135
|
+
if (resolved !== cwd && !resolved.startsWith(`${cwd}${path.sep}`)) {
|
|
136
|
+
context.report({
|
|
137
|
+
node: sourceNode,
|
|
138
|
+
message: `Relative import '${spec}' escapes the repository root; use published packages (@agentpulselabs/test-kit, @agentpulselabs/platform-sdk) instead.`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
ImportDeclaration(node) {
|
|
145
|
+
checkSource(node.source);
|
|
146
|
+
},
|
|
147
|
+
ExportNamedDeclaration(node) {
|
|
148
|
+
if (node.source) checkSource(node.source);
|
|
149
|
+
},
|
|
150
|
+
ExportAllDeclaration(node) {
|
|
151
|
+
checkSource(node.source);
|
|
152
|
+
},
|
|
153
|
+
ImportExpression(node) {
|
|
154
|
+
if (node.source?.type === 'Literal') checkSource(node.source);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
115
160
|
export const agentpulseTestingPlugin = {
|
|
116
161
|
rules: {
|
|
117
162
|
'require-assertion': requireAssertionRule,
|
|
163
|
+
'no-repo-escape-import': noRepoEscapeImportRule,
|
|
118
164
|
},
|
|
119
165
|
};
|
|
120
166
|
|
|
121
167
|
export const testingConfig = [
|
|
122
168
|
{
|
|
123
169
|
name: '@agentpulselabs/eslint-config/testing',
|
|
124
|
-
files: [
|
|
170
|
+
files: [
|
|
171
|
+
'**/*.test.js',
|
|
172
|
+
'**/*.test.mjs',
|
|
173
|
+
'**/*.test.ts',
|
|
174
|
+
'**/*.selftest.js',
|
|
175
|
+
'**/*.selftest.mjs',
|
|
176
|
+
'test/**/*.js',
|
|
177
|
+
'test/**/*.mjs',
|
|
178
|
+
'tests/**/*.js',
|
|
179
|
+
'tests/**/*.mjs',
|
|
180
|
+
],
|
|
125
181
|
plugins: {
|
|
126
182
|
'agentpulse-testing': agentpulseTestingPlugin,
|
|
127
183
|
},
|
|
128
184
|
rules: {
|
|
129
185
|
'agentpulse-testing/require-assertion': 'warn',
|
|
186
|
+
'agentpulse-testing/no-repo-escape-import': 'error',
|
|
130
187
|
'no-restricted-imports': [
|
|
131
188
|
'error',
|
|
132
189
|
{
|
|
@@ -137,10 +194,6 @@ export const testingConfig = [
|
|
|
137
194
|
},
|
|
138
195
|
],
|
|
139
196
|
patterns: [
|
|
140
|
-
{
|
|
141
|
-
group: ['../../*', '../../../*', '**/AgentforceVoice/**', '**/Google_Cloud/**'],
|
|
142
|
-
message: 'Do not climb outside the app repository root or import private platform checkouts; use @agentpulselabs/test-kit.',
|
|
143
|
-
},
|
|
144
197
|
{
|
|
145
198
|
group: ['@agentpulse/platform/dal/*', '@agentpulse/platform/dal/**'],
|
|
146
199
|
message: 'Do not import private @agentpulse/platform/dal/* paths from app tests.',
|