Skip to content

Commit

Permalink
tools: add unescaped regexp dot rule to linter
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mscdex authored and fhinkel committed Mar 29, 2017
1 parent 678480e commit 61ebfa8
Show file tree
Hide file tree
Showing 35 changed files with 214 additions and 47 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ rules:
assert-throws-arguments: [2, { requireTwo: false }]
new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError]
timer-arguments: 2
no-unescaped-regexp-dot: 2

# Global scoped method and vars
globals:
Expand Down
1 change: 1 addition & 0 deletions benchmark/buffers/buffer-base64-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const bench = common.createBenchmark(main, {
function main(conf) {
const n = +conf.n;
const s = 'abcd'.repeat(8 << 20);
// eslint-disable-next-line no-unescaped-regexp-dot
s.match(/./); // Flatten string.
assert.strictEqual(s.length % 4, 0);
const b = Buffer.allocUnsafe(s.length / 4 * 3);
Expand Down
1 change: 1 addition & 0 deletions benchmark/child_process/child-process-exec-stdout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function main(conf) {
const len = +conf.len;

const msg = `"${'.'.repeat(len)}"`;
// eslint-disable-next-line no-unescaped-regexp-dot
msg.match(/./);
const options = {'stdio': ['ignore', 'pipe', 'ignore']};
const child = exec(`yes ${msg}`, options);
Expand Down
2 changes: 1 addition & 1 deletion test/addons/node-module-version/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const re = new RegExp(
'^Error: The module \'.+\'\n' +
'was compiled against a different Node\\.js version using\n' +
'NODE_MODULE_VERSION 42\\. This version of Node\\.js requires\n' +
`NODE_MODULE_VERSION ${process.versions.modules}. ` +
`NODE_MODULE_VERSION ${process.versions.modules}\\. ` +
'Please try re-compiling or re-installing\n' +
'the module \\(for instance, using `npm rebuild` or `npm install`\\)\\.$');

Expand Down
2 changes: 1 addition & 1 deletion test/debugger/test-debugger-repl-break-in-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repl.addTest('restart', [].concat(
],
repl.handshakeLines,
[
/Restoring breakpoint mod.js:2/,
/Restoring breakpoint mod\.js:2/,
/Warning: script 'mod\.js' was not loaded yet\./,
/Restoring breakpoint \).*:\d+/,
/Warning: script '\)[^']*' was not loaded yet\./
Expand Down
2 changes: 1 addition & 1 deletion test/debugger/test-debugger-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ addTest('sb("setInterval()", "!(setInterval.flag++)")', [

// Continue
addTest('c', [
/break in timers.js:\d+/,
/break in timers\.js:\d+/,
/\d/, /\d/, /\d/, /\d/, /\d/
]);

Expand Down
2 changes: 1 addition & 1 deletion test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function checkListResponse(err, response) {
assert.ok(response[0]['devtoolsFrontendUrl']);
assert.ok(
response[0]['webSocketDebuggerUrl']
.match(/ws:\/\/127.0.0.1:\d+\/[0-9A-Fa-f]{8}-/));
.match(/ws:\/\/127\.0\.0\.1:\d+\/[0-9A-Fa-f]{8}-/));
}

function checkVersion(err, response) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ assert.doesNotThrow(function() { assert.ifError(); });

assert.throws(() => {
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
}, /Got unwanted exception. user message/,
}, /Got unwanted exception: user message/,
'a.doesNotThrow ignores user message');

// make sure that validating using constructor really works
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ assert.throws(() => Buffer.allocUnsafe(10).copy(),
/TypeError: argument should be a Buffer/);

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

assert.throws(() => Buffer.from(), regErrorMsg);
assert.throws(() => Buffer.from(null), regErrorMsg);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-crypto-dh.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ ecdh5.setPrivateKey(cafebabeKey, 'hex');
].forEach((element) => {
assert.throws(() => {
ecdh5.setPrivateKey(element, 'hex');
}, /^Error: Private key is not valid for specified curve.$/);
}, /^Error: Private key is not valid for specified curve\.$/);
// Verify object state did not change.
assert.strictEqual(ecdh5.getPrivateKey('hex'), cafebabeKey);
});
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-debug-port-from-cmdline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const child = spawn(process.execPath, args, childOptions);

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

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

if (os.platform() === 'win32') {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-cluster-bind-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (cluster.isMaster) {
const socket = dgram.createSocket('udp4');

socket.on('error', common.mustCall((err) => {
assert(/^Error: bind UNKNOWN 0.0.0.0$/.test(err.toString()));
assert(/^Error: bind UNKNOWN 0\.0\.0\.0$/.test(err.toString()));
process.nextTick(common.mustCall(() => {
assert.strictEqual(socket._bindState, 0); // BIND_STATE_UNBOUND
socket.close();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-write-stream-throw-type-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const fs = require('fs');
const path = require('path');

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-outgoing-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ assert.throws(() => {
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader.call({_header: 'test'}, 'test', 'value');
}, /^Error: Can't set headers after they are sent.$/);
}, /^Error: Can't set headers after they are sent\.$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-response-status-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ testCases.findByPath = function(path) {

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

connection.write(testCase.response);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-https-agent-create-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const options = {
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
};

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

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-internal-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ assert.strictEqual(err5.code, 'TEST_ERROR_1');

assert.throws(
() => new errors.Error('TEST_FOO_KEY'),
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY.$/);
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY\.$/);
// Calling it twice yields same result (using the key does not create it)
assert.throws(
() => new errors.Error('TEST_FOO_KEY'),
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY.$/);
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY\.$/);
assert.throws(
() => new errors.Error(1),
/^AssertionError: 'number' === 'string'$/);
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-internal-util-assertCrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const assert = require('assert');
const util = require('internal/util');

if (!process.versions.openssl) {
assert.throws(() => util.assertCrypto(),
/^Error: Node.js is not compiled with openssl crypto support$/);
assert.throws(
() => util.assertCrypto(),
/^Error: Node\.js is not compiled with openssl crypto support$/
);
} else {
assert.doesNotThrow(() => util.assertCrypto());
}
10 changes: 5 additions & 5 deletions test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ const unixSpecialCaseFormatTests = [

const errors = [
{method: 'parse', input: [null],
message: /^TypeError: Path must be a string. Received null$/},
message: /^TypeError: Path must be a string\. Received null$/},
{method: 'parse', input: [{}],
message: /^TypeError: Path must be a string. Received {}$/},
message: /^TypeError: Path must be a string\. Received {}$/},
{method: 'parse', input: [true],
message: /^TypeError: Path must be a string. Received true$/},
message: /^TypeError: Path must be a string\. Received true$/},
{method: 'parse', input: [1],
message: /^TypeError: Path must be a string. Received 1$/},
message: /^TypeError: Path must be a string\. Received 1$/},
{method: 'parse', input: [],
message: /^TypeError: Path must be a string. Received undefined$/},
message: /^TypeError: Path must be a string\. Received undefined$/},
{method: 'format', input: [null],
message:
/^TypeError: Parameter "pathObject" must be an object, not object$/},
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-process-hrtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ validateTuple(process.hrtime(tuple));
// test that only an Array may be passed to process.hrtime()
assert.throws(() => {
process.hrtime(1);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);
assert.throws(() => {
process.hrtime([]);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);
assert.throws(() => {
process.hrtime([1]);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);
assert.throws(() => {
process.hrtime([1, 2, 3]);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
}, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/);

function validateTuple(tuple) {
assert(Array.isArray(tuple));
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ const qsColonTestCases = [
const extendedFunction = function() {};
extendedFunction.prototype = {a: 'b'};
const qsWeirdObjects = [
// eslint-disable-next-line no-unescaped-regexp-dot
[{regexp: /./g}, 'regexp=', {'regexp': ''}],
// eslint-disable-next-line no-unescaped-regexp-dot
[{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}],
[{fn: function() {}}, 'fn=', {'fn': ''}],
[{fn: new Function('')}, 'fn=', {'fn': ''}],
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-readline-undefined-columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ oStream.on('end', common.mustCall(() => {

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

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

iStream.write('\t');
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-repl-definecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ r.defineCommand('say2', function() {
});

inputStream.write('.help\n');
assert(/\n.say1 help for say1\n/.test(output), 'help for say1 not present');
assert(/\n.say2\n/.test(output), 'help for say2 not present');
assert(/\n\.say1 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');
assert(/> hello node developer/.test(output), 'say1 outputted incorrectly');
inputStream.write('.say2 node developer\n');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const args = ['-i'];
const child = spawn(process.execPath, args);

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

child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-unexpected-token-recoverable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const child = spawn(process.execPath, args);

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

child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function error_test() {
{
client: client_unix,
send: '(function() { "use strict"; if (true) function f() { } })()',
expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block./ // eslint-disable-line max-len
expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block\./ // eslint-disable-line max-len
},
// Named functions can be used:
{ client: client_unix, send: 'function blah() { return 1; }',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-require-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const assert = require('assert');
try {
require(path.join(common.fixturesDir, 'invalid.json'));
} catch (err) {
const re = /test[/\\]fixtures[/\\]invalid.json: Unexpected string/;
const re = /test[/\\]fixtures[/\\]invalid\.json: Unexpected string/;
const i = err.message.match(re);
assert.notStrictEqual(null, i, 'require() json error should include path');
}
4 changes: 2 additions & 2 deletions test/parallel/test-stream-unshift-read-race.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ r._read = function(n) {
function pushError() {
assert.throws(function() {
r.push(Buffer.allocUnsafe(1));
}, /^Error: stream.push\(\) after EOF$/);
}, /^Error: stream\.push\(\) after EOF$/);
}


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

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-vm-cached-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ assert.throws(() => {
new vm.Script('function abc() {}', {
cachedData: 'ohai'
});
}, /^TypeError: options.cachedData must be a Buffer instance$/);
}, /^TypeError: options\.cachedData must be a Buffer instance$/);
2 changes: 1 addition & 1 deletion test/parallel/test-vm-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ assert.throws(function() {
columnOffset: 123
});
}, function(err) {
return /expected-filename.js:33:130/.test(err.stack);
return /expected-filename\.js:33:130/.test(err.stack);
}, 'Expected appearance of proper offset in Error stack');

// https://github.com/nodejs/node/issues/6158
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-vm-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ assert.throws(function() {
};
vm.runInNewContext('runInVM(10)', context, { timeout: 10000 });
throw new Error('Test 5 failed');
}, /Script execution timed out./);
}, /Script execution timed out\./);

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

// Test 7: Nested vm timeouts, inner script throws an error.
assert.throws(function() {
Expand Down
4 changes: 3 additions & 1 deletion test/sequential/test-deprecation-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ execFile(node, traceDep, function(er, stdout, stderr) {
assert.strictEqual(stdout, '');
const stack = stderr.trim().split('\n');
// just check the top and bottom.
assert(/util.debug is deprecated. Use console.error instead./.test(stack[1]));
assert(
/util\.debug is deprecated\. Use console\.error instead\./.test(stack[1])
);
assert(/DEBUG: This is deprecated/.test(stack[0]));
console.log('trace ok');
});
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const my_path = require('../fixtures/path');
assert.ok(my_path.path_func instanceof Function);
// this one does not exist and should throw
assert.throws(function() { require('./utils'); },
/^Error: Cannot find module '.\/utils'$/);
/^Error: Cannot find module '\.\/utils'$/);

let errorThrown = false;
try {
Expand Down Expand Up @@ -318,5 +318,5 @@ assert.strictEqual(42, require('../fixtures/utf8-bom.json'));
assert.throws(function() {
require('../fixtures/test-error-first-line-offset.js');
}, function(err) {
return /test-error-first-line-offset.js:1:/.test(err.stack);
return /test-error-first-line-offset\.js:1:/.test(err.stack);
}, 'Expected appearance of proper offset in Error stack');
2 changes: 1 addition & 1 deletion test/sequential/test-process-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ execFile(node, traceWarn, function(er, stdout, stderr) {
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr));
assert(/at Object\.<anonymous>\s\(.+warnings.js:3:9\)/.test(stderr));
assert(/at Object\.<anonymous>\s\(.+warnings\.js:3:9\)/.test(stderr));
});
Loading

0 comments on commit 61ebfa8

Please sign in to comment.