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:
Rich Trott 2016-02-03 12:27:40 -08:00 committed by James M Snell
parent c714b2e21c
commit 7406cd3a59
17 changed files with 20 additions and 18 deletions

View File

@ -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

View File

@ -327,7 +327,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;

View 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++;

View 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++) {

View 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++) {

View 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' });

View 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');

View 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);

View 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() {