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

tools: eslint rule to disallow Unicode quotes #17934

Closed
wants to merge 2 commits into from
Closed
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: 6 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -147,6 +147,12 @@ rules:
}, {
selector: "ThrowStatement > CallExpression[callee.name=/Error$/]",
message: "Use new keyword when throwing an Error."
}, {
selector: "Literal[value=/\u2019/]",
message: "use an ASCII single quote (`'`) instead of a Unicode quote (`\u2019`)"
}, {
selector: "Literal[value=/[“”«»]/]",
message: "use an ASCII double quote (`\"`) instead of a Unicode double quote (`“`, `”`, `«`, `»`)"
}]
no-tabs: error
no-trailing-spaces: error
2 changes: 2 additions & 0 deletions test/addons-napi/test_string/test.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,9 @@ assert.strictEqual(test_string.TestUtf16Insufficient(str3), str3.slice(0, 3));
assert.strictEqual(test_string.Utf16Length(str3), 27);
assert.strictEqual(test_string.Utf8Length(str3), 27);

/* eslint-disable no-restricted-syntax */
const str4 = '¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿';
/* eslint-enable no-restricted-syntax */
assert.strictEqual(test_string.TestLatin1(str4), str4);
assert.strictEqual(test_string.TestUtf8(str4), str4);
assert.strictEqual(test_string.TestUtf16(str4), str4);
2 changes: 2 additions & 0 deletions test/parallel/test-buffer-ascii.js
Original file line number Diff line number Diff line change
@@ -28,8 +28,10 @@ const assert = require('assert');
assert.strictEqual(Buffer.from('hérité').toString('ascii'), 'hC)ritC)');

// 71 characters, 78 bytes. The ’ character is a triple-byte sequence.
/* eslint-disable no-restricted-syntax */
const input = 'C’est, graphiquement, la réunion d’un accent aigu ' +
'et d’un accent grave.';
/* eslint-enable no-restricted-syntax */

const expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' +
'db\u0000\u0019un accent aigu et db\u0000\u0019un ' +
2 changes: 2 additions & 0 deletions test/parallel/test-fs-append-file-sync.js
Original file line number Diff line number Diff line change
@@ -28,13 +28,15 @@ const fs = require('fs');
const currentFileData = 'ABCD';
const m = 0o600;
const num = 220;
/* eslint-disable no-restricted-syntax */
const data = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' +
'广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' +
'南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' +
'前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
'南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' +
'历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' +
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n';
/* eslint-enable no-restricted-syntax */

common.refreshTmpDir();

2 changes: 2 additions & 0 deletions test/parallel/test-fs-append-file.js
Original file line number Diff line number Diff line change
@@ -30,13 +30,15 @@ const filename = join(common.tmpDir, 'append.txt');
const currentFileData = 'ABCD';

const n = 220;
/* eslint-disable no-restricted-syntax */
const s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' +
'广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' +
'南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' +
'前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
'南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' +
'历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' +
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n';
/* eslint-enable no-restricted-syntax */

let ncallbacks = 0;

2 changes: 2 additions & 0 deletions test/parallel/test-fs-write-file-uint8array.js
Original file line number Diff line number Diff line change
@@ -8,13 +8,15 @@ common.refreshTmpDir();

const filename = join(common.tmpDir, 'test.txt');

/* eslint-disable no-restricted-syntax */
const s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' +
'广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' +
'南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' +
'前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
'南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' +
'历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' +
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n';
/* eslint-enable no-restricted-syntax */

const input = Uint8Array.from(Buffer.from(s, 'utf8'));

2 changes: 2 additions & 0 deletions test/parallel/test-fs-write-file.js
Original file line number Diff line number Diff line change
@@ -30,13 +30,15 @@ common.refreshTmpDir();
const filename = join(common.tmpDir, 'test.txt');

const n = 220;
/* eslint-disable no-restricted-syntax */
const s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' +
'广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' +
'南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' +
'前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
'南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' +
'历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' +
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n';
/* eslint-enable no-restricted-syntax */

fs.writeFile(filename, s, common.mustCall(function(e) {
assert.ifError(e);
2 changes: 2 additions & 0 deletions test/parallel/test-http-chunked.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ const common = require('../common');
const assert = require('assert');
const http = require('http');

/* eslint-disable no-restricted-syntax */
const UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一个国家,' +
'国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、' +
'贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' +
@@ -33,6 +34,7 @@ const UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的
'南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' +
'采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' +
'有效的改善了岭南地区落后的政治、经济现状。';
/* eslint-enable no-restricted-syntax */

const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf8' });
3 changes: 2 additions & 1 deletion test/parallel/test-stdin-from-file.js
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ const tmpFile = join(common.tmpDir, 'stdin.txt');

const cmd = `"${process.argv[0]}" "${stdoutScript}" < "${tmpFile}"`;

/* eslint-disable no-restricted-syntax */
const string = 'abc\nümlaut.\nsomething else\n' +
'南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,' +
'疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、' +
@@ -22,7 +23,7 @@ const string = 'abc\nümlaut.\nsomething else\n' +
'采用封建制和郡县制并存的制度,' +
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,' +
'有效的改善了岭南地区落后的政治、##济现状。\n';

/* eslint-enable no-restricted-syntax */

common.refreshTmpDir();