Skip to content

feat(eslint): add no-does-not-throw rule with auto-fix#7692

Merged
BridgeAR merged 5 commits intomasterfrom
brian.marks/eslint-no-does-not-throw
Mar 6, 2026
Merged

feat(eslint): add no-does-not-throw rule with auto-fix#7692
BridgeAR merged 5 commits intomasterfrom
brian.marks/eslint-no-does-not-throw

Conversation

@bm1549
Copy link
Copy Markdown
Contributor

@bm1549 bm1549 commented Mar 5, 2026

Summary

  • Enforces the project convention of not using assert.doesNotThrow() in test files (per CLAUDE.md)
  • Uses the built-in ESLint no-restricted-syntax rule with an AST selector — no custom rule needed
  • Fixed all ~50 existing violations across 25 test files (callback bodies extracted and called directly)
  • Cascading cleanups: removed 3 now-unused assert imports, converted 2 letconst

Fix patterns applied

Before After
assert.doesNotThrow(() => expr) expr
assert.doesNotThrow(() => { stmt1; stmt2 }) stmt1
stmt2
assert.doesNotThrow(fn) fn()
assert.doesNotThrow(obj.method) obj.method()

Test plan

  • npm run lint passes clean
  • Verified all 25 fixed test files have semantically equivalent transformations
  • Verified cascading cleanups are correct (unused imports, let→const)

🤖 Generated with Claude Code

Add an ESLint rule that bans `assert.doesNotThrow()` in test files and
auto-fixes violations by extracting the callback body directly.

Per CLAUDE.md: "Never use the doesNotThrow() assertion. Instead,
execute the method directly — if it throws, the test will fail."

Auto-fix handles:
- Arrow with expression body: assert.doesNotThrow(() => expr) → expr
- Arrow/function with block body: extracts statements
- Function reference: assert.doesNotThrow(fn) → fn()
- Destructured doesNotThrow from require('assert')

Fixes all ~50 existing violations across 25 test files, including
cascading cleanups (unused assert imports, let→const).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@bm1549 bm1549 added semver-patch AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos labels Mar 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

Overall package size

Self size: 4.93 MB
Deduped: 5.77 MB
No deduping: 5.77 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

bm1549 added a commit that referenced this pull request Mar 5, 2026
Add ESLint rules and a CI check based on recurring PR review themes:

1. eslint-no-structured-clone: bans structuredClone() in production
   code (not available in all supported Node.js versions)

2. eslint-prefer-assert-object-contains: detects 3+ consecutive
   assert.strictEqual calls on the same object and suggests using
   assertObjectContains instead (currently off, 143 violations)

3. check-config-completeness: validates that all DD_/OTEL_ env vars
   in config/index.js are registered in supported-configurations.json

