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

Linter rule: use ASCII quotes not Unicode ones #11209

Closed
gibfahn opened this issue Feb 7, 2017 · 14 comments
Closed

Linter rule: use ASCII quotes not Unicode ones #11209

gibfahn opened this issue Feb 7, 2017 · 14 comments
Labels
good first issue Issues that are suitable for first-time contributors. tools Issues and PRs related to the tools directory.

Comments

@gibfahn
Copy link
Member

gibfahn commented Feb 7, 2017

  • Subsystem: eslint

See: #11129 (comment)

I added a second commit that replaces a few U+2019 quotes with ASCII quotes so that their files can be stored as one-byte strings.
Probably one for another PR, but this sounds like a good candidate for a lint rule.

Basically we need a lint rule that checks for U+2019 quotes: , and suggests that they be replaced with ASCII quotes: '.

cc/ @bnoordhuis @richardlau

@gibfahn gibfahn added the good first issue Issues that are suitable for first-time contributors. label Feb 7, 2017
@addaleax addaleax added the tools Issues and PRs related to the tools directory. label Feb 7, 2017
@addaleax
Copy link
Member

addaleax commented Feb 7, 2017

Two things:

  • This should apply to lib/ and only to lib/, because that’s where we need it.
  • This isn’t really about quotation marks; ideally, any non-ASCII character would be forbidden (sigh)…

@silverwind
Copy link
Contributor

silverwind commented Feb 7, 2017

We could do something like this (match is fed to the RegExp constructor):

- match: ''
  replacement: '\''
- match: '[—–]'
  replacement: '-' 
- match: '[^\x00-\x7F]'
  replacement: ''

The last one might be a bit extreme :)

@aqrln
Copy link
Contributor

aqrln commented Feb 7, 2017

@silverwind I'd also add replacements for “” and «» to ASCII double quotes.

@silverwind
Copy link
Contributor

You can always contribute improvements later, above is just about the general rule config layout.

@gibfahn
Copy link
Member Author

gibfahn commented Feb 8, 2017

I'd also add replacements for “” and «» to ASCII double quotes.

This is an open issue looking for someone to raise a PR. If whoever raises it wants to include those then that sounds good to me.

@not-an-aardvark
Copy link
Contributor

not-an-aardvark commented Feb 10, 2017

If the goal is to allow files to be stored as one-byte strings, would it be better for the rule to just disallow all non-ascii characters in files?

edit: Never mind, I see @addaleax also mentioned this above.

@hkal
Copy link

hkal commented Feb 10, 2017

@gibfahn I'll give this a go if no one else is assigned.

@gibfahn
Copy link
Member Author

gibfahn commented Feb 10, 2017

@hkal go for it!

@hkal
Copy link

hkal commented Feb 14, 2017

Do we still need this after #11129?

cc @bnoordhuis

@bnoordhuis
Copy link
Member

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

hkal added a commit to hkal/node that referenced this issue Mar 24, 2017
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
@Trott
Copy link
Member

Trott commented Jul 26, 2017

This is for quotation marks inside of strings only, right?

I think we should be able to use ESLint's no-restricted-syntax to find these things rather than write a custom rule.

/cc @not-an-aardvark

@not-an-aardvark
Copy link
Contributor

Yes, that should be possible to do. A selector like 'Literal[value=/\u2019/]' will match all string literals containing \u2019.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jul 26, 2017

If we ban all the non-ASCII chars, this could beLiteral[value=/[^\n\x20-\x7e]/]. But this does not affect comments if I get this right.

Currently, we have non-ASCII chars in 4 *.js files in lib folder:

  1. lib/console.js (two in comments)
  2. lib/stream.js (one in comments)
  3. lib/internal/test/unicode.js (one in code)
  4. lib/timers.js (many pseudographics chars in comments)

@SirR4T
Copy link
Contributor

SirR4T commented Jan 1, 2018

Hi. First time contributing here, so please bear with some doubts. I was able to follow @Trott and @not-an-aardvark 's comments, and added two new linter rules. Now make -j4 lint-js fails with the following errors:

/Users/sarat/Play/Github/node/test/addons-napi/test_string/test.js
  45:14  error  use an ASCII double quote (`"`) instead of a Unicode double quote (`“`, `”`, `«`, `»`)  no-restricted-syntax

/Users/sarat/Play/Github/node/test/parallel/test-buffer-ascii.js
  31:15  error  use an ASCII single quote (`'`) instead of a Unicode quote (`’`)  no-restricted-syntax
  32:15  error  use an ASCII single quote (`'`) instead of a Unicode quote (`’`)  no-restricted-syntax
...

Doubts:

  1. Is this the correct place to add the eslint rules?
  2. I see that /* eslint-disable no-restricted-syntax */ can be used to bypass the rules. Since the linter is failing with this commit, should I be adding this to bypass current strings? I notice that all the failing strings are in tests/ folder, so I'm presuming they are necessary and need not be fixed.

SirR4T added a commit to SirR4T/node that referenced this issue Jan 4, 2018
SirR4T added a commit to SirR4T/node that referenced this issue Jan 19, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

Fixes: nodejs#11209
MylesBorins pushed a commit that referenced this issue Feb 21, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

PR-URL: #18043
Fixes: #11209
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
MylesBorins pushed a commit that referenced this issue Feb 21, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

PR-URL: #18043
Fixes: #11209
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
MylesBorins pushed a commit that referenced this issue Feb 21, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

PR-URL: #18043
Fixes: #11209
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
SirR4T added a commit to SirR4T/node that referenced this issue Mar 29, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

PR-URL: nodejs#18043
Fixes: nodejs#11209
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
SirR4T added a commit to SirR4T/node that referenced this issue Mar 29, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

PR-URL: nodejs#18043
Fixes: nodejs#11209
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
BethGriggs pushed a commit that referenced this issue Apr 10, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

PR-URL: #18043
Backport-PR-URL: #19499
Fixes: #11209
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
Non-ASCII characters in /lib get compiled into the node binary,
and may bloat the binary size unnecessarily. A linter rule may
help prevent this.

PR-URL: nodejs#18043
Fixes: nodejs#11209
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. tools Issues and PRs related to the tools directory.
Projects
None yet
10 participants