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 — tools: add ASCII only lint rule in lib/ by hkal · Pull Request #11371 · nodejs/node

Conversation

@hkal

@hkal hkal commented Feb 14, 2017

Copy link
Copy Markdown

Detects if files in lib/ contain non-ASCII characters and
raises a linting error. Also removes non-ASCII characters from
lib/timers.js

Fixes: #11209

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

tools, lib

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 timers Issues and PRs related to timers, setImmediate(), setInterval(), and setTimeout(). tools Issues and PRs related to the tools directory. labels Feb 14, 2017
@Trott

Trott commented Feb 14, 2017

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

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

mscdex
mscdex reviewed Feb 14, 2017
View reviewed changes
Comment thread lib/timers.js Outdated

@mscdex mscdex Feb 14, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

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.

Minor nit: maybe slashes would look a tad better for the corners instead of a pipe?

Sorry, something went wrong.

Uh oh!

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

All reactions
@thefourtheye

thefourtheye commented Feb 14, 2017

Copy link
Copy Markdown
Contributor

This contradicts #11129

All reactions

Sorry, something went wrong.

Uh oh!

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

@aqrln

aqrln commented Feb 14, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@thefourtheye actually it doesn't, to the contrary, I'd say it complements it.

All reactions

Sorry, something went wrong.

Uh oh!

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

addaleax
addaleax reviewed Feb 14, 2017
View reviewed changes
Comment thread lib/timers.js Outdated

@addaleax addaleax Feb 14, 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.

I think it would be okay to make an exception for this file and just add an eslint-disable line for the rule.

(It would be good to have this file as a test that we can use UTF-8 in sources, even if we prefer not to.)

Sorry, something went wrong.

Uh oh!

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

All reactions

@aqrln aqrln Feb 14, 2017

Copy link
Copy Markdown
Contributor

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.

@addaleax I don't really think it is a way to test this. It wasn't possible to use UTF-8 in sources since #5458 and before #11129 yet all worked well since it doesn't actually matter whether comments are encoded correctly while these are just comments.

Sorry, something went wrong.

Uh oh!

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

All reactions
@gibfahn

gibfahn commented Feb 14, 2017

Copy link
Copy Markdown
Member

@thefourtheye cross-posting @bnoordhuis's comment from #11209 (comment)

Would be good to enforce it because Unicode files take up twice as much space in the binary as plain ASCII files.

thefourtheye 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.

@jasnell

jasnell commented Feb 14, 2017

Copy link
Copy Markdown
Member

I'm really not entirely sure that we should do this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@addaleax

addaleax commented Feb 14, 2017

Copy link
Copy Markdown
Member

Fwiw once I have the time (maybe later this week) I’d like to look into making the tooling strip comments during compilation, so that we can at least keep non-ASCII characters inside of comments.

aqrln and jasnell reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@Fishrock123

Fishrock123 commented Feb 14, 2017

Copy link
Copy Markdown
Contributor

Erm, I added those comments, what is the point of this? The source bundling tool supports UTF-8 as previously linked above.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fishrock123
Fishrock123 self-requested a review February 14, 2017 15:54
@aqrln

aqrln commented Feb 14, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@addaleax that would be great. Do you mind if I take it? :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@addaleax

addaleax commented Feb 14, 2017

Copy link
Copy Markdown
Member

@aqrln You mean, updating the tooling to do that? Sure, go for it! You can ping me if there are any questions :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@bnoordhuis

bnoordhuis commented Feb 14, 2017

Copy link
Copy Markdown
Member

@addaleax @aqrln It shouldn't strip line ends though, or line numbers in stack traces won't match with the on-disk files.

addaleax, aqrln, and thefourtheye reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

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

@aqrln

aqrln commented Feb 14, 2017

Copy link
Copy Markdown
Contributor

@bnoordhuis sure thing :) But thanks for pointing that out anyway.

All reactions

Sorry, something went wrong.

Uh oh!

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

@hkal

hkal commented Feb 15, 2017

Copy link
Copy Markdown
Author

Alright, so it looks like the consensus is we don't want the linter checking for ASCII characters and other solutions will be explored?

All reactions

Sorry, something went wrong.

Uh oh!

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

@addaleax

addaleax commented Feb 15, 2017

