tools: lint for spacing around unary operators
Enable `space-unary-ops` in `.eslintrc`. This prohibits things like: i ++ // use `i++` instead typeof(foo) // use `typeof foo` or `typeof (foo)` instead Ref: https://github.com/nodejs/node/pull/4772#discussion_r51732299 PR-URL: https://github.com/nodejs/node/pull/5063 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
c714b2e21c
commit
7406cd3a59
@ -83,6 +83,8 @@ rules:
|
|||||||
space-after-keywords: 2
|
space-after-keywords: 2
|
||||||
## no leading/trailing spaces in parens
|
## no leading/trailing spaces in parens
|
||||||
space-in-parens: [2, "never"]
|
space-in-parens: [2, "never"]
|
||||||
|
## no spaces with non-word unary operators, require for word unary operators
|
||||||
|
space-unary-ops: 2
|
||||||
|
|
||||||
# ECMAScript 6
|
# ECMAScript 6
|
||||||
# list: http://eslint.org/docs/rules/#ecmascript-6
|
# list: http://eslint.org/docs/rules/#ecmascript-6
|
||||||
|
@ -327,7 +327,7 @@ function unrefdHandle() {
|
|||||||
Timeout.prototype.unref = function() {
|
Timeout.prototype.unref = function() {
|
||||||
if (this._handle) {
|
if (this._handle) {
|
||||||
this._handle.unref();
|
this._handle.unref();
|
||||||
} else if (typeof(this._onTimeout) === 'function') {
|
} else if (typeof this._onTimeout === 'function') {
|
||||||
var now = Timer.now();
|
var now = Timer.now();
|
||||||
if (!this._idleStart) this._idleStart = now;
|
if (!this._idleStart) this._idleStart = now;
|
||||||
var delay = this._idleStart + this._idleTimeout - now;
|
var delay = this._idleStart + this._idleTimeout - now;
|
||||||
|
@ -48,7 +48,7 @@ for (var i = 0; i < 10; i++)
|
|||||||
getall();
|
getall();
|
||||||
|
|
||||||
function afterGC() {
|
function afterGC() {
|
||||||
countGC ++;
|
countGC++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var timer;
|
var timer;
|
||||||
|
@ -56,7 +56,7 @@ function runTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function afterGC() {
|
function afterGC() {
|
||||||
countGC ++;
|
countGC++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var timer;
|
var timer;
|
||||||
|
@ -57,7 +57,7 @@ for (var i = 0; i < 10; i++)
|
|||||||
getall();
|
getall();
|
||||||
|
|
||||||
function afterGC() {
|
function afterGC() {
|
||||||
countGC ++;
|
countGC++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var timer;
|
var timer;
|
||||||
|
@ -51,7 +51,7 @@ for (var i = 0; i < 10; i++)
|
|||||||
getall();
|
getall();
|
||||||
|
|
||||||
function afterGC() {
|
function afterGC() {
|
||||||
countGC ++;
|
countGC++;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(status, 1000).unref();
|
setInterval(status, 1000).unref();
|
||||||
|
@ -57,7 +57,7 @@ for (var i = 0; i < 10; i++)
|
|||||||
getall();
|
getall();
|
||||||
|
|
||||||
function afterGC() {
|
function afterGC() {
|
||||||
countGC ++;
|
countGC++;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(status, 100).unref();
|
setInterval(status, 100).unref();
|
||||||
|
@ -10,8 +10,8 @@ var str = 'hello';
|
|||||||
|
|
||||||
// default encoding
|
// default encoding
|
||||||
exec('echo ' + str, function(err, stdout, stderr) {
|
exec('echo ' + str, function(err, stdout, stderr) {
|
||||||
assert.ok('string', typeof(stdout), 'Expected stdout to be a string');
|
assert.ok('string', typeof stdout, 'Expected stdout to be a string');
|
||||||
assert.ok('string', typeof(stderr), 'Expected stderr to be a string');
|
assert.ok('string', typeof stderr, 'Expected stderr to be a string');
|
||||||
assert.equal(str + os.EOL, stdout);
|
assert.equal(str + os.EOL, stdout);
|
||||||
|
|
||||||
success_count++;
|
success_count++;
|
||||||
|
@ -55,7 +55,7 @@ file.on('close', function() {
|
|||||||
var file3 = fs.createReadStream(fn, Object.create({encoding: 'utf8'}));
|
var file3 = fs.createReadStream(fn, Object.create({encoding: 'utf8'}));
|
||||||
file3.length = 0;
|
file3.length = 0;
|
||||||
file3.on('data', function(data) {
|
file3.on('data', function(data) {
|
||||||
assert.equal('string', typeof(data));
|
assert.equal('string', typeof data);
|
||||||
file3.length += data.length;
|
file3.length += data.length;
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
@ -55,7 +55,7 @@ file.on('close', function() {
|
|||||||
var file3 = fs.createReadStream(fn, {encoding: 'utf8'});
|
var file3 = fs.createReadStream(fn, {encoding: 'utf8'});
|
||||||
file3.length = 0;
|
file3.length = 0;
|
||||||
file3.on('data', function(data) {
|
file3.on('data', function(data) {
|
||||||
assert.equal('string', typeof(data));
|
assert.equal('string', typeof data);
|
||||||
file3.length += data.length;
|
file3.length += data.length;
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
@ -16,7 +16,7 @@ var httpServer = http.createServer(function(req, res) {
|
|||||||
|
|
||||||
res.on('finish', function() {
|
res.on('finish', function() {
|
||||||
sawFinish = true;
|
sawFinish = true;
|
||||||
assert(typeof(req.connection.bytesWritten) === 'number');
|
assert(typeof req.connection.bytesWritten === 'number');
|
||||||
assert(req.connection.bytesWritten > 0);
|
assert(req.connection.bytesWritten > 0);
|
||||||
});
|
});
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||||
|
@ -6,7 +6,7 @@ var http = require('http');
|
|||||||
var testResBody = 'other stuff!\n';
|
var testResBody = 'other stuff!\n';
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function(req, res) {
|
||||||
assert.ok(! ('date' in req.headers),
|
assert.ok(!('date' in req.headers),
|
||||||
'Request headers contained a Date.');
|
'Request headers contained a Date.');
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Type': 'text/plain'
|
'Content-Type': 'text/plain'
|
||||||
|
@ -59,7 +59,7 @@ server.listen(common.PORT, common.mustCall(function() {
|
|||||||
http.get(
|
http.get(
|
||||||
{port:common.PORT, headers:{'x-num': n}},
|
{port:common.PORT, headers:{'x-num': n}},
|
||||||
common.mustCall(function(res) {
|
common.mustCall(function(res) {
|
||||||
if (++ count === 2) server.close();
|
if (++count === 2) server.close();
|
||||||
assert.equal(res.headers['content-length'], 1);
|
assert.equal(res.headers['content-length'], 1);
|
||||||
for (const name of norepeat) {
|
for (const name of norepeat) {
|
||||||
assert.equal(res.headers[name], 'A');
|
assert.equal(res.headers[name], 'A');
|
||||||
|
@ -33,7 +33,7 @@ server.on('listening', function() {
|
|||||||
|
|
||||||
c.on('end', function() {
|
c.on('end', function() {
|
||||||
c.end();
|
c.end();
|
||||||
assert.ok(! /x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
|
assert.ok(!/x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
|
||||||
outstanding_reqs--;
|
outstanding_reqs--;
|
||||||
if (outstanding_reqs == 0) {
|
if (outstanding_reqs == 0) {
|
||||||
server.close();
|
server.close();
|
||||||
|
@ -18,7 +18,7 @@ var body = 'hello world\n';
|
|||||||
|
|
||||||
var httpsServer = https.createServer(options, function(req, res) {
|
var httpsServer = https.createServer(options, function(req, res) {
|
||||||
res.on('finish', function() {
|
res.on('finish', function() {
|
||||||
assert(typeof(req.connection.bytesWritten) === 'number');
|
assert(typeof req.connection.bytesWritten === 'number');
|
||||||
assert(req.connection.bytesWritten > 0);
|
assert(req.connection.bytesWritten > 0);
|
||||||
httpsServer.close();
|
httpsServer.close();
|
||||||
console.log('ok');
|
console.log('ok');
|
||||||
|
@ -21,8 +21,8 @@ assert.throws(function() {
|
|||||||
vm.runInDebugContext('(function(f) { f(f) })(function(f) { f(f) })');
|
vm.runInDebugContext('(function(f) { f(f) })(function(f) { f(f) })');
|
||||||
}, /RangeError/);
|
}, /RangeError/);
|
||||||
|
|
||||||
assert.equal(typeof(vm.runInDebugContext('this')), 'object');
|
assert.equal(typeof vm.runInDebugContext('this'), 'object');
|
||||||
assert.equal(typeof(vm.runInDebugContext('Debug')), 'object');
|
assert.equal(typeof vm.runInDebugContext('Debug'), 'object');
|
||||||
|
|
||||||
assert.strictEqual(vm.runInDebugContext(), undefined);
|
assert.strictEqual(vm.runInDebugContext(), undefined);
|
||||||
assert.strictEqual(vm.runInDebugContext(0), 0);
|
assert.strictEqual(vm.runInDebugContext(0), 0);
|
||||||
|
@ -12,7 +12,7 @@ if (cluster.isMaster) {
|
|||||||
// ensure that the port is not 0 or null
|
// ensure that the port is not 0 or null
|
||||||
assert(port);
|
assert(port);
|
||||||
// ensure that the port is numerical
|
// ensure that the port is numerical
|
||||||
assert.strictEqual(typeof(port), 'number');
|
assert.strictEqual(typeof port, 'number');
|
||||||
worker.kill();
|
worker.kill();
|
||||||
});
|
});
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user