Skip to content

Commit 61ebfa8

Browse files
mscdexfhinkel
authored andcommitted
tools: add unescaped regexp dot rule to linter
PR-URL: #11834 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 678480e commit 61ebfa8

35 files changed

+214
-47
lines changed

.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ rules:
136136
assert-throws-arguments: [2, { requireTwo: false }]
137137
new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError]
138138
timer-arguments: 2
139+
no-unescaped-regexp-dot: 2
139140

140141
# Global scoped method and vars
141142
globals:

benchmark/buffers/buffer-base64-decode.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const bench = common.createBenchmark(main, {
99
function main(conf) {
1010
const n = +conf.n;
1111
const s = 'abcd'.repeat(8 << 20);
12+
// eslint-disable-next-line no-unescaped-regexp-dot
1213
s.match(/./); // Flatten string.
1314
assert.strictEqual(s.length % 4, 0);
1415
const b = Buffer.allocUnsafe(s.length / 4 * 3);

benchmark/child_process/child-process-exec-stdout.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function main(conf) {
1818
const len = +conf.len;
1919

2020
const msg = `"${'.'.repeat(len)}"`;
21+
// eslint-disable-next-line no-unescaped-regexp-dot
2122
msg.match(/./);
2223
const options = {'stdio': ['ignore', 'pipe', 'ignore']};
2324
const child = exec(`yes ${msg}`, options);

test/addons/node-module-version/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const re = new RegExp(
77
'^Error: The module \'.+\'\n' +
88
'was compiled against a different Node\\.js version using\n' +
99
'NODE_MODULE_VERSION 42\\. This version of Node\\.js requires\n' +
10-
`NODE_MODULE_VERSION ${process.versions.modules}. ` +
10+
`NODE_MODULE_VERSION ${process.versions.modules}\\. ` +
1111
'Please try re-compiling or re-installing\n' +
1212
'the module \\(for instance, using `npm rebuild` or `npm install`\\)\\.$');
1313

test/debugger/test-debugger-repl-break-in-module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ repl.addTest('restart', [].concat(
5454
],
5555
repl.handshakeLines,
5656
[
57-
/Restoring breakpoint mod.js:2/,
57+
/Restoring breakpoint mod\.js:2/,
5858
/Warning: script 'mod\.js' was not loaded yet\./,
5959
/Restoring breakpoint \).*:\d+/,
6060
/Warning: script '\)[^']*' was not loaded yet\./

test/debugger/test-debugger-repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ addTest('sb("setInterval()", "!(setInterval.flag++)")', [
7272

7373
// Continue
7474
addTest('c', [
75-
/break in timers.js:\d+/,
75+
/break in timers\.js:\d+/,
7676
/\d/, /\d/, /\d/, /\d/, /\d/
7777
]);
7878

test/inspector/test-inspector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function checkListResponse(err, response) {
1212
assert.ok(response[0]['devtoolsFrontendUrl']);
1313
assert.ok(
1414
response[0]['webSocketDebuggerUrl']
15-
.match(/ws:\/\/127.0.0.1:\d+\/[0-9A-Fa-f]{8}-/));
15+
.match(/ws:\/\/127\.0\.0\.1:\d+\/[0-9A-Fa-f]{8}-/));
1616
}
1717

1818
function checkVersion(err, response) {

test/parallel/test-assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ assert.doesNotThrow(function() { assert.ifError(); });
406406

407407
assert.throws(() => {
408408
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
409-
}, /Got unwanted exception. user message/,
409+
}, /Got unwanted exception: user message/,
410410
'a.doesNotThrow ignores user message');
411411

412412
// make sure that validating using constructor really works

test/parallel/test-buffer-alloc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ assert.throws(() => Buffer.allocUnsafe(10).copy(),
923923
/TypeError: argument should be a Buffer/);
924924

925925
const regErrorMsg = new RegExp('First argument must be a string, Buffer, ' +
926-
'ArrayBuffer, Array, or array-like object.');
926+
'ArrayBuffer, Array, or array-like object\\.');
927927

928928
assert.throws(() => Buffer.from(), regErrorMsg);
929929
assert.throws(() => Buffer.from(null), regErrorMsg);

test/parallel/test-crypto-dh.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ ecdh5.setPrivateKey(cafebabeKey, 'hex');
301301
].forEach((element) => {
302302
assert.throws(() => {
303303
ecdh5.setPrivateKey(element, 'hex');
304-
}, /^Error: Private key is not valid for specified curve.$/);
304+
}, /^Error: Private key is not valid for specified curve\.$/);
305305
// Verify object state did not change.
306306
assert.strictEqual(ecdh5.getPrivateKey('hex'), cafebabeKey);
307307
});

test/parallel/test-debug-port-from-cmdline.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const child = spawn(process.execPath, args, childOptions);
1111

1212
const reDeprecationWarning = new RegExp(
1313
/^\(node:\d+\) \[DEP0062\] DeprecationWarning: /.source +
14-
/node --debug is deprecated. /.source +
15-
/Please use node --inspect instead.$/.source
14+
/node --debug is deprecated\. /.source +
15+
/Please use node --inspect instead\.$/.source
1616
);
1717

1818
child.stdin.write("process.send({ msg: 'childready' });\n");
@@ -47,9 +47,9 @@ function assertOutputLines() {
4747
// need a var so can swap the first two lines in following
4848
// eslint-disable-next-line no-var
4949
var expectedLines = [
50-
/^Starting debugger agent.$/,
50+
/^Starting debugger agent\.$/,
5151
reDeprecationWarning,
52-
new RegExp(`^Debugger listening on 127.0.0.1:${debugPort}$`)
52+
new RegExp(`^Debugger listening on 127\\.0\\.0\\.1:${debugPort}$`)
5353
];
5454

5555
if (os.platform() === 'win32') {

test/parallel/test-dgram-cluster-bind-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (cluster.isMaster) {
1717
const socket = dgram.createSocket('udp4');
1818

1919
socket.on('error', common.mustCall((err) => {
20-
assert(/^Error: bind UNKNOWN 0.0.0.0$/.test(err.toString()));
20+
assert(/^Error: bind UNKNOWN 0\.0\.0\.0$/.test(err.toString()));
2121
process.nextTick(common.mustCall(() => {
2222
assert.strictEqual(socket._bindState, 0); // BIND_STATE_UNBOUND
2323
socket.close();

test/parallel/test-fs-write-stream-throw-type-error.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const fs = require('fs');
55
const path = require('path');
66

77
const numberError = new RegExp('^TypeError: "options" must be a string ' +
8-
'or an object, got number instead.$');
8+
'or an object, got number instead\\.$');
99

1010
const booleanError = new RegExp('^TypeError: "options" must be a string ' +
11-
'or an object, got boolean instead.$');
11+
'or an object, got boolean instead\\.$');
1212

1313
const example = path.join(common.tmpDir, 'dummy');
1414

test/parallel/test-http-outgoing-proto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ assert.throws(() => {
3333
assert.throws(() => {
3434
const outgoingMessage = new OutgoingMessage();
3535
outgoingMessage.setHeader.call({_header: 'test'}, 'test', 'value');
36-
}, /^Error: Can't set headers after they are sent.$/);
36+
}, /^Error: Can't set headers after they are sent\.$/);
3737

3838
assert.throws(() => {
3939
const outgoingMessage = new OutgoingMessage();

test/parallel/test-http-response-status-message.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ testCases.findByPath = function(path) {
5151

5252
const server = net.createServer(function(connection) {
5353
connection.on('data', function(data) {
54-
const path = data.toString().match(/GET (.*) HTTP.1.1/)[1];
54+
const path = data.toString().match(/GET (.*) HTTP\/1\.1/)[1];
5555
const testCase = testCases.findByPath(path);
5656

5757
connection.write(testCase.response);

test/parallel/test-https-agent-create-connection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const options = {
1818
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
1919
};
2020

21-
const expectedHeader = /^HTTP\/1.1 200 OK/;
21+
const expectedHeader = /^HTTP\/1\.1 200 OK/;
2222
const expectedBody = /hello world\n/;
2323
const expectCertError = /^Error: unable to verify the first certificate$/;
2424

test/parallel/test-internal-errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ assert.strictEqual(err5.code, 'TEST_ERROR_1');
4141

4242
assert.throws(
4343
() => new errors.Error('TEST_FOO_KEY'),
44-
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY.$/);
44+
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY\.$/);
4545
// Calling it twice yields same result (using the key does not create it)
4646
assert.throws(
4747
() => new errors.Error('TEST_FOO_KEY'),
48-
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY.$/);
48+
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY\.$/);
4949
assert.throws(
5050
() => new errors.Error(1),
5151
/^AssertionError: 'number' === 'string'$/);

test/parallel/test-internal-util-assertCrypto.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ const assert = require('assert');
55
const util = require('internal/util');
66

77
if (!process.versions.openssl) {
8-
assert.throws(() => util.assertCrypto(),
9-
/^Error: Node.js is not compiled with openssl crypto support$/);
8+
assert.throws(
9+
() => util.assertCrypto(),
10+
/^Error: Node\.js is not compiled with openssl crypto support$/
11+
);
1012
} else {
1113
assert.doesNotThrow(() => util.assertCrypto());
1214
}

test/parallel/test-path-parse-format.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ const unixSpecialCaseFormatTests = [
9090

9191
const errors = [
9292
{method: 'parse', input: [null],
93-
message: /^TypeError: Path must be a string. Received null$/},
93+
message: /^TypeError: Path must be a string\. Received null$/},
9494
{method: 'parse', input: [{}],
95-
message: /^TypeError: Path must be a string. Received {}$/},
95+
message: /^TypeError: Path must be a string\. Received {}$/},
9696
{method: 'parse', input: [true],
97-
message: /^TypeError: Path must be a string. Received true$/},
97+
message: /^TypeError: Path must be a string\. Received true$/},
9898
{method: 'parse', input: [1],
99-
message: /^TypeError: Path must be a string. Received 1$/},
99+
message: /^TypeError: Path must be a string\. Received 1$/},
100100
{method: 'parse', input: [],
101-
message: /^TypeError: Path must be a string. Received undefined$/},
101+
message: /^TypeError: Path must be a string\. Received undefined$/},
102102
{method: 'format', input: [null],
103103
message:
104104
/^TypeError: Parameter "pathObject" must be an object, not object$/},

test/parallel/test-process-hrtime.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ validateTuple(process.hrtime(tuple));
3535
// test that only an Array may be passed to process.hrtime()
3636
assert.throws(() => {
3737
process.hrtime(1);
38-
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
38+
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);
3939
assert.throws(() => {
4040
process.hrtime([]);
41-
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
41+
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);
4242
assert.throws(() => {
4343
process.hrtime([1]);
44-
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
44+
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);
4545
assert.throws(() => {
4646
process.hrtime([1, 2, 3]);
47-
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
47+
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);
4848

4949
function validateTuple(tuple) {
5050
assert(Array.isArray(tuple));

test/parallel/test-querystring.js

+2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ const qsColonTestCases = [
110110
const extendedFunction = function() {};
111111
extendedFunction.prototype = {a: 'b'};
112112
const qsWeirdObjects = [
113+
// eslint-disable-next-line no-unescaped-regexp-dot
113114
[{regexp: /./g}, 'regexp=', {'regexp': ''}],
115+
// eslint-disable-next-line no-unescaped-regexp-dot
114116
[{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}],
115117
[{fn: function() {}}, 'fn=', {'fn': ''}],
116118
[{fn: new Function('')}, 'fn=', {'fn': ''}],

test/parallel/test-readline-undefined-columns.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ oStream.on('end', common.mustCall(() => {
3535

3636
iStream.write('process.s\t');
3737

38-
assert(/process.std\b/.test(output)); // Completion works.
38+
assert(/process\.std\b/.test(output)); // Completion works.
3939
assert(!/stdout/.test(output)); // Completion doesn’t show all results yet.
4040

4141
iStream.write('\t');

test/parallel/test-repl-definecommand.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ r.defineCommand('say2', function() {
3535
});
3636

3737
inputStream.write('.help\n');
38-
assert(/\n.say1 help for say1\n/.test(output), 'help for say1 not present');
39-
assert(/\n.say2\n/.test(output), 'help for say2 not present');
38+
assert(/\n\.say1 help for say1\n/.test(output),
39+
'help for say1 not present');
40+
assert(/\n\.say2\n/.test(output), 'help for say2 not present');
4041
inputStream.write('.say1 node developer\n');
4142
assert(/> hello node developer/.test(output), 'say1 outputted incorrectly');
4243
inputStream.write('.say2 node developer\n');

test/parallel/test-repl-harmony.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const args = ['-i'];
2828
const child = spawn(process.execPath, args);
2929

3030
const input = '(function(){"use strict"; const y=1;y=2})()\n';
31-
const expectOut = /^> TypeError: Assignment to constant variable.\n/;
31+
const expectOut = /^> TypeError: Assignment to constant variable\.\n/;
3232

3333
child.stderr.setEncoding('utf8');
3434
child.stderr.on('data', function(c) {

test/parallel/test-repl-unexpected-token-recoverable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const child = spawn(process.execPath, args);
1212

1313
const input = 'var foo = "bar\\\nbaz"';
1414
// Match '...' as well since it marks a multi-line statement
15-
const expectOut = /^> ... undefined\n/;
15+
const expectOut = /^> \.\.\. undefined\n/;
1616

1717
child.stderr.setEncoding('utf8');
1818
child.stderr.on('data', function(c) {

test/parallel/test-repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function error_test() {
212212
{
213213
client: client_unix,
214214
send: '(function() { "use strict"; if (true) function f() { } })()',
215-
expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block./ // eslint-disable-line max-len
215+
expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block\./ // eslint-disable-line max-len
216216
},
217217
// Named functions can be used:
218218
{ client: client_unix, send: 'function blah() { return 1; }',

test/parallel/test-require-json.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const assert = require('assert');
2727
try {
2828
require(path.join(common.fixturesDir, 'invalid.json'));
2929
} catch (err) {
30-
const re = /test[/\\]fixtures[/\\]invalid.json: Unexpected string/;
30+
const re = /test[/\\]fixtures[/\\]invalid\.json: Unexpected string/;
3131
const i = err.message.match(re);
3232
assert.notStrictEqual(null, i, 'require() json error should include path');
3333
}

test/parallel/test-stream-unshift-read-race.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ r._read = function(n) {
7070
function pushError() {
7171
assert.throws(function() {
7272
r.push(Buffer.allocUnsafe(1));
73-
}, /^Error: stream.push\(\) after EOF$/);
73+
}, /^Error: stream\.push\(\) after EOF$/);
7474
}
7575

7676

@@ -84,7 +84,7 @@ w._write = function(chunk, encoding, cb) {
8484
r.on('end', common.mustCall(function() {
8585
assert.throws(function() {
8686
r.unshift(Buffer.allocUnsafe(1));
87-
}, /^Error: stream.unshift\(\) after end event$/);
87+
}, /^Error: stream\.unshift\(\) after end event$/);
8888
w.end();
8989
}));
9090

test/parallel/test-vm-cached-data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ assert.throws(() => {
8989
new vm.Script('function abc() {}', {
9090
cachedData: 'ohai'
9191
});
92-
}, /^TypeError: options.cachedData must be a Buffer instance$/);
92+
}, /^TypeError: options\.cachedData must be a Buffer instance$/);

test/parallel/test-vm-context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ assert.throws(function() {
9090
columnOffset: 123
9191
});
9292
}, function(err) {
93-
return /expected-filename.js:33:130/.test(err.stack);
93+
return /expected-filename\.js:33:130/.test(err.stack);
9494
}, 'Expected appearance of proper offset in Error stack');
9595

9696
// https://github.com/nodejs/node/issues/6158

test/parallel/test-vm-timeout.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ assert.throws(function() {
5252
};
5353
vm.runInNewContext('runInVM(10)', context, { timeout: 10000 });
5454
throw new Error('Test 5 failed');
55-
}, /Script execution timed out./);
55+
}, /Script execution timed out\./);
5656

5757
// Test 6: Nested vm timeouts, outer timeout is shorter and fires first.
5858
assert.throws(function() {
@@ -63,7 +63,7 @@ assert.throws(function() {
6363
};
6464
vm.runInNewContext('runInVM(10000)', context, { timeout: 100 });
6565
throw new Error('Test 6 failed');
66-
}, /Script execution timed out./);
66+
}, /Script execution timed out\./);
6767

6868
// Test 7: Nested vm timeouts, inner script throws an error.
6969
assert.throws(function() {

test/sequential/test-deprecation-flags.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ execFile(node, traceDep, function(er, stdout, stderr) {
6161
assert.strictEqual(stdout, '');
6262
const stack = stderr.trim().split('\n');
6363
// just check the top and bottom.
64-
assert(/util.debug is deprecated. Use console.error instead./.test(stack[1]));
64+
assert(
65+
/util\.debug is deprecated\. Use console\.error instead\./.test(stack[1])
66+
);
6567
assert(/DEBUG: This is deprecated/.test(stack[0]));
6668
console.log('trace ok');
6769
});

test/sequential/test-module-loading.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const my_path = require('../fixtures/path');
121121
assert.ok(my_path.path_func instanceof Function);
122122
// this one does not exist and should throw
123123
assert.throws(function() { require('./utils'); },
124-
/^Error: Cannot find module '.\/utils'$/);
124+
/^Error: Cannot find module '\.\/utils'$/);
125125

126126
let errorThrown = false;
127127
try {
@@ -318,5 +318,5 @@ assert.strictEqual(42, require('../fixtures/utf8-bom.json'));
318318
assert.throws(function() {
319319
require('../fixtures/test-error-first-line-offset.js');
320320
}, function(err) {
321-
return /test-error-first-line-offset.js:1:/.test(err.stack);
321+
return /test-error-first-line-offset\.js:1:/.test(err.stack);
322322
}, 'Expected appearance of proper offset in Error stack');

test/sequential/test-process-warnings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ execFile(node, traceWarn, function(er, stdout, stderr) {
2929
assert.strictEqual(er, null);
3030
assert.strictEqual(stdout, '');
3131
assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr));
32-
assert(/at Object\.<anonymous>\s\(.+warnings.js:3:9\)/.test(stderr));
32+
assert(/at Object\.<anonymous>\s\(.+warnings\.js:3:9\)/.test(stderr));
3333
});

0 commit comments

Comments
 (0)