Copy link
Copy Markdown
Member

@hkal I think it still makes sense to try to enforce this outside of comments… I am not an eslint expert but it looks like adjusting your code should be easy?

Maybe just wait until we’ve resolve the above discussion…

All reactions

Sorry, something went wrong.

Uh oh!

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

@hkal

hkal commented Feb 15, 2017

Copy link
Copy Markdown
Author

@addaleax the code can easily be changed to not include comments. I'll hold off making any changes until a decision has been reached. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@gibfahn

gibfahn commented Feb 16, 2017

Copy link
Copy Markdown
Member

I think it still makes sense to try to enforce this outside of comments… I am not an eslint expert but it looks like adjusting your code should be easy?

Maybe just wait until we’ve resolve the above discussion…

@Fishrock123 @thefourtheye are you opposed to a lint rule that enforces ASCII outside of comments?

All reactions

Sorry, something went wrong.

Uh oh!

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

@aqrln aqrln mentioned this pull request Feb 16, 2017
tools: make js2c.py strip comments from sources #11417
Closed
2 tasks done
@Fishrock123

Fishrock123 commented Feb 16, 2017

Copy link
Copy Markdown
Contributor

Not really, I think?

gibfahn reacted with thumbs up emoji gibfahn reacted with laugh emoji
All reactions
  • 👍 1 reaction
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

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

aqrln added a commit to aqrln/node that referenced this pull request Feb 16, 2017
@aqrln
tools: make js2c.py strip comments from sources
6296a6c
In order to allow using Unicode characters inside comments of built-in
JavaScript libraries without forcing them to be stored as UTF-16 data in
Node's binary, update the tooling to strip comments during build
process. All line breaks are preserved so that line numbers in stack
traces aren't broken.

Refs: nodejs#11129
Refs: nodejs#11371 (comment)
@aqrln aqrln mentioned this pull request Feb 17, 2017
test: add Unicode characters regression test #11423
Closed
3 tasks done
@hkal

hkal commented Mar 8, 2017

Copy link
Copy Markdown
Author

@gibfahn any movement on this?

All reactions

Sorry, something went wrong.

Uh oh!

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

@gibfahn

gibfahn commented Mar 9, 2017

Copy link
Copy Markdown
Member

@hkal I personally prefer the unicode comment in lib/timers.js, so I'd rather we added an eslint-disable exception for that block and left it as it is. In the future if that is moved out into a separate guide it could be removed.

Otherwise, unless @jasnell or @thefourtheye or any other collaborators disagree, we should be able to move forward on this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jasnell

jasnell commented Mar 10, 2017

Copy link
Copy Markdown
Member

As long as we add the eslint-disable for the timers comment block, I'm ok with this going forward

All reactions

Sorry, something went wrong.

Uh oh!

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

@TimothyGu

TimothyGu commented Mar 20, 2017

Copy link
Copy Markdown
Member

@hkal, can you add a eslint-disable for lib/timers.js as @aqrln and @jasnell suggested? If you do so we'll be able to merge this. Thanks a lot!

All reactions

Sorry, something went wrong.

Uh oh!

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

@thefourtheye

thefourtheye commented Mar 20, 2017

Copy link
Copy Markdown
Contributor

@gibfahn wrote

@Fishrock123 @thefourtheye are you opposed to a lint rule that enforces ASCII outside of comments?

No, I am not opposed to it.

addaleax and gibfahn reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@hkal
hkal force-pushed the only-ascii-characters branch 3 times, most recently from 3a7ff16 to aad90cf Compare March 22, 2017 14:36
@hkal

hkal commented Mar 22, 2017

Copy link
Copy Markdown
Author

@gibfahn Alright, I think we're good here. Please review.

All reactions

Sorry, something went wrong.

Uh oh!

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

jasnell
jasnell approved these changes Mar 22, 2017
View reviewed changes
Comment thread lib/timers.js Outdated

@jasnell jasnell Mar 22, 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.

Unrelated whitespace change :-)

Sorry, something went wrong.

Uh oh!

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

gibfahn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
aqrln
aqrln reviewed Mar 22, 2017
View reviewed changes
Comment thread tools/eslint-rules/only-ascii-characters.js Outdated

@aqrln aqrln Mar 22, 2017

