util: honor breakLength: Infinity with deep objects in inspect - #66471
RohithPariki wants to merge 1 commit into
Conversation
When inspecting deeply nested objects with breakLength: Infinity and depth: Infinity (or depth: null), reduceToSingleString() was previously skipping inline consolidation because currentDepth exceeded compact (default 3), causing unexpected newlines. Allow single-line consolidation when breakLength is Infinity and depth is unlimited, while preserving compact array grouping. Fixes: nodejs#60475 Signed-off-by: Rohith Pariki <rohithpariki@gmail.com>
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. Caution AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context. |
|
The recommendations in: advise you should tackle only one issue at a time and that you should not open any new PRs until your first PR has been approved. This is for your benefit and for the benefit of the team assisting with PRs. In both PRs the commit messages are incorrectly formatted, so it makes double the amount of work to advise you to correct the mistake in 2 different places. You have later also opened #66472. |
|
See Commit message guidelines according to the Pull requests documentation. Please correct the problem with the text width. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66471 +/- ##
==========================================
- Coverage 90.42% 90.41% -0.01%
==========================================
Files 791 791
Lines 275569 275571 +2
Branches 52842 52842
==========================================
- Hits 249185 249161 -24
- Misses 16802 16806 +4
- Partials 9582 9604 +22
🚀 New features to boost your workflow:
|
Problem
When using
util.inspect(obj, { breakLength: Infinity, depth: Infinity })(ordepth: null), deeply nested objects are unexpectedly split across multiple lines instead of being formatted on a single line. The Node.js documentation states:Root Cause
In
reduceToSingleString()(lib/internal/util/inspect.js):When inspecting an object with unlimited depth (
depth: Infinityordepth: null),ctx.currentDepthincrements as depth increases. Sincecompactdefaults to 3,ctx.currentDepth - recurseTimes < ctx.compactfails for all parent/outer levels beyond depth 2. As a result, inline consolidation is skipped and newlines are inserted, despitebreakLength: Infinity.A previous closed attempt (#60783) disabled
groupArrayElementswhenbreakLength === Infinity, which broke compact array grouping withcompact: 1.Solution
In
reduceToSingleString(), permit inline single-line consolidation whenbreakLength === Infinityand depth is unlimited (ctx.depth === null || ctx.depth === Infinity):This preserves array element grouping under
compact: 1and line wrapping for finitebreakLength, while honoring the documented single-line contract for deep objects.Testing
test/parallel/test-util-inspect.jscoveringbreakLength: Infinitywithdepth: Infinityanddepth: nullfor deeply nested objects.compact: 1), normal wrapping with finitebreakLength, and default inspection behavior.Fixes: #60475