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, test: improve inspect escaping by BridgeAR · Pull Request #21624 · nodejs/node

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Jul 2, 2018

Copy link
Copy Markdown
Member

For me it is always hard to read strings that use escaped quotes. This PR reduces the amount of quotes that have to be escaped significantly be just using either double quotes or backticks instead, if appropriate. That should improve the readability of these strings a lot.

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

Sorry, something went wrong.

Uh oh!

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

All reactions
BridgeAR added 3 commits July 2, 2018 22:49
@BridgeAR
util: do not escape single quotes if not necessary
05ce84a
Right now util.inspect will always escape single quotes. That is not
necessary though in case the string that will be escaped does not
contain double quotes. In that case the string can simply be wrapped
in double quotes instead.
@BridgeAR
util: reduce .inspect quote escaping
1c80969
This reduces the amount of quotes util.inspect escapes by falling
back to backticks in case a string contains single and double quotes.
That makes sure only very few strings have to escape quotes at all.
Thus it increases the readability of these strings.
@BridgeAR
test: improve inspect readability
8655234
The string escaping is hard to read. This changes all those escaped
strings to use double quotes instead so no escaping is necessary.
@nodejs-github-bot

nodejs-github-bot commented Jul 2, 2018

Copy link
Copy Markdown
Collaborator

@BridgeAR build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/197/pipeline

All reactions

Sorry, something went wrong.

Uh oh!

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

@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Jul 2, 2018
@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 2, 2018
@BridgeAR
BridgeAR requested a review from a team July 2, 2018 21:50
ChALkeR
ChALkeR previously requested changes Jul 3, 2018
View reviewed changes

@ChALkeR ChALkeR left a comment

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.

> console.log(util.inspect('${xx}\'"'))
`${xx}'"`
undefined
> `${xx}'"`
ReferenceError: xx is not defined

If $ is present backticks should be avoided as well.
Also, please add a test for that.

Sorry, something went wrong.

Uh oh!

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

All reactions
@BridgeAR
fixup: address comment
97f78de
@BridgeAR

BridgeAR commented Jul 4, 2018

Copy link
Copy Markdown
Member Author

@ChALkeR done

All reactions

Sorry, something went wrong.

Uh oh!

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

@BridgeAR

BridgeAR commented Jul 4, 2018

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@BridgeAR

BridgeAR commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

Ping @ChALkeR
@nodejs/tsc PTAL

All reactions

Sorry, something went wrong.

Uh oh!

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

jasnell
jasnell approved these changes Jul 10, 2018
View reviewed changes
@BridgeAR

BridgeAR commented Jul 13, 2018

Copy link
Copy Markdown
Member Author

@nodejs/tsc PTAL.

@ChALkeR PTAL, I addressed your comment :)

ChALkeR 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 requested a review from a team July 13, 2018 15:19
@BridgeAR BridgeAR added the tsc-review label Jul 13, 2018
@ChALkeR
ChALkeR dismissed their stale review July 13, 2018 19:36

Fixed.

@ChALkeR

ChALkeR commented Jul 13, 2018

Copy link
Copy Markdown
Member

@BridgeAR Sorry for the delay, totally missed this. 😞
I dismissed my stale review.

All reactions

Sorry, something went wrong.

Uh oh!

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

@targos

targos commented Jul 14, 2018

Copy link
Copy Markdown
Member

I'm OK with the change

All reactions

Sorry, something went wrong.

Uh oh!

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

@Trott

Trott commented Jul 15, 2018

Copy link
Copy Markdown
Member

I'm neutral on this one. I see that there is benefit. And I see that there is maintenance cost. And I wonder whether or not it's an issue that people may be surprised. ("Why did I get a template string one time, a single-quoted string the other time, and a double-quoted string the last time? What is going on?!") Honestly have no idea if that will ever come up and if it's a problem or not.

Leaving a note so that it doesn't feel like the TSC ping is being ignored.

ChALkeR 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 Jul 16, 2018

Copy link
Copy Markdown
Member Author

@targos is the "OK" a LG? In that case I would go ahead and land this.

@Trott I believe that is relatively clear from the output itself: if the string contains a single quote it is clear that it can only be wrapped into double quotes or back ticks or the single quote would have to be escaped. Do you really think there is room for confusion? I actually wonder if people will even notice the difference besides being able to read the output without knowing that it was escaped before.

All reactions

Sorry, something went wrong.

Uh oh!

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

mcollina
mcollina approved these changes Jul 16, 2018
View reviewed changes

@mcollina mcollina left a comment

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.

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
@targos

targos commented Jul 16, 2018

Copy link
Copy Markdown
Member

@BridgeAR consider it a rubber-stamp LG. I didn't review the code.

All reactions

Sorry, something went wrong.

Uh oh!

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

@BridgeAR

BridgeAR commented Jul 16, 2018

Copy link
Copy Markdown
Member Author

CI before landing: https://ci.nodejs.org/job/node-test-pull-request/15893/

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 Jul 16, 2018
@BridgeAR
util: do not escape single quotes if not necessary
b3e93a9
Right now util.inspect will always escape single quotes. That is not
necessary though in case the string that will be escaped does not
contain double quotes. In that case the string can simply be wrapped
in double quotes instead.
If the string contains single and double quotes and it does not
contain `${` as part of the string, backticks will be used instead.
That makes sure only very few strings have to escape quotes at all.
Thus it increases the readability of these strings.

PR-URL: nodejs#21624
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Jul 16, 2018
@BridgeAR
test: improve inspect readability
9c50199
The string escaping is hard to read. This changes all those escaped
strings to use double quotes instead so no escaping is necessary.

PR-URL: nodejs#21624
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@BridgeAR

BridgeAR commented Jul 16, 2018

Copy link
Copy Markdown
Member Author

Landed in b3e93a9, 9c50199 🎉

All reactions

Sorry, something went wrong.

Uh oh!

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

@BridgeAR BridgeAR closed this Jul 16, 2018
targos pushed a commit that referenced this pull request Jul 31, 2018
@BridgeAR @targos
test: improve inspect readability
62fd845
The string escaping is hard to read. This changes all those escaped
strings to use double quotes instead so no escaping is necessary.

PR-URL: #21624
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@targos targos mentioned this pull request Jul 31, 2018
v10.8.0 proposal #22040
Merged
This was referenced Aug 1, 2018
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-nodejs#212
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#223
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#224
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#225
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#226
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#227
Closed
@bnb bnb mentioned this pull request Sep 12, 2019
util: change in console.log() output #29539
Closed
@BridgeAR
BridgeAR deleted the improve-inspect-escaping branch January 20, 2020 11:34
@snyk-bot snyk-bot mentioned this pull request Mar 18, 2020
[Snyk] Upgrade: gatsby, gatsby-image, gatsby-plugin-catch-links, gatsby-plugin-manifest, gatsby-plugin-no-sourcemaps, gatsby-plugin-offline, gatsby-plugin-react-helmet, gatsby-plugin-sharp, gatsby-plugin-styled-components, gatsby-remark-autolink-headers, gatsby-remark-prismjs, gatsby-source-filesystem, gatsby-transformer-remark O330oei/node#3
Open
@sttk sttk mentioned this pull request Dec 5, 2021
chore!: Normalize repository, dropping node <10.13 support gulpjs/fancy-log#21
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@jasnell jasnell jasnell approved these changes
@ChALkeR ChALkeR ChALkeR left review comments

Uh oh!

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

Assignees

No one assigned

Labels

semver-major PRs that contain breaking changes and should be released in the next major 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 @nodejs-github-bot @ChALkeR @targos @Trott @mcollina @jasnell
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.