Skip to content

Commit 9f2cfb6

Browse files
bm1549claudeBridgeAR
authored
chore(eslint): add no-does-not-throw rule (#7692)
Add an ESLint rule that bans `assert.doesNotThrow()` in test files. All entries where it was used are fixed and CLAUDE.md is adjusted, since the comment is not needed anymore. --------- Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Ruben Bridgewater <[email protected]>
1 parent c20c352 commit 9f2cfb6

File tree

29 files changed

+70
-103
lines changed

29 files changed

+70
-103
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210

211211
# Language Platform
212212
/* @DataDog/lang-platform-js
213+
/eslint-rules/ @DataDog/lang-platform-js
213214

214215
/integration-tests/bun/ @DataDog/lang-platform-js
215216
/integration-tests/init.spec.js @DataDog/lang-platform-js

AGENTS.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ Use `node:assert/strict` for standard assertions. For partial deep object checks
115115

116116
Favor fewer `assert.deepStrictEqual`/`assertObjectContains` calls over many `assert.strictEqual` calls. Combine existing calls, when touching test files.
117117

118-
Never use the `doesNotThrow()` assertion. Instead, execute the method directly.
119-
120118
### Time-Based Testing
121119

122120
**Never rely on actual time passing in unit tests.** Use sinon's fake timers to mock time and make tests deterministic and fast.

eslint.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ export default [
647647
'mocha',
648648
],
649649
}],
650+
'no-restricted-syntax': ['error', {
651+
selector: "CallExpression:matches([callee.name='doesNotThrow'], [callee.property.name='doesNotThrow'])",
652+
message: 'Do not use `assert.doesNotThrow()`. Execute the expression directly instead.',
653+
}],
650654
'n/no-missing-require': 'off',
651655
'require-await': 'off',
652656
},

packages/datadog-instrumentations/test/express.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ withVersions('express', 'express', version => {
7979
// Router does not exist in Express 5
8080
it('should work correctly when router[method] is called without handler', () => {
8181
const router = express.Router()
82-
assert.doesNotThrow(() => { router.bind('/test') })
82+
router.bind('/test')
8383
})
8484
}
8585
})

packages/datadog-plugin-elasticsearch/test/index.spec.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,7 @@ describe('Plugin', () => {
241241
})
242242

243243
it('should support aborting the query', () => {
244-
assert.doesNotThrow(() => {
245-
client.ping(() => {}).abort()
246-
})
244+
client.ping(() => {}).abort()
247245
})
248246
})
249247
}
@@ -305,13 +303,10 @@ describe('Plugin', () => {
305303
})
306304

307305
it('should support aborting the query', () => {
308-
assert.doesNotThrow(() => {
309-
const promise = client.ping()
310-
311-
if (promise.abort) {
312-
promise.abort()
313-
}
314-
})
306+
const promise = client.ping()
307+
if (promise.abort) {
308+
promise.abort()
309+
}
315310
})
316311

317312
it('should work with userland promises', done => {

packages/datadog-plugin-graphql/test/index.spec.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,8 @@ describe('Plugin', () => {
11551155
it('should support multiple executions on a pre-parsed document', () => {
11561156
const source = 'query MyQuery { hello(name: "world") }'
11571157
const document = graphql.parse(source)
1158-
assert.doesNotThrow(() => {
1159-
graphql.execute({ schema, document })
1160-
graphql.execute({ schema, document })
1161-
})
1158+
graphql.execute({ schema, document })
1159+
graphql.execute({ schema, document })
11621160
})
11631161

11641162
it('should not fail without directives in the document ' +
@@ -1172,9 +1170,7 @@ describe('Plugin', () => {
11721170
dc.channel('datadog:graphql:resolver:start').subscribe(noop)
11731171

11741172
try {
1175-
assert.doesNotThrow(() => {
1176-
graphql.execute({ schema, document })
1177-
})
1173+
graphql.execute({ schema, document })
11781174
} finally {
11791175
dc.channel('datadog:graphql:resolver:start').unsubscribe(noop)
11801176
}
@@ -1184,10 +1180,8 @@ describe('Plugin', () => {
11841180
const source = 'query MyQuery { hello(name: "world") }'
11851181
const document = graphql.parse(source)
11861182

1187-
assert.doesNotThrow(() => {
1188-
graphql.validate(schema, document)
1189-
graphql.validate(schema, document)
1190-
})
1183+
graphql.validate(schema, document)
1184+
graphql.validate(schema, document)
11911185
})
11921186

11931187
it('should support multi-operations documents', done => {

packages/datadog-plugin-http/test/server.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ describe('Plugin', () => {
193193
const req = new IncomingMessage()
194194
const res = new ServerResponse(req)
195195

196-
assert.doesNotThrow(() => res.emit('finish'))
196+
res.emit('finish')
197197
})
198198

199199
it('should not cause `end` to be called multiple times', done => {

packages/datadog-plugin-opensearch/test/index.spec.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,10 @@ describe('Plugin', () => {
191191
})
192192

193193
it('should support aborting the query', () => {
194-
assert.doesNotThrow(() => {
195-
const promise = client.ping()
196-
197-
if (promise.abort) {
198-
promise.abort()
199-
}
200-
})
194+
const promise = client.ping()
195+
if (promise.abort) {
196+
promise.abort()
197+
}
201198
})
202199

203200
it('should work with userland promises', done => {

packages/datadog-plugin-winston/test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ describe('Plugin', () => {
295295
}
296296

297297
it('should skip injection without a store', async () => {
298-
assert.doesNotThrow(() => winston.info('message'))
298+
winston.info('message')
299299
})
300300
})
301301

packages/datadog-plugin-ws/test/index.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ describe('Plugin', () => {
150150
done()
151151
})
152152

153-
assert.doesNotThrow(() => {
154-
client.off('message', neverAddedHandler)
155-
})
153+
client.off('message', neverAddedHandler)
156154
})
157155

158156
it('should do automatic instrumentation for server connections', done => {

0 commit comments

Comments
 (0)