From 5d70195d5697bbed5051706865339140c519853b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 9 Jan 2022 08:45:19 -0800 Subject: [PATCH] tools,lib,test: enable ESLint no-regex-spaces rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/41463 Reviewed-By: Tobias Nießen Reviewed-By: Michaël Zasso Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Geoffrey Booth --- .eslintrc.js | 1 + lib/internal/util/inspect.js | 2 +- test/parallel/test-assert-deep.js | 2 +- test/parallel/test-assert.js | 2 +- test/parallel/test-debugger-address.js | 2 +- .../test-events-uncaught-exception-stack.js | 2 +- test/parallel/test-http2-stream-client.js | 6 +++--- test/parallel/test-repl-definecommand.js | 2 +- test/parallel/test-repl-underscore.js | 2 +- test/parallel/test-repl.js | 20 +++++++++---------- test/sequential/test-debugger-pid.js | 2 +- .../test-tick-processor-unknown.js | 2 +- 12 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d6c2a7455f8651..5fe6e5b377506d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -215,6 +215,7 @@ module.exports = { 'no-path-concat': 'error', 'no-proto': 'error', 'no-redeclare': ['error', { 'builtinGlobals': false }], + 'no-regex-spaces': 'error', 'no-restricted-modules': ['error', 'sys'], /* eslint-disable max-len */ 'no-restricted-properties': [ diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 3e2309a00bcb91..814e5bf0f37cd4 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -188,7 +188,7 @@ const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]|[\ud800-\udbf const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/; const numberRegExp = /^(0|[1-9][0-9]*)$/; -const coreModuleRegExp = /^ at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/; +const coreModuleRegExp = /^ {4}at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/; const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g; const classRegExp = /^(\s+[^(]*?)\s*{/; diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index f067ad83dc0e69..87d5328d6afc63 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -1123,7 +1123,7 @@ assert.throws( { code: 'ERR_ASSERTION', name: 'AssertionError', - 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 72d259592548b3..b6cc1ea7f1558d 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -1246,7 +1246,7 @@ assert.throws( assert.deepStrictEqual(Array(100).fill(1), 'foobar'); } catch (err) { threw = true; - assert.match(inspect(err), /actual: \[Array],\n expected: 'foobar',/); + assert.match(inspect(err), /actual: \[Array],\n {2}expected: 'foobar',/); } assert(threw); } diff --git a/test/parallel/test-debugger-address.js b/test/parallel/test-debugger-address.js index 95dd1c6e3f8283..bffc28ac916e8d 100644 --- a/test/parallel/test-debugger-address.js +++ b/test/parallel/test-debugger-address.js @@ -65,7 +65,7 @@ function launchTarget(...args) { .then(() => { assert.match( cli.output, - /> 3 \+\+x;/, + /> 3 {3}\+\+x;/, 'marks the 3rd line'); }) .then(() => cleanup()) diff --git a/test/parallel/test-events-uncaught-exception-stack.js b/test/parallel/test-events-uncaught-exception-stack.js index 793a6b0c2ae5e9..e330f254aea3c5 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.match(line, /^ at/); + assert.match(line, /^ {4}at/); }); })); diff --git a/test/parallel/test-http2-stream-client.js b/test/parallel/test-http2-stream-client.js index f975e90cbdac61..89a571b27efc22 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.match(insp, /Http2Stream {/); - assert.match(insp, / state:/); - assert.match(insp, / readableState:/); - assert.match(insp, / writableState:/); + assert.match(insp, / {2}state:/); + assert.match(insp, / {2}readableState:/); + assert.match(insp, / {2}writableState:/); stream.end('ok'); })); server.listen(0, common.mustCall(() => { diff --git a/test/parallel/test-repl-definecommand.js b/test/parallel/test-repl-definecommand.js index 0057eb51ebdd4e..f3973f25d69412 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.match(output, /\n\.say1 help for say1\n/); +assert.match(output, /\n\.say1 {5}help for say1\n/); assert.match(output, /\n\.say2\n/); inputStream.write('.say1 node developer\n'); assert.ok(output.startsWith('hello node developer\n'), diff --git a/test/parallel/test-repl-underscore.js b/test/parallel/test-repl-underscore.js index 8f4470b94963b3..3abd01ba9d0cbc 100644 --- a/test/parallel/test-repl-underscore.js +++ b/test/parallel/test-repl-underscore.js @@ -179,7 +179,7 @@ function testError() { // The sync error, with individual property echoes /^Uncaught Error: ENOENT: no such file or directory, scandir '.*nonexistent\?'/, /Object\.readdirSync/, - /^ errno: -(2|4058),$/, + /^ {2}errno: -(2|4058),$/, " syscall: 'scandir',", " code: 'ENOENT',", " path: '/nonexistent?'", diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 2db174d9691362..c1f87345c8e326 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -566,10 +566,10 @@ const errorTests = [ /^Uncaught Error: Cannot find module 'internal\/repl'/, /^Require stack:/, /^- /, - /^ at .*/, - /^ at .*/, - /^ at .*/, - /^ at .*/, + /^ {4}at .*/, + /^ {4}at .*/, + /^ {4}at .*/, + /^ {4}at .*/, " code: 'MODULE_NOT_FOUND',", " requireStack: [ '' ]", '}', @@ -771,12 +771,12 @@ const errorTests = [ ' group: [Function: group],', ' groupEnd: [Function: groupEnd],', ' table: [Function: table],', - / debug: \[Function: (debug|log)],/, - / info: \[Function: (info|log)],/, - / dirxml: \[Function: (dirxml|log)],/, - / error: \[Function: (error|warn)],/, - / groupCollapsed: \[Function: (groupCollapsed|group)],/, - / Console: \[Function: Console],?/, + / {2}debug: \[Function: (debug|log)],/, + / {2}info: \[Function: (info|log)],/, + / {2}dirxml: \[Function: (dirxml|log)],/, + / {2}error: \[Function: (error|warn)],/, + / {2}groupCollapsed: \[Function: (groupCollapsed|group)],/, + / {2}Console: \[Function: Console],?/, ...process.features.inspector ? [ ' profile: [Function: profile],', ' profileEnd: [Function: profileEnd],', diff --git a/test/sequential/test-debugger-pid.js b/test/sequential/test-debugger-pid.js index 402c1f86dd4ed9..0056113ecaecd3 100644 --- a/test/sequential/test-debugger-pid.js +++ b/test/sequential/test-debugger-pid.js @@ -44,7 +44,7 @@ function launchTarget(...args) { .then(() => { assert.match( cli.output, - /> 3 \+\+x;/, + /> 3 {3}\+\+x;/, 'marks the 3rd line'); }) .then(() => cleanup()) diff --git a/test/tick-processor/test-tick-processor-unknown.js b/test/tick-processor/test-tick-processor-unknown.js index 42208f3bb36d36..d5e6a9359e52eb 100644 --- a/test/tick-processor/test-tick-processor-unknown.js +++ b/test/tick-processor/test-tick-processor-unknown.js @@ -14,7 +14,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 (let i = 0; i < 1000000; i++) { i++;