tools: lint for spacing around unary operators
authorRich Trott <rtrott@gmail.com>
Wed, 3 Feb 2016 20:27:40 +0000 (12:27 -0800)
committerMyles Borins <mborins@us.ibm.com>
Wed, 2 Mar 2016 22:01:11 +0000 (14:01 -0800)
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>
16 files changed:
.eslintrc
lib/timers.js
test/gc/test-http-client-connaborted.js
test/gc/test-http-client-onerror.js
test/gc/test-http-client-timeout.js
test/gc/test-http-client.js
test/gc/test-net-timeout.js
test/parallel/test-child-process-exec-buffer.js
test/parallel/test-fs-read-stream-inherit.js
test/parallel/test-fs-read-stream.js
test/parallel/test-http-byteswritten.js
test/parallel/test-http-date-header.js
test/parallel/test-http-set-trailers.js
test/parallel/test-https-byteswritten.js
test/parallel/test-vm-debug-context.js
test/sequential/test-cluster-listening-port.js

index 5b95af8..6aec251 100644 (file)
--- a/.eslintrc
+++ b/.eslintrc
@@ -83,6 +83,8 @@ rules:
   space-after-keywords: 2
   ## no leading/trailing spaces in parens
   space-in-parens: [2, "never"]
+  ## no spaces with non-word unary operators, require for word unary operators
+  space-unary-ops: 2
 
   # ECMAScript 6
   # list: http://eslint.org/docs/rules/#ecmascript-6
index 8cfd1cb..ec3676a 100644 (file)
@@ -318,7 +318,7 @@ function unrefdHandle() {
 Timeout.prototype.unref = function() {
   if (this._handle) {
     this._handle.unref();
-  } else if (typeof(this._onTimeout) === 'function') {
+  } else if (typeof this._onTimeout === 'function') {
     var now = Timer.now();
     if (!this._idleStart) this._idleStart = now;
     var delay = this._idleStart + this._idleTimeout - now;
index 5accec4..074457a 100644 (file)
@@ -48,7 +48,7 @@ for (var i = 0; i < 10; i++)
   getall();
 
 function afterGC() {
-  countGC ++;
+  countGC++;
 }
 
 var timer;
index e94bde6..2e5ef6a 100644 (file)
@@ -56,7 +56,7 @@ function runTest() {
 }
 
 function afterGC() {
-  countGC ++;
+  countGC++;
 }
 
 var timer;
index 1f87bce..d80cf9c 100644 (file)
@@ -57,7 +57,7 @@ for (var i = 0; i < 10; i++)
   getall();
 
 function afterGC() {
-  countGC ++;
+  countGC++;
 }
 
 var timer;
index 0cceb1e..73f284a 100644 (file)
@@ -51,7 +51,7 @@ for (var i = 0; i < 10; i++)
   getall();
 
 function afterGC() {
-  countGC ++;
+  countGC++;
 }
 
 setInterval(status, 1000).unref();
index 26e0378..24671a6 100644 (file)
@@ -57,7 +57,7 @@ for (var i = 0; i < 10; i++)
   getall();
 
 function afterGC() {
-  countGC ++;
+  countGC++;
 }
 
 setInterval(status, 100).unref();
index a381af9..6f19ac8 100644 (file)
@@ -10,8 +10,8 @@ var str = 'hello';
 
 // default encoding
 exec('echo ' + str, function(err, stdout, stderr) {
-  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 stdout, 'Expected stdout to be a string');
+  assert.ok('string', typeof stderr, 'Expected stderr to be a string');
   assert.equal(str + os.EOL, stdout);
 
   success_count++;
index 2261b26..2b3a2f8 100644 (file)
@@ -55,7 +55,7 @@ file.on('close', function() {
 var file3 = fs.createReadStream(fn, Object.create({encoding: 'utf8'}));
 file3.length = 0;
 file3.on('data', function(data) {
-  assert.equal('string', typeof(data));
+  assert.equal('string', typeof data);
   file3.length += data.length;
 
   for (var i = 0; i < data.length; i++) {
index e6aa997..7cf0cd9 100644 (file)
@@ -55,7 +55,7 @@ file.on('close', function() {
 var file3 = fs.createReadStream(fn, {encoding: 'utf8'});
 file3.length = 0;
 file3.on('data', function(data) {
-  assert.equal('string', typeof(data));
+  assert.equal('string', typeof data);
   file3.length += data.length;
 
   for (var i = 0; i < data.length; i++) {
index fdc407a..41d8f4d 100644 (file)
@@ -16,7 +16,7 @@ var httpServer = http.createServer(function(req, res) {
 
   res.on('finish', function() {
     sawFinish = true;
-    assert(typeof(req.connection.bytesWritten) === 'number');
+    assert(typeof req.connection.bytesWritten === 'number');
     assert(req.connection.bytesWritten > 0);
   });
   res.writeHead(200, { 'Content-Type': 'text/plain' });
index 4c73800..5ed7fc6 100644 (file)
@@ -6,7 +6,7 @@ var http = require('http');
 var testResBody = 'other stuff!\n';
 
 var server = http.createServer(function(req, res) {
-  assert.ok(! ('date' in req.headers),
+  assert.ok(!('date' in req.headers),
             'Request headers contained a Date.');
   res.writeHead(200, {
     'Content-Type': 'text/plain'
index f3ee5b1..000df01 100644 (file)
@@ -33,7 +33,7 @@ server.on('listening', function() {
 
   c.on('end', function() {
     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--;
     if (outstanding_reqs == 0) {
       server.close();
index beef89b..4d42714 100644 (file)
@@ -18,7 +18,7 @@ var body = 'hello world\n';
 
 var httpsServer = https.createServer(options, function(req, res) {
   res.on('finish', function() {
-    assert(typeof(req.connection.bytesWritten) === 'number');
+    assert(typeof req.connection.bytesWritten === 'number');
     assert(req.connection.bytesWritten > 0);
     httpsServer.close();
     console.log('ok');
index 7789ddc..07335fa 100644 (file)
@@ -21,8 +21,8 @@ assert.throws(function() {
   vm.runInDebugContext('(function(f) { f(f) })(function(f) { f(f) })');
 }, /RangeError/);
 
-assert.equal(typeof(vm.runInDebugContext('this')), 'object');
-assert.equal(typeof(vm.runInDebugContext('Debug')), 'object');
+assert.equal(typeof vm.runInDebugContext('this'), 'object');
+assert.equal(typeof vm.runInDebugContext('Debug'), 'object');
 
 assert.strictEqual(vm.runInDebugContext(), undefined);
 assert.strictEqual(vm.runInDebugContext(0), 0);
index aaad1ff..dc048c8 100644 (file)
@@ -12,7 +12,7 @@ if (cluster.isMaster) {
     // ensure that the port is not 0 or null
     assert(port);
     // ensure that the port is numerical
-    assert.strictEqual(typeof(port), 'number');
+    assert.strictEqual(typeof port, 'number');
     worker.kill();
   });
   process.on('exit', function() {