chore(eslint): add require export consistency rule#7543
chore(eslint): add require export consistency rule#7543
Conversation
Overall package sizeSelf size: 4.62 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.6 | 81.92 kB | 813.08 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7543 +/- ##
==========================================
- Coverage 80.16% 80.15% -0.01%
==========================================
Files 730 730
Lines 31217 31217
==========================================
- Hits 25024 25023 -1
- Misses 6193 6194 +1 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🔗 Commit SHA: eeb6354 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
BenchmarksBenchmark execution time: 2026-02-16 16:44:25 Comparing candidate commit eeb6354 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 230 metrics, 30 unstable metrics. |
Add a custom `eslint` rule that validates destructured CommonJS `require()` access against statically discoverable first-party exports. Support common CJS export patterns and JSON top-level keys, and skip dynamic/unknown export shapes to keep the rule conservative and avoid false positives. Wire the rule into `eslint.config.mjs` and add fixture-based `RuleTester` coverage for valid, invalid, and skip scenarios.
Move the eslint-rules plugin and eslint-require-export-exists from dd-trace/src/all into dd-trace/defaults so the rule runs project-wide instead of only under packages/dd-trace/src.
d49f247 to
f73d4ce
Compare

What does this PR do?
Adds a new custom ESLint rule,
eslint-rules/eslint-require-export-exists, that validates destructured CommonJSrequire()usage against statically discoverable exports for first-party modules. The rule is enabled ineslint.config.mjsand now helps catch typos/mismatches likeconst { missingKey } = require('./module')before runtime.The rule is intentionally scoped and conservative:
const { foo } = require('./mod')), not namespace member access..jsonmodules (top-level keys are treated as available properties).Motivation
We want earlier feedback when destructuring from
require()so export mismatches are caught during linting instead of failing later at runtime. This keeps CommonJS module usage safer and more consistent across the codebase while staying conservative to avoid noisy false positives.