feat(eslint): add no-object-keys-length rule with auto-fix#7691
feat(eslint): add no-object-keys-length rule with auto-fix#7691
Conversation
Add an ESLint rule that flags `Object.keys(x).length` emptiness checks and auto-fixes them to use a shared `isEmptyObject()` utility that avoids allocating an intermediate array. - Add `isEmptyObject` utility in `datadog-core/src/utils/src/` - ESLint rule with `fixable: 'code'` auto-fix support - Auto-fix computes correct relative require paths - Auto-fix handles 'use strict' and top-level require placement - Fix all existing violations across packages Co-Authored-By: Claude Opus 4.6 <[email protected]>
Overall package sizeSelf size: 4.93 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 |
Extend computeRequirePath to handle files outside the packages/ directory by falling back to context.cwd for the repo root. Remove all eslint-disable comments and auto-fix the remaining violations in integration-tests/, test/, and scripts/. Co-Authored-By: Claude Opus 4.6 <[email protected]>
BenchmarksBenchmark execution time: 2026-03-06 00:41:50 Comparing candidate commit 9deba25 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 233 metrics, 27 unstable metrics. |
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]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #7691 +/- ##
==========================================
+ Coverage 80.31% 80.32% +0.01%
==========================================
Files 739 740 +1
Lines 31946 31969 +23
==========================================
+ Hits 25657 25680 +23
Misses 6289 6289
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:
|
BridgeAR
left a comment
There was a problem hiding this comment.
This sadly does not really address the problem in a way that I would expect.
In most cases, we can prevent using Object.keys(). That would be a good goal, it is just not possible to create a lint rule for that.
This just replaces these with another notation that is slower in my local benchmarks.
Summary
isEmptyObject()utility inpackages/datadog-core/src/utils/src/is-empty-object.jsthat checks emptiness without allocating an intermediate array (usesfor...inwithObject.hasOwnguard)eslint-no-object-keys-length) that flagsObject.keys(x).lengthemptiness checks and auto-fixes them to useisEmptyObject()'use strict'placement, and only inserts at module-level scopeMotivation
Object.keys(obj).length === 0allocates an intermediate array just to check if an object is empty. In a tracer that runs in application hot paths, this is unnecessary overhead. TheisEmptyObject()utility performs the same check with zero allocations.ESLint rule features
=== 0,!== 0,== 0,!= 0,> 0,< 1,!Object.keys(x).length, and truthy checks inif/ternary/logical expressionsObject.values()andObject.entries()patternsObject.keys(x).length >= 10or=== 3require('..../is-empty-object')at the correct module-level positionTest plan
npm run lintpasses (only pre-existingoxc-parsererror remains)'use strict'ordering is preserved after auto-fix🤖 Generated with Claude Code