Note: eslint-no-object-keys-length and eslint-no-does-not-throw have
been split into separate PRs (#7691 and #7692) with auto-fix support.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 5, 2026

Benchmarks

Benchmark execution time: 2026-03-06 17:39:09

Comparing candidate commit 530fc69 in PR branch brian.marks/eslint-no-does-not-throw with baseline commit b6f7a69 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 231 metrics, 29 unstable metrics.

@bm1549 bm1549 requested a review from a team March 5, 2026 23:08
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.32%. Comparing base (b6f7a69) to head (530fc69).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7692   +/-   ##
=======================================
  Coverage   80.31%   80.32%           
=======================================
  Files         739      739           
  Lines       31946    31960   +14     
=======================================
+ Hits        25657    25671   +14     
  Misses       6289     6289           
Flag Coverage Δ
aiguard-macos 38.96% <ø> (-0.04%) ⬇️
aiguard-ubuntu 39.08% <ø> (-0.04%) ⬇️
aiguard-windows 38.81% <ø> (-0.04%) ⬇️
apm-capabilities-tracing-macos 48.78% <ø> (+0.05%) ⬆️
apm-capabilities-tracing-ubuntu 48.82% <ø> (+0.01%) ⬆️
apm-capabilities-tracing-windows 47.76% <ø> (-0.78%) ⬇️
apm-integrations-child-process 38.52% <ø> (-0.06%) ⬇️
apm-integrations-couchbase-18 37.43% <ø> (+0.06%) ⬆️
apm-integrations-couchbase-eol 37.90% <ø> (+0.06%) ⬆️
apm-integrations-oracledb 37.73% <ø> (-0.08%) ⬇️
appsec-express 55.31% <ø> (-0.07%) ⬇️
appsec-fastify 51.63% <ø> (-0.07%) ⬇️
appsec-graphql 51.82% <ø> (-0.07%) ⬇️
appsec-kafka 44.39% <ø> (+<0.01%) ⬆️
appsec-ldapjs 44.01% <ø> (-0.08%) ⬇️
appsec-lodash 43.66% <ø> (-0.07%) ⬇️
appsec-macos 58.32% <ø> (-0.05%) ⬇️
appsec-mongodb-core 48.81% <ø> (-0.08%) ⬇️
appsec-mongoose 49.49% <ø> (-0.07%) ⬇️
appsec-mysql 50.87% <ø> (-0.05%) ⬇️
appsec-node-serialize 43.18% <ø> (-0.07%) ⬇️
appsec-passport 47.62% <ø> (-0.08%) ⬇️
appsec-postgres 50.63% <ø> (-0.05%) ⬇️
appsec-sourcing 42.58% <ø> (-0.07%) ⬇️
appsec-template 43.35% <ø> (-0.07%) ⬇️
appsec-ubuntu 58.40% <ø> (-0.05%) ⬇️
appsec-windows 58.18% <ø> (-0.05%) ⬇️
instrumentations-instrumentation-bluebird 32.31% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-body-parser 40.47% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-child_process 37.82% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-cookie-parser 34.31% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-express 34.63% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.44% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-express-session 40.10% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-fs 31.93% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-generic-pool 29.70% <ø> (ø)
instrumentations-instrumentation-http 39.82% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-knex 32.32% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-mongoose 33.45% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-multer 40.21% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-mysql2 38.29% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-passport 43.99% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-passport-http 43.66% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-passport-local 44.20% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-pg 37.72% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-promise 32.24% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-promise-js 32.25% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-q 32.29% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-url 32.21% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-when 32.26% <ø> (-0.08%) ⬇️
llmobs-ai 42.11% <ø> (-0.08%) ⬇️
llmobs-anthropic 40.28% <ø> (-0.08%) ⬇️
llmobs-bedrock 39.24% <ø> (-0.07%) ⬇️
llmobs-google-genai 39.81% <ø> (-0.08%) ⬇️
llmobs-langchain 39.88% <ø> (-0.07%) ⬇️
llmobs-openai 44.11% <ø> (-0.08%) ⬇️
llmobs-vertex-ai 40.00% <ø> (-0.15%) ⬇️
platform-core 31.53% <ø> (ø)
platform-esbuild 34.48% <ø> (ø)
platform-instrumentations-misc 45.53% <ø> (ø)
platform-shimmer 37.63% <ø> (ø)
platform-unit-guardrails 32.95% <ø> (ø)
plugins-azure-event-hubs 25.83% <ø> (ø)
plugins-azure-service-bus 25.19% <ø> (ø)
plugins-bullmq 44.01% <ø> (+0.02%) ⬆️
plugins-cassandra 37.77% <ø> (-0.08%) ⬇️
plugins-cookie 26.89% <ø> (ø)
plugins-cookie-parser 26.67% <ø> (ø)
plugins-crypto 26.79% <ø> (ø)
plugins-dd-trace-api 38.35% <ø> (-0.09%) ⬇️
plugins-express-mongo-sanitize 26.82% <ø> (ø)
plugins-express-session 26.63% <ø> (ø)
plugins-fastify 42.21% <ø> (-0.08%) ⬇️
plugins-fetch 38.34% <ø> (-0.05%) ⬇️
plugins-fs 38.63% <ø> (-0.06%) ⬇️
plugins-generic-pool 25.87% <ø> (ø)
plugins-google-cloud-pubsub 45.36% <ø> (-0.08%) ⬇️
plugins-grpc 40.92% <ø> (-0.08%) ⬇️
plugins-handlebars 26.86% <ø> (ø)
plugins-hapi 40.11% <ø> (-0.08%) ⬇️
plugins-hono 40.37% <ø> (-0.08%) ⬇️
plugins-ioredis 38.43% <ø> (-0.06%) ⬇️
plugins-knex 26.50% <ø> (ø)
plugins-ldapjs 24.36% <ø> (ø)
plugins-light-my-request 26.23% <ø> (ø)
plugins-limitd-client 32.60% <ø> (-0.08%) ⬇️
plugins-lodash 25.96% <ø> (ø)
plugins-mariadb 39.49% <ø> (-0.06%) ⬇️
plugins-memcached 38.15% <ø> (-0.09%) ⬇️
plugins-microgateway-core 39.15% <ø> (-0.08%) ⬇️
plugins-moleculer 40.51% <ø> (-0.05%) ⬇️
plugins-mongodb 39.18% <ø> (-0.08%) ⬇️
plugins-mongodb-core 39.01% <ø> (-0.08%) ⬇️
plugins-mongoose 38.86% <ø> (-0.05%) ⬇️
plugins-multer 26.63% <ø> (ø)
plugins-mysql 39.18% <ø> (-0.06%) ⬇️
plugins-mysql2 39.27% <ø> (-0.03%) ⬇️
plugins-node-serialize 26.93% <ø> (ø)
plugins-opensearch 37.61% <ø> (-0.08%) ⬇️
plugins-passport-http 26.68% <ø> (ø)
plugins-postgres 35.71% <ø> (-0.07%) ⬇️
plugins-process 26.79% <ø> (ø)
plugins-pug 26.89% <ø> (ø)
plugins-redis 38.90% <ø> (-0.06%) ⬇️
plugins-router 43.07% <ø> (-0.09%) ⬇️
plugins-sequelize 25.47% <ø> (ø)
plugins-test-and-upstream-amqp10 38.33% <ø> (-0.23%) ⬇️
plugins-test-and-upstream-amqplib 43.82% <ø> (-0.06%) ⬇️
plugins-test-and-upstream-apollo 39.01% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-avsc 38.69% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-bunyan 33.88% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-connect 40.76% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-graphql 40.14% <ø> (-0.06%) ⬇️
plugins-test-and-upstream-koa 40.35% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-protobufjs 38.91% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-rhea 43.98% <ø> (-0.09%) ⬇️
plugins-undici 39.12% <ø> (-0.05%) ⬇️
plugins-url 26.79% <ø> (ø)
plugins-valkey 38.07% <ø> (-0.09%) ⬇️
plugins-vm 26.79% <ø> (ø)
plugins-winston 34.07% <ø> (-0.08%) ⬇️
plugins-ws 41.88% <ø> (-0.06%) ⬇️
profiling-macos 39.81% <ø> (-0.09%) ⬇️
profiling-ubuntu 39.94% <ø> (-0.09%) ⬇️
profiling-windows 41.14% <ø> (-0.08%) ⬇️
serverless-azure-functions-client 25.54% <ø> (ø)
serverless-azure-functions-eventhubs 25.54% <ø> (ø)
serverless-azure-functions-servicebus 25.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, while we can replace the custom rule with no-restricted-syntax:

{
  selector: "CallExpression:matches([callee.name='doesNotThrow'], [callee.property.name='doesNotThrow'])",
  message: 'Do not use `assert.doesNotThrow()`. Write the code without the wrapper and add a comment instead.',
}

@bm1549 bm1549 requested a review from BridgeAR March 6, 2026 15:52
@bm1549 bm1549 marked this pull request as ready for review March 6, 2026 15:52
@bm1549 bm1549 requested review from a team as code owners March 6, 2026 15:52
BridgeAR
BridgeAR previously approved these changes Mar 6, 2026
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just left a independent of the change suggestion

BridgeAR
BridgeAR previously approved these changes Mar 6, 2026
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM

One last nit: the CLAUDE.md could be changed to remove this now.

@BridgeAR BridgeAR enabled auto-merge (squash) March 6, 2026 16:50
bm1549 and others added 4 commits March 6, 2026 12:32
…icted-syntax

Simplifies the implementation by using the built-in ESLint
no-restricted-syntax rule with an AST selector, per BridgeAR's
review suggestion. The ~50 existing violations were already fixed
in the previous commits, so the custom auto-fix machinery is no
longer needed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The no-restricted-syntax ESLint rule now statically enforces this
convention, making the manual instruction in AGENTS.md redundant.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@bm1549 bm1549 force-pushed the brian.marks/eslint-no-does-not-throw branch from 85bbc95 to 530fc69 Compare March 6, 2026 17:32
@datadog-official
Copy link
Copy Markdown

datadog-official bot commented Mar 6, 2026

⚠️ Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

🧪 1 Test failed

AIGuard SDK "before each" hook for "test evaluate 'tool call' with ALLOW action (blocking: true)" from AIGuard SDK (Datadog) (Fix with Cursor)
Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/runner/work/dd-trace-js/dd-trace-js/packages/dd-trace/test/aiguard/index.spec.js)

Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/runner/work/dd-trace-js/dd-trace-js/packages/dd-trace/test/aiguard/index.spec.js)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)

ℹ️ Info

❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 530fc69 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@BridgeAR BridgeAR merged commit 9f2cfb6 into master Mar 6, 2026
826 of 833 checks passed
@BridgeAR BridgeAR deleted the brian.marks/eslint-no-does-not-throw branch March 6, 2026 18:01
dd-octo-sts bot pushed a commit that referenced this pull request Mar 7, 2026
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]>
@atlassian atlassian bot mentioned this pull request Mar 7, 2026
juan-fernandez pushed a commit that referenced this pull request Mar 10, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos semver-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants