GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: add util.inspect compact option by BridgeAR · Pull Request #17576 · nodejs/node

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Dec 9, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I personally really dislike the formatting used in util.inspect and this should
improve the situation a lot. I am also working on a feature that requires a
more structural util.inspect output. In general, I do not argue about it being
perfect, so if anyone has some further input, I am all ears.

commit - util: add util.inspect structured option

The current default formatting is not ideal and this improves
the situation by formatting the output more intuitiv.

1) All object keys are now indented by 2 characters instead of
   something 2 and sometimes 3 characters.
2) Each object key will now use a individual line instead of
   sharing a line potentially with multiple object keys.
3) Long strings will now be split into multiple lines in case
   they exceed the "lineBreak" option length (including the
   current indentation).
4) Opening braces are now directly behind a object property
   instead of using a new line.

commit - util: rename util.inspect argument

util.inspect can actually receive any property and the description
was wrong so far. This fixes it by renaming the argument to
value and also updating the description.

commit - util: fix custom inspect description

Using a custom inspect function on the inspected object is
deprecated. Remove the reference from the option description
to make sure the user will read about the deprecation in the
more detailed description.

CI https://ci.nodejs.org/job/node-test-pull-request/12008/

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

util

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Dec 9, 2017
@BridgeAR
BridgeAR force-pushed the util-structured branch 2 times, most recently from 8c65749 to b44a6f8 Compare December 9, 2017 17:55
@BridgeAR

BridgeAR commented Dec 9, 2017

Copy link
Copy Markdown
Member Author

I pushed another commit that changes the base order of the inspected object.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR added the semver-minor PRs that contain new features and should be released in the next minor version. label Dec 10, 2017
@BridgeAR BridgeAR mentioned this pull request Dec 10, 2017
doc: clarify util.inspect usage intent #17375
Closed
2 tasks done
@Trott

Trott commented Dec 10, 2017

Copy link
Copy Markdown
Member

Two small typos in the first commit message: something 2 -> sometimes 2 and a individual -> an individual. I normally don't flag typos in commit messages but that first one had me puzzled for a few moments longer than I want to admit.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR added 4 commits December 10, 2017 18:15
@BridgeAR
util: add util.inspect structured option
d76d28d
The current default formatting is not ideal and this improves
the situation by formatting the output more intuitiv.

1) All object keys are now indented by 2 characters instead of
   sometimes 2 and sometimes 3 characters.
2) Each object key will now use an individual line instead of
   sharing a line potentially with multiple object keys.
3) Long strings will now be split into multiple lines in case
   they exceed the "lineBreak" option length (including the
   current indentation).
4) Opening braces are now directly behind a object property
   instead of using a new line.
@BridgeAR
util: rename util.inspect argument
ecf019e
util.inspect can actually receive any property and the description
was wrong so far. This fixes it by renaming the argument to
value and also updating the description.
@BridgeAR
util: fix custom inspect description
843a5d5
Using a custom inspect function on the inspected object is
deprecated. Remove the reference from the option description
to make sure the user will read about the deprecation in the
more detailed description.
@BridgeAR
util: switch inspect "base" order
cd5be74
In case the structured option is used, it will now print

  "[Function: foo] {\n  property: 'data'\n}"

instead of

  "{ [Function: foo]\n  property: 'data'\n}"
@BridgeAR
BridgeAR force-pushed the util-structured branch from 0f8cae2 to cd5be74 Compare December 10, 2017 20:15
@BridgeAR

BridgeAR commented Dec 10, 2017

Copy link
Copy Markdown
Member Author

I updated the commit message accordingly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR mentioned this pull request Dec 11, 2017
assert: add error diffs #17615
Closed
4 tasks done
@addaleax

addaleax commented Dec 11, 2017

Copy link
Copy Markdown
Member

@BridgeAR I’m a fan of this feature, but not so sure about the name – “structured” doesn’t say that much, I think… it’s hard to come up with something better. I’ve thought about “long”, which also seems to have potential for confusion but is more to the point, I think. Maybe onePropertyPerLine? It’s verbose but very unambiguous.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Dec 11, 2017

Copy link
Copy Markdown
Member Author

@addaleax yeah, the name is probably not ideal. What do you think about beautify? 😄
I am not a fan of very long option names and onePropertyPerLine would actually not describe everything that is changed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Dec 11, 2017

Copy link
Copy Markdown
Member

@BridgeAR Me neither, but I’d rather have something that actually tells you what’s happening

And beauty is definitely in the eye of the beholder ;)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Dec 11, 2017

Copy link
Copy Markdown
Member

Maybe make an option called compact and have it default to true? Then, if you want this feature (what is called structured in this PR currently), set compact to false?

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Dec 11, 2017

Copy link
Copy Markdown
Member Author

@Trott that would also work but it somehow sounds "less good". And I personally prefer the new formatting a lot over the current one. If it is abot me I would just replace it ^^. But even though the output is considered to be changed from time to time, I guess that would be to harsh.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Dec 11, 2017

