From 7c882c3961b0be0366ddad3af2306158b26e5403 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Sun, 3 Mar 2019 12:36:12 +0800 Subject: [PATCH] tools: add and apply eslint rule no-regex-spaces --- .eslintrc.js | 1 + test/parallel/test-assert-deep.js | 2 +- test/parallel/test-assert.js | 2 +- test/parallel/test-debug-usage.js | 2 +- test/parallel/test-events-uncaught-exception-stack.js | 2 +- test/parallel/test-http2-stream-client.js | 6 +++--- test/parallel/test-internal-errors.js | 4 ++-- test/parallel/test-repl-definecommand.js | 2 +- test/parallel/test-repl-underscore.js | 6 +++--- test/parallel/test-repl.js | 8 ++++---- test/parallel/test-v8-untrusted-code-mitigations.js | 2 +- test/tick-processor/test-tick-processor-unknown.js | 2 +- 12 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 03dd8e47b875d3..6f25881d7c5904 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -137,6 +137,7 @@ module.exports = { 'no-path-concat': 'error', 'no-proto': 'error', 'no-redeclare': 'error', + 'no-regex-spaces': 'error', 'no-restricted-modules': ['error', 'sys'], /* eslint-disable max-len */ 'no-restricted-properties': [ diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index fc1ace51b39293..245adc6f0f6978 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -1064,7 +1064,7 @@ assert.throws( { code: 'ERR_ASSERTION', name: 'AssertionError [ERR_ASSERTION]', - message: /a: \[Getter: 5]\n- a: \[Getter: 6]\n / + message: /a: \[Getter: 5]\n- {3}a: \[Getter: 6]\n {2}/ } ); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index a7c37e8fb33024..aaadb68e54a6a8 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -1144,7 +1144,7 @@ assert.throws( assert.deepStrictEqual(Array(100).fill(1), 'foobar'); } catch (err) { threw = true; - assert(/actual: \[Array],\n expected: 'foobar',/.test(inspect(err))); + assert(/actual: \[Array],\n {2}expected: 'foobar',/.test(inspect(err))); } assert(threw); } diff --git a/test/parallel/test-debug-usage.js b/test/parallel/test-debug-usage.js index a264029f434a5a..30901591ba8312 100644 --- a/test/parallel/test-debug-usage.js +++ b/test/parallel/test-debug-usage.js @@ -12,7 +12,7 @@ child.stderr.setEncoding('utf8'); const expectedLines = [ /^\(node:\d+\) \[DEP0068\] DeprecationWarning:/, /^Usage: .*node.* debug script\.js$/, - /^ .*node.* debug :$/ + /^ {7}.*node.* debug :$/ ]; let actualUsageMessage = ''; diff --git a/test/parallel/test-events-uncaught-exception-stack.js b/test/parallel/test-events-uncaught-exception-stack.js index c55322a5aa56c4..59328c13c39c70 100644 --- a/test/parallel/test-events-uncaught-exception-stack.js +++ b/test/parallel/test-events-uncaught-exception-stack.js @@ -9,7 +9,7 @@ process.on('uncaughtException', common.mustCall((err) => { const lines = err.stack.split('\n'); assert.strictEqual(lines[0], 'Error'); lines.slice(1).forEach((line) => { - assert(/^ at/.test(line), `${line} has an unexpected format`); + assert(/^ {4}at/.test(line), `${line} has an unexpected format`); }); })); diff --git a/test/parallel/test-http2-stream-client.js b/test/parallel/test-http2-stream-client.js index 3e6c6b2a8a1b5e..ec426c71ee47f0 100644 --- a/test/parallel/test-http2-stream-client.js +++ b/test/parallel/test-http2-stream-client.js @@ -12,9 +12,9 @@ server.on('stream', common.mustCall((stream) => { assert.strictEqual(stream.aborted, false); const insp = util.inspect(stream); assert.ok(/Http2Stream { id/.test(insp)); - assert.ok(/ state:/.test(insp)); - assert.ok(/ readableState:/.test(insp)); - assert.ok(/ writableState:/.test(insp)); + assert.ok(/ {2}state:/.test(insp)); + assert.ok(/ {2}readableState:/.test(insp)); + assert.ok(/ {2}writableState:/.test(insp)); stream.end('ok'); })); server.listen(0, common.mustCall(() => { diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index e53a9a9fe42ca8..466c5f3dc71d2f 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -86,7 +86,7 @@ common.expectsError(() => { }, { code: 'TEST_ERROR_1', type: RangeError }); }, { code: 'ERR_ASSERTION', - message: /\+ type: \[Function: TypeError]\n- type: \[Function: RangeError]/ + message: /\+ {3}type: \[Function: TypeError]\n- {3}type: \[Function: RangeError]/ }); common.expectsError(() => { @@ -98,7 +98,7 @@ common.expectsError(() => { }, { code: 'ERR_ASSERTION', type: assert.AssertionError, - message: /\+ message: 'Error for testing purposes: a',\n- message: \/\^Error/ + message: /\+ {3}message: 'Error for testing purposes: a',\n- {3}message: \/\^Error/ }); // Test ERR_INVALID_FD_TYPE diff --git a/test/parallel/test-repl-definecommand.js b/test/parallel/test-repl-definecommand.js index efa22ed56f740f..eed9d3efc46fce 100644 --- a/test/parallel/test-repl-definecommand.js +++ b/test/parallel/test-repl-definecommand.js @@ -35,7 +35,7 @@ r.defineCommand('say2', function() { }); inputStream.write('.help\n'); -assert(/\n\.say1 help for say1\n/.test(output), +assert(/\n\.say1 {5}help for say1\n/.test(output), 'help for say1 not present'); assert(/\n\.say2\n/.test(output), 'help for say2 not present'); inputStream.write('.say1 node developer\n'); diff --git a/test/parallel/test-repl-underscore.js b/test/parallel/test-repl-underscore.js index cbf62c3b6e0308..74205b5a7e7250 100644 --- a/test/parallel/test-repl-underscore.js +++ b/test/parallel/test-repl-underscore.js @@ -181,7 +181,7 @@ function testError() { 'Thrown:', /^{ Error: ENOENT: no such file or directory, scandir '.*nonexistent.*'/, /Object\.readdirSync/, - /^ errno: -(2|4058),$/, + /^ {2}errno: -(2|4058),$/, " syscall: 'scandir',", " code: 'ENOENT',", " path: '/nonexistent?' }", @@ -196,8 +196,8 @@ function testError() { 'Thrown:', 'Error: baz', /setImmediate/, - /^ at/, - /^ at/, + /^ {4}at/, + /^ {4}at/, ]; for (const line of lines) { const expected = expectedLines.shift(); diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 2337e32280e8f9..a01a50e2fc5be7 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -537,10 +537,10 @@ const errorTests = [ /^{ Error: Cannot find module 'internal\/repl'/, /^Require stack:/, /^- /, - /^ at .*/, - /^ at .*/, - /^ at .*/, - /^ at .*/ + /^ {4}at .*/, + /^ {4}at .*/, + /^ {4}at .*/, + /^ {4}at .*/ ] }, // REPL should handle quotes within regexp literal in multiline mode diff --git a/test/parallel/test-v8-untrusted-code-mitigations.js b/test/parallel/test-v8-untrusted-code-mitigations.js index c9d89cd5a66e18..6b731878cc72d7 100644 --- a/test/parallel/test-v8-untrusted-code-mitigations.js +++ b/test/parallel/test-v8-untrusted-code-mitigations.js @@ -15,4 +15,4 @@ assert.notStrictEqual(untrustedFlag, -1); const nextFlag = v8Options.indexOf('--', untrustedFlag + 2); const slice = v8Options.substring(untrustedFlag, nextFlag); -assert(slice.match(/type: bool default: false/)); +assert(slice.match(/type: bool {2}default: false/)); diff --git a/test/tick-processor/test-tick-processor-unknown.js b/test/tick-processor/test-tick-processor-unknown.js index 182f8c957c820a..d8330f489c18c0 100644 --- a/test/tick-processor/test-tick-processor-unknown.js +++ b/test/tick-processor/test-tick-processor-unknown.js @@ -17,7 +17,7 @@ const base = require('./tick-processor-base.js'); // Unknown checked for to prevent flakiness, if pattern is not found, // then a large number of unknown ticks should be present base.runTest({ - pattern: /LazyCompile.*\[eval]:1|.*% UNKNOWN/, + pattern: /LazyCompile.*\[eval]:1|.*% {2}UNKNOWN/, code: `function f() { for (var i = 0; i < 1000000; i++) { i++;