Copy link
Copy Markdown
Contributor

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.

Either the comment is misleading, or it works not the way you planned it to. This will report the first non-ASCII character per token, not per line.

Sorry, something went wrong.

Uh oh!

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

All reactions

@hkal hkal Mar 24, 2017

Copy link
Copy Markdown
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.

This line makes the values in the tokens (couldn't think of a better name) array look like:

{ type: 'Punctuator',
  value: ';',
  start: 22327,
  end: 22328,
  loc:
   SourceLocation {
     start: Position { line: 767, column: 1 },
     end: Position { line: 767, column: 2 } },
  range: [ 22327, 22328 ] }
{ type: 'Line',
  value: ' Copyright Joyent, Inc. and other Node contributors.',
  start: 0,
  end: 54,
  range: [ 0, 54 ],
  loc:
   { start: Position { line: 1, column: 0 },
     end: Position { line: 1, column: 54 } } }

In the case of type Line we only report the the first occurrence of a non-ASCII character. In my latest iteration I took the comment out since it didn't really help clarify.

Sorry, something went wrong.

Uh oh!

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

All reactions
aqrln
aqrln reviewed Mar 22, 2017
View reviewed changes
Comment thread tools/eslint-rules/only-ascii-characters.js Outdated

@aqrln aqrln Mar 22, 2017

Copy link
Copy Markdown
Contributor

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.

Why not do this in one pass without the extra errors array? You can make this a named function and call it instead of errors.push().

Sorry, something went wrong.

Uh oh!

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

hkal reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
aqrln
aqrln reviewed Mar 22, 2017
View reviewed changes
Comment thread tools/eslint-rules/only-ascii-characters.js Outdated

@aqrln aqrln Mar 22, 2017

Copy link
Copy Markdown
Contributor

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.

IMO, it would be better to flip the condition and return early (if (!matches) return;) reducing the indentation level for the rest of the function.

Sorry, something went wrong.

Uh oh!

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

All reactions
@hkal
tools: add ASCII only lint rule for lib/
e7b2a19
Detects if files in lib/ contain non-ASCII characters and
raises a linting error. Also removes non-ASCII characters
from lib/console.js comments

Fixes: nodejs#11209
@hkal
hkal force-pushed the only-ascii-characters branch from aad90cf to e7b2a19 Compare March 24, 2017 04:39
@hkal

hkal commented Mar 24, 2017

Copy link
Copy Markdown
Author

I think I've addressed all the feedback.

@aqrln @jasnell @gibfahn

All reactions

Sorry, something went wrong.

Uh oh!

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

jasnell
jasnell approved these changes Mar 24, 2017
View reviewed changes
@gibfahn

gibfahn commented Mar 24, 2017

Copy link
Copy Markdown
Member

As this is an eslint rule addition, cc/ @not-an-aardvark, @silverwind, @Trott, @mscdex

All reactions

Sorry, something went wrong.

Uh oh!

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

not-an-aardvark
not-an-aardvark reviewed Mar 24, 2017
View reviewed changes
Comment thread tools/eslint-rules/only-ascii-characters.js
const commentTokens = source.getAllComments();
const tokens = sourceTokens.concat(commentTokens);

tokens.forEach((token) => {

@not-an-aardvark not-an-aardvark Mar 24, 2017

Copy link
Copy Markdown
Contributor

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.

This will fail to match non-ascii whitespace that could appear between tokens, so it's not quite disallowing all non-ascii characters in files. This could be fixed by matching the regex against source.text rather than against each token.

That said, I think the no-irregular-whitespace rule will cover non-ascii whitespace.

Sorry, something went wrong.

Uh oh!

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

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

@gibfahn gibfahn Mar 24, 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.

If the latter is true, it would be good to have a comment explaining that.

Sorry, something went wrong.

Uh oh!

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

All reactions

@aqrln aqrln Mar 24, 2017

Copy link
Copy Markdown
Contributor

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.

The comment alone would not be sufficient, it is important that the linter ensures there are no irregular Unicode whitespace characters since they cannot be seen during code review.

Sorry, something went wrong.

Uh oh!

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

All reactions

@gibfahn gibfahn Mar 25, 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.

@aqrln by:

If the latter is true

I mean that if:

I think the no-irregular-whitespace rule will cover non-ascii whitespace.

@not-an-aardvark's theory is correct, and the non-ASCII whitespace characters are already covered in a separate rule, then we could just use that for whitespace, and add a comment in here to explain that we don't need to worry about whitespace as it's covered in another rule.

Sorry, something went wrong.

Uh oh!

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

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

@aqrln aqrln Mar 25, 2017

Copy link
Copy Markdown
Contributor

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.

@gibfahn ah, I see, sorry. I didn't pay enough attention to that "if the latter" part so I didn't understand you right.

Sorry, something went wrong.

Uh oh!

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

gibfahn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread tools/eslint-rules/only-ascii-characters.js
// Rule Definition
//------------------------------------------------------------------------------

const nonAsciiPattern = new RegExp('([^\x00-\x7F])', 'g');

@not-an-aardvark not-an-aardvark Mar 24, 2017

Copy link
Copy Markdown
Contributor

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 might be clearer to use a regex literal here instead of the RegExp constructor. Right now, \x00 and \x7F are interpreted as part of the string, so the resulting regex pattern actually contains a null character. This still works fine, but it could be confusing for debugging (e.g. if the regex is printed, it will be difficult to tell that it contains a null character).

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread tools/eslint-rules/only-ascii-characters.js

reportError({
line: loc.start.line,
column,

@not-an-aardvark not-an-aardvark Mar 24, 2017

Copy link
Copy Markdown
Contributor

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.

This could result in an invalid report location if the offending character is in a block comment. For example:

/* foo
■ */

The rule reports an error for this comment at line 1, column 7, but that location doesn't actually exist.

Sorry, something went wrong.

Uh oh!

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

All reactions
Trott
Trott reviewed Mar 24, 2017
View reviewed changes
Comment thread tools/eslint-rules/only-ascii-characters.js
* @author Kalon Hinds
*/

/* eslint no-control-regex:0 */

@Trott Trott Mar 24, 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.

I'd prefer see eslint-disable-line or eslint-disable-next-line to target the places where the control characters are needed.

Sorry, something went wrong.

Uh oh!

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

All reactions
@Fishrock123

Fishrock123 commented Apr 3, 2017

Copy link
Copy Markdown
Contributor

still not really a fan

All reactions

Sorry, something went wrong.

Uh oh!

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

@refack
refack force-pushed the master branch from 16073c0 to fbe946b Compare April 14, 2017 04:11
@BridgeAR

BridgeAR commented Aug 26, 2017

Copy link
Copy Markdown
Member

@hkal would you be so kind and have a look at the other comments and rebase this?

All reactions

Sorry, something went wrong.

Uh oh!

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

@jasnell jasnell added the stalled Issues and PRs manually marked as stalled and scheduled for automatic closure. label Aug 29, 2017
@BridgeAR

BridgeAR commented Sep 8, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Closing this due to a long inactivity period. @hkal thanks for your contribution anyways and please feel free to reopen (or just leave a comment to reopen) if you would like to follow up on this!

All reactions

Sorry, something went wrong.

Uh oh!

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

@BridgeAR BridgeAR closed this Sep 8, 2017
This was referenced Jan 4, 2018
tools: eslint rule to disallow Unicode quotes #17934
Closed
tools: non-Ascii linter for /lib only #18043
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Trott Trott Trott left review comments
@addaleax addaleax addaleax left review comments
@jasnell jasnell jasnell approved these changes
@Fishrock123 Fishrock123 Awaiting requested review from Fishrock123
+4 more reviewers
@mscdex mscdex mscdex left review comments
@aqrln aqrln aqrln left review comments
@not-an-aardvark not-an-aardvark not-an-aardvark left review comments
@gibfahn gibfahn gibfahn left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

stalled Issues and PRs manually marked as stalled and scheduled for automatic closure. timers Issues and PRs related to timers, setImmediate(), setInterval(), and setTimeout(). tools Issues and PRs related to the tools directory.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Linter rule: use ASCII quotes not Unicode ones

Uh oh!

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

14 participants

@hkal @Trott @thefourtheye @aqrln @gibfahn @jasnell @addaleax @Fishrock123 @bnoordhuis @TimothyGu @BridgeAR @mscdex @not-an-aardvark @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 01402520 — 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.