Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: reduce inspection depth default to five #23350

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ stream.write('With ES6');
added: v0.3.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/22846
description: The `depth` default changed to `20`.
pr-url: https://github.com/nodejs/node/pull/23350
description: The `depth` default changed to `5`.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/22788
description: The `sorted` option is supported now.
Expand Down Expand Up @@ -408,7 +408,7 @@ changes:
* `depth` {number} Specifies the number of times to recurse while formatting
the `object`. This is useful for inspecting large complicated objects. To
make it recurse up to the maximum call stack size pass `Infinity` or `null`.
**Default:** `20`.
**Default:** `5`.
* `colors` {boolean} If `true`, the output will be styled with ANSI color
codes. Colors are customizable, see [Customizing `util.inspect` colors][].
**Default:** `false`.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);

const inspectDefaultOptions = Object.seal({
showHidden: false,
depth: 20,
depth: 5,
colors: false,
customInspect: true,
showProxy: false,
Expand Down
8 changes: 1 addition & 7 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1565,15 +1565,9 @@ util.inspect(process);
head = head.next = {};
}

const res = Array(15)
.fill(0)
.map((_, i) => `{ next:\n${' '.repeat(i + 1)}`)
.join('') +
'{ next: { next: { next: { next: { next: { next:' +
' [Object] } } } } } } } } } } } } } } } } } } } } }';
assert.strictEqual(
util.inspect(list),
res
'{ next: { next: { next: { next: { next: { next: [Object] } } } } } }'
);
const longList = util.inspect(list, { depth: Infinity });
const match = longList.match(/next/g);
Expand Down