Copy link
Copy Markdown
Member

@BridgeAR OK, but I do think we need a better term than structured. I gave my suggestion. :-D

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Dec 12, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

So I thought about it again and what do you think about readerFriendly?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Dec 12, 2017

Copy link
Copy Markdown
Member

I think readerFriendly doesn’t say anything about the format, and is pretty subjective?

I actually like compact.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Dec 12, 2017

Copy link
Copy Markdown
Member Author

I agree that compact itself sounds nice but that is exactly the problem I have with it. Because compact = false sounds like you deactivate something positive. Otherwise I would would have already changed the name to it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell reviewed Dec 12, 2017
View reviewed changes
Comment thread test/parallel/test-util-inspect.js
'NotStringClass {}');
}

{

@jasnell jasnell Dec 12, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It looks like none of the examples here test objects with a custom inspect method. Can you add some coverage in for that?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Dec 17, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR BridgeAR added the notable-change PRs with changes that should be highlighted in changelogs. label Dec 15, 2017
BridgeAR added 2 commits December 17, 2017 03:02
@BridgeAR
squash - change to "compact", add more tests, fix \n issue
e2792d5
@BridgeAR
squash - add another test
e31fd8a
@BridgeAR

BridgeAR commented Dec 17, 2017

Copy link
Copy Markdown
Member Author

I changed the name to compact and I also updated the RegExp to handle line breaks better.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax
addaleax approved these changes Dec 17, 2017
View reviewed changes
Comment thread lib/util.js Outdated
const averageLineLength = Math.ceil(value.length / Math.ceil(value.length / minLineLength));
const divisor = Math.max(averageLineLength, MIN_LINE_LENGTH);
var res = '';
if (readableRegExps[divisor] === undefined)

@addaleax addaleax Dec 17, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you add {} for multi-line if bodies? :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Dec 17, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR
squash - address comment
684b992
@BridgeAR BridgeAR closed this Dec 21, 2017
@addaleax addaleax removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Dec 29, 2017
@MylesBorins MylesBorins added the backport-requested-v9.x label Jan 9, 2018
@MylesBorins

MylesBorins commented Jan 9, 2018

Copy link
Copy Markdown
Contributor

This does not land cleanly on v9.x. Would someone be willing to backport?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR added a commit to BridgeAR/node that referenced this pull request Mar 8, 2018
@BridgeAR
util: fix custom inspect description
5d88557
Using a custom inspect function on the inspected object is
deprecated. Remove the reference from the option description
to make sure the user will read about the deprecation in the
more detailed description.

PR-URL: nodejs#17576
Reviewed-By: Anna Henningsen <[email protected]>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Mar 8, 2018
@BridgeAR
util: rename util.inspect argument
f77f91d
util.inspect can actually receive any property and the description
was wrong so far. This fixes it by renaming the argument to
value and also updating the description.

PR-URL: nodejs#17576
Reviewed-By: Anna Henningsen <[email protected]>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Mar 8, 2018
@BridgeAR
util: add util.inspect compact option
fb85597
The current default formatting is not ideal and this improves
the situation by formatting the output more intuitiv.

1) All object keys are now indented by 2 characters instead of
   sometimes 2 and sometimes 3 characters.
2) Each object key will now use an individual line instead of
   sharing a line potentially with multiple object keys.
3) Long strings will now be split into multiple lines in case
   they exceed the "lineBreak" option length (including the
   current indentation).
4) Opening braces are now directly behind a object property
   instead of using a new line.
5) Switch inspect "base" order. In case the compact option is set
   to `false`, inspect will now print
     "[Function: foo] {\n  property: 'data'\n}"
   instead of
     "{ [Function: foo]\n  property: 'data'\n}".

PR-URL: nodejs#17576
Reviewed-By: Anna Henningsen <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Mar 8, 2018
[9.x backport] assert & util PRs #19230
Closed
4 tasks done
@BridgeAR

BridgeAR commented Mar 8, 2018

Copy link
Copy Markdown
Member Author

Backport opened in #19230

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

MylesBorins pushed a commit that referenced this pull request Mar 15, 2018
@BridgeAR @MylesBorins
util: fix custom inspect description
08d7378
Using a custom inspect function on the inspected object is
deprecated. Remove the reference from the option description
to make sure the user will read about the deprecation in the
more detailed description.

Backport-PR-URL: #19230
PR-URL: #17576
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 15, 2018
@BridgeAR @MylesBorins
util: rename util.inspect argument
527081f
util.inspect can actually receive any property and the description
was wrong so far. This fixes it by renaming the argument to
value and also updating the description.

Backport-PR-URL: #19230
PR-URL: #17576
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 15, 2018
@BridgeAR @MylesBorins
util: add util.inspect compact option
16843a2
The current default formatting is not ideal and this improves
the situation by formatting the output more intuitiv.

