Skip to content

Commit 53cbd05

Browse files
Trottrvagg
authored andcommitted
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: #4772 (comment) PR-URL: #5063 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9c93ea3 commit 53cbd05

17 files changed

+20
-18
lines changed

.eslintrc

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ rules:
8181
space-after-keywords: 2
8282
## no leading/trailing spaces in parens
8383
space-in-parens: [2, "never"]
84+
## no spaces with non-word unary operators, require for word unary operators
85+
space-unary-ops: 2
8486

8587
# ECMAScript 6
8688
# list: http://eslint.org/docs/rules/#ecmascript-6

lib/timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function unrefdHandle() {
318318
Timeout.prototype.unref = function() {
319319
if (this._handle) {
320320
this._handle.unref();
321-
} else if (typeof(this._onTimeout) === 'function') {
321+
} else if (typeof this._onTimeout === 'function') {
322322
var now = Timer.now();
323323
if (!this._idleStart) this._idleStart = now;
324324
var delay = this._idleStart + this._idleTimeout - now;

test/gc/test-http-client-connaborted.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for (var i = 0; i < 10; i++)
4848
getall();
4949

5050
function afterGC() {
51-
countGC ++;
51+
countGC++;
5252
}
5353

5454
var timer;

test/gc/test-http-client-onerror.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function runTest() {
5656
}
5757

5858
function afterGC() {
59-
countGC ++;
59+
countGC++;
6060
}
6161

6262
var timer;

test/gc/test-http-client-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ for (var i = 0; i < 10; i++)
5757
getall();
5858

5959
function afterGC() {
60-
countGC ++;
60+
countGC++;
6161
}
6262

6363
var timer;

test/gc/test-http-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ for (var i = 0; i < 10; i++)
5151
getall();
5252

5353
function afterGC() {
54-
countGC ++;
54+
countGC++;
5555
}
5656

5757
setInterval(status, 1000).unref();

test/gc/test-net-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ for (var i = 0; i < 10; i++)
5757
getall();
5858

5959
function afterGC() {
60-
countGC ++;
60+
countGC++;
6161
}
6262

6363
setInterval(status, 100).unref();

test/parallel/test-child-process-exec-buffer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ var str = 'hello';
1010

1111
// default encoding
1212
exec('echo ' + str, function(err, stdout, stderr) {
13-
assert.ok('string', typeof(stdout), 'Expected stdout to be a string');
14-
assert.ok('string', typeof(stderr), 'Expected stderr to be a string');
13+
assert.ok('string', typeof stdout, 'Expected stdout to be a string');
14+
assert.ok('string', typeof stderr, 'Expected stderr to be a string');
1515
assert.equal(str + os.EOL, stdout);
1616

1717
success_count++;

test/parallel/test-fs-read-stream-inherit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ file.on('close', function() {
5555
var file3 = fs.createReadStream(fn, Object.create({encoding: 'utf8'}));
5656
file3.length = 0;
5757
file3.on('data', function(data) {
58-
assert.equal('string', typeof(data));
58+
assert.equal('string', typeof data);
5959
file3.length += data.length;
6060

6161
for (var i = 0; i < data.length; i++) {

test/parallel/test-fs-read-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ file.on('close', function() {
5555
var file3 = fs.createReadStream(fn, {encoding: 'utf8'});
5656
file3.length = 0;
5757
file3.on('data', function(data) {
58-
assert.equal('string', typeof(data));
58+
assert.equal('string', typeof data);
5959
file3.length += data.length;
6060

6161
for (var i = 0; i < data.length; i++) {

test/parallel/test-http-byteswritten.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var httpServer = http.createServer(function(req, res) {
1616

1717
res.on('finish', function() {
1818
sawFinish = true;
19-
assert(typeof(req.connection.bytesWritten) === 'number');
19+
assert(typeof req.connection.bytesWritten === 'number');
2020
assert(req.connection.bytesWritten > 0);
2121
});
2222
res.writeHead(200, { 'Content-Type': 'text/plain' });

test/parallel/test-http-date-header.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var http = require('http');
66
var testResBody = 'other stuff!\n';
77

88
var server = http.createServer(function(req, res) {
9-
assert.ok(! ('date' in req.headers),
9+
assert.ok(!('date' in req.headers),
1010
'Request headers contained a Date.');
1111
res.writeHead(200, {
1212
'Content-Type': 'text/plain'

test/parallel/test-http-response-multiheaders.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ server.listen(common.PORT, common.mustCall(function() {
5959
http.get(
6060
{port:common.PORT, headers:{'x-num': n}},
6161
common.mustCall(function(res) {
62-
if (++ count === 2) server.close();
62+
if (++count === 2) server.close();
6363
assert.equal(res.headers['content-length'], 1);
6464
for (const name of norepeat) {
6565
assert.equal(res.headers[name], 'A');

test/parallel/test-http-set-trailers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ server.on('listening', function() {
3333

3434
c.on('end', function() {
3535
c.end();
36-
assert.ok(! /x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
36+
assert.ok(!/x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
3737
outstanding_reqs--;
3838
if (outstanding_reqs == 0) {
3939
server.close();

test/parallel/test-https-byteswritten.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var body = 'hello world\n';
1818

1919
var httpsServer = https.createServer(options, function(req, res) {
2020
res.on('finish', function() {
21-
assert(typeof(req.connection.bytesWritten) === 'number');
21+
assert(typeof req.connection.bytesWritten === 'number');
2222
assert(req.connection.bytesWritten > 0);
2323
httpsServer.close();
2424
console.log('ok');

test/parallel/test-vm-debug-context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ assert.throws(function() {
2121
vm.runInDebugContext('(function(f) { f(f) })(function(f) { f(f) })');
2222
}, /RangeError/);
2323

24-
assert.equal(typeof(vm.runInDebugContext('this')), 'object');
25-
assert.equal(typeof(vm.runInDebugContext('Debug')), 'object');
24+
assert.equal(typeof vm.runInDebugContext('this'), 'object');
25+
assert.equal(typeof vm.runInDebugContext('Debug'), 'object');
2626

2727
assert.strictEqual(vm.runInDebugContext(), undefined);
2828
assert.strictEqual(vm.runInDebugContext(0), 0);

test/sequential/test-cluster-listening-port.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (cluster.isMaster) {
1212
// ensure that the port is not 0 or null
1313
assert(port);
1414
// ensure that the port is numerical
15-
assert.strictEqual(typeof(port), 'number');
15+
assert.strictEqual(typeof port, 'number');
1616
worker.kill();
1717
});
1818
process.on('exit', function() {

0 commit comments

Comments
 (0)