@agentpulselabs/eslint-config 0.0.0-stage → 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/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # `@agentpulselabs/eslint-config`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared ESLint flat config for AgentPulse repositories.
4
+
5
+ ## Usage
6
+
7
+ ```js
8
+ import testingConfig from '@agentpulselabs/eslint-config/testing';
9
+
10
+ export default [
11
+ ...testingConfig,
12
+ ];
13
+ ```
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@agentpulselabs/eslint-config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Shared ESLint flat config for AgentPulse repositories and feature apps",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ "./testing": {
9
+ "types": "./src/testing.d.ts",
10
+ "default": "./src/testing.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "src/",
15
+ "package.json",
16
+ "README.md"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "peerDependencies": {
22
+ "eslint": "^9.0.0 || ^10.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "eslint": "^10.15.0"
26
+ }
27
+ }
@@ -0,0 +1,8 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export const agentpulseTestingPlugin: {
4
+ rules: Record<string, unknown>;
5
+ };
6
+
7
+ export const testingConfig: Linter.Config[];
8
+ export default testingConfig;
package/src/testing.js ADDED
@@ -0,0 +1,239 @@
1
+ import path from 'node:path';
2
+
3
+ const TEST_CALL_NAMES = new Set(['test', 'it']);
4
+ const ASSERTION_METHODS = new Set([
5
+ 'ok',
6
+ 'equal',
7
+ 'notEqual',
8
+ 'strictEqual',
9
+ 'notStrictEqual',
10
+ 'deepEqual',
11
+ 'notDeepEqual',
12
+ 'deepStrictEqual',
13
+ 'notDeepStrictEqual',
14
+ 'throws',
15
+ 'doesNotThrow',
16
+ 'rejects',
17
+ 'doesNotReject',
18
+ 'match',
19
+ 'doesNotMatch',
20
+ 'ifError',
21
+ 'fail',
22
+ 'partialDeepStrictEqual',
23
+ 'done',
24
+ ]);
25
+
26
+ function isTestCall(node) {
27
+ if (!node || node.type !== 'CallExpression') return false;
28
+ if (node.callee.type === 'Identifier' && TEST_CALL_NAMES.has(node.callee.name)) {
29
+ return true;
30
+ }
31
+ if (
32
+ node.callee.type === 'MemberExpression' &&
33
+ node.callee.object.type === 'Identifier' &&
34
+ (TEST_CALL_NAMES.has(node.callee.object.name) || node.callee.object.name === 't') &&
35
+ node.callee.property.type === 'Identifier' &&
36
+ (node.callee.property.name === 'test' ||
37
+ node.callee.property.name === 'only' ||
38
+ node.callee.property.name === 'skip' ||
39
+ node.callee.property.name === 'todo')
40
+ ) {
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+
46
+ function isAssertionCall(node) {
47
+ if (!node || node.type !== 'CallExpression') return false;
48
+ const { callee } = node;
49
+ if (callee.type === 'Identifier') {
50
+ return callee.name === 'assert' || callee.name === 'expect';
51
+ }
52
+ if (callee.type === 'MemberExpression' && callee.property.type === 'Identifier') {
53
+ if (callee.object.type === 'Identifier' && (callee.object.name === 'assert' || callee.object.name === 'expect')) {
54
+ return true;
55
+ }
56
+ if (ASSERTION_METHODS.has(callee.property.name)) {
57
+ return true;
58
+ }
59
+ if (
60
+ callee.object.type === 'MemberExpression' &&
61
+ callee.object.property.type === 'Identifier' &&
62
+ callee.object.property.name === 'assert'
63
+ ) {
64
+ return true;
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+
70
+ function hasAssertionInNode(node, isRoot = false) {
71
+ if (!node || typeof node !== 'object') return false;
72
+ if (!isRoot && isTestCall(node)) return false;
73
+ if (isAssertionCall(node)) return true;
74
+
75
+ for (const [key, value] of Object.entries(node)) {
76
+ if (key === 'parent') continue;
77
+ if (Array.isArray(value)) {
78
+ for (const item of value) {
79
+ if (item && typeof item.type === 'string' && hasAssertionInNode(item, false)) {
80
+ return true;
81
+ }
82
+ }
83
+ } else if (value && typeof value.type === 'string') {
84
+ if (hasAssertionInNode(value, false)) return true;
85
+ }
86
+ }
87
+ return false;
88
+ }
89
+
90
+ const requireAssertionRule = {
91
+ meta: {
92
+ type: 'suggestion',
93
+ docs: {
94
+ description: 'Warn when a test case has no visible assertion call',
95
+ },
96
+ schema: [],
97
+ },
98
+ create(context) {
99
+ return {
100
+ CallExpression(node) {
101
+ if (!isTestCall(node)) return;
102
+ const fnArg = [...node.arguments]
103
+ .reverse()
104
+ .find((a) => a.type === 'ArrowFunctionExpression' || a.type === 'FunctionExpression');
105
+ if (!fnArg) return;
106
+ if (!hasAssertionInNode(fnArg.body, true)) {
107
+ context.report({
108
+ node,
109
+ message: 'Test case has no visible assertion; add an assert/expect call.',
110
+ });
111
+ }
112
+ },
113
+ };
114
+ },
115
+ };
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
+
160
+ export const agentpulseTestingPlugin = {
161
+ rules: {
162
+ 'require-assertion': requireAssertionRule,
163
+ 'no-repo-escape-import': noRepoEscapeImportRule,
164
+ },
165
+ };
166
+
167
+ export const testingConfig = [
168
+ {
169
+ name: '@agentpulselabs/eslint-config/testing',
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
+ ],
181
+ plugins: {
182
+ 'agentpulse-testing': agentpulseTestingPlugin,
183
+ },
184
+ rules: {
185
+ 'agentpulse-testing/require-assertion': 'warn',
186
+ 'agentpulse-testing/no-repo-escape-import': 'error',
187
+ 'no-restricted-imports': [
188
+ 'error',
189
+ {
190
+ paths: [
191
+ {
192
+ name: 'pg',
193
+ message: 'Do not import pg directly in app tests; use @agentpulselabs/test-kit/runAs (withRollbackTx) or test-kit stubs.',
194
+ },
195
+ ],
196
+ patterns: [
197
+ {
198
+ group: ['@agentpulse/platform/dal/*', '@agentpulse/platform/dal/**'],
199
+ message: 'Do not import private @agentpulse/platform/dal/* paths from app tests.',
200
+ },
201
+ ],
202
+ },
203
+ ],
204
+ 'no-restricted-syntax': [
205
+ 'error',
206
+ {
207
+ selector: "CallExpression[callee.object.name=/^(test|describe|it)$/][callee.property.name='only']",
208
+ message: 'Do not commit .only() in tests.',
209
+ },
210
+ {
211
+ selector: "CallExpression[callee.object.name=/^(test|describe|it)$/][callee.property.name=/^(skip|todo)$/]",
212
+ message: 'Do not use .skip() or .todo() without a reason string; use { skip: "reason" } or { todo: "reason" }.',
213
+ },
214
+ {
215
+ selector: "Property[key.name=/^(skip|todo)$/][value.value=true]",
216
+ message: 'skip/todo option requires a non-empty reason string instead of true.',
217
+ },
218
+ {
219
+ selector: "Property[key.name=/^(skip|todo)$/][value.value='']",
220
+ message: 'skip/todo reason string cannot be empty.',
221
+ },
222
+ {
223
+ selector: "Property[key.name='requireScope']",
224
+ message: 'Do not override requireScope in tests; @agentpulselabs/test-kit/register keeps scope checks real.',
225
+ },
226
+ {
227
+ selector: "VariableDeclarator[id.name='requireScope']",
228
+ message: 'Do not stub requireScope in tests; @agentpulselabs/test-kit/register keeps scope checks real.',
229
+ },
230
+ {
231
+ selector: "CallExpression[callee.name='register']",
232
+ message: 'Do not call custom node:module register() loaders in app tests; use @agentpulselabs/test-kit/register.',
233
+ },
234
+ ],
235
+ },
236
+ },
237
+ ];
238
+
239
+ export default testingConfig;