1) All object keys are now indented by 2 characters instead of
   sometimes 2 and sometimes 3 characters.
2) Each object key will now use an individual line instead of
   sharing a line potentially with multiple object keys.
3) Long strings will now be split into multiple lines in case
   they exceed the "lineBreak" option length (including the
   current indentation).
4) Opening braces are now directly behind a object property
   instead of using a new line.
5) Switch inspect "base" order. In case the compact option is set
   to `false`, inspect will now print
     "[Function: foo] {\n  property: 'data'\n}"
   instead of
     "{ [Function: foo]\n  property: 'data'\n}".

Backport-PR-URL: #19230
PR-URL: #17576
Reviewed-By: Anna Henningsen <[email protected]>
@targos targos mentioned this pull request Mar 18, 2018
v9.9.0 proposal #19428
Merged
MylesBorins pushed a commit that referenced this pull request Mar 20, 2018
@BridgeAR @MylesBorins
util: fix custom inspect description
fd4c05a
Using a custom inspect function on the inspected object is
deprecated. Remove the reference from the option description
to make sure the user will read about the deprecation in the
more detailed description.

Backport-PR-URL: #19230
PR-URL: #17576
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 20, 2018
@BridgeAR @MylesBorins
util: rename util.inspect argument
ce3a5af
util.inspect can actually receive any property and the description
was wrong so far. This fixes it by renaming the argument to
value and also updating the description.

Backport-PR-URL: #19230
PR-URL: #17576
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 20, 2018
@BridgeAR @MylesBorins
util: add util.inspect compact option
c18ac52
The current default formatting is not ideal and this improves
the situation by formatting the output more intuitiv.

1) All object keys are now indented by 2 characters instead of
   sometimes 2 and sometimes 3 characters.
2) Each object key will now use an individual line instead of
   sharing a line potentially with multiple object keys.
3) Long strings will now be split into multiple lines in case
   they exceed the "lineBreak" option length (including the
   current indentation).
4) Opening braces are now directly behind a object property
   instead of using a new line.
5) Switch inspect "base" order. In case the compact option is set
   to `false`, inspect will now print
     "[Function: foo] {\n  property: 'data'\n}"
   instead of
     "{ [Function: foo]\n  property: 'data'\n}".

Backport-PR-URL: #19230
PR-URL: #17576
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins added a commit that referenced this pull request Mar 21, 2018
@MylesBorins
2018-03-21, Version 9.9.0 (Current)
74fb02f
Notable changes:

* assert:
  - From now on all error messages produced by `assert` in strict mode
    will produce a error diff. (Ruben Bridgewater)
    #17615
  - From now on it is possible to use a validation object in throws
    instead of the other possibilities. (Ruben Bridgewater)
    #17584
* crypto:
  - allow passing null as IV unless required (Tobias Nießen)
    #18644
* fs:
  - support as and as+ flags in stringToFlags() (Sarat Addepalli)
    #18801
* tls:
  - expose Finished messages in TLSSocket (Anton Salikhmetov)
    #19102
* tty:
  - Add getColorDepth function to determine if terminal supports colors
    (Ruben Bridgewater) #17615
* util:
  - add util.inspect compact option (Ruben Bridgewater)
    #17576
* **Added new collaborators**
  - [watson](https://github.com/watson) Thomas Watson

PR-URL: #19428
MylesBorins added a commit that referenced this pull request Mar 21, 2018
@MylesBorins
2018-03-21, Version 9.9.0 (Current)
0fc3592
Notable changes:

* assert:
  - From now on all error messages produced by `assert` in strict mode
    will produce a error diff. (Ruben Bridgewater)
    #17615
  - From now on it is possible to use a validation object in throws
    instead of the other possibilities. (Ruben Bridgewater)
    #17584
* crypto:
  - allow passing null as IV unless required (Tobias Nießen)
    #18644
* fs:
  - support as and as+ flags in stringToFlags() (Sarat Addepalli)
    #18801
* tls:
  - expose Finished messages in TLSSocket (Anton Salikhmetov)
    #19102
* tty:
  - Add getColorDepth function to determine if terminal supports colors
    (Ruben Bridgewater) #17615
* util:
  - add util.inspect compact option (Ruben Bridgewater)
    #17576
* **Added new collaborators**
  - [watson](https://github.com/watson) Thomas Watson

PR-URL: #19428
@targos targos added backported-to-v9.x and removed backport-requested-v9.x labels Mar 24, 2018
@MylesBorins MylesBorins added the backport-requested-v8.x label Jul 31, 2018
@MylesBorins

MylesBorins commented Jul 31, 2018

Copy link
Copy Markdown
Contributor

Requested backport to 8.x in #19230

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR
BridgeAR deleted the util-structured branch April 1, 2019 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell left review comments
@addaleax addaleax addaleax approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@BridgeAR @Trott @addaleax @MylesBorins @jasnell @targos @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.