diff --git a/.eslintrc.yml b/.eslintrc.yml index 587169c533..8c46adcc68 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -4,5 +4,7 @@ rules: eol-last: error eqeqeq: [error, allow-null] indent: [error, 2, { MemberExpression: "off", SwitchCase: 1 }] + no-cond-assign: error no-trailing-spaces: error no-unused-vars: [error, { vars: all, args: none, ignoreRestSiblings: true }] + yoda: error diff --git a/examples/params/index.js b/examples/params/index.js index f3cd8457eb..11eef51a59 100644 --- a/examples/params/index.js +++ b/examples/params/index.js @@ -32,7 +32,8 @@ app.param(['to', 'from'], function(req, res, next, num, name){ // Load user by id app.param('user', function(req, res, next, id){ - if (req.user = users[id]) { + req.user = users[id] + if (req.user) { next(); } else { next(createError(404, 'failed to find user')); diff --git a/lib/request.js b/lib/request.js index 3f1eeca6c1..8a3bac4667 100644 --- a/lib/request.js +++ b/lib/request.js @@ -242,9 +242,9 @@ req.param = function param(name, defaultValue) { : 'name, default'; deprecate('req.param(' + args + '): Use req.params, req.body, or req.query instead'); - if (null != params[name] && params.hasOwnProperty(name)) return params[name]; - if (null != body[name]) return body[name]; - if (null != query[name]) return query[name]; + if (params[name] != null && params.hasOwnProperty(name)) return params[name]; + if (body[name] != null) return body[name]; + if (query[name] != null) return query[name]; return defaultValue; }; @@ -470,10 +470,10 @@ defineGetter(req, 'fresh', function(){ var status = res.statusCode // GET or HEAD for weak freshness validation only - if ('GET' !== method && 'HEAD' !== method) return false; + if (method !== 'GET' && method !== 'HEAD') return false; // 2xx or 304 as per rfc2616 14.26 - if ((status >= 200 && status < 300) || 304 === status) { + if ((status >= 200 && status < 300) || status === 304) { return fresh(this.headers, { 'etag': res.get('ETag'), 'last-modified': res.get('Last-Modified') diff --git a/lib/response.js b/lib/response.js index fede486c06..01131e0ffe 100644 --- a/lib/response.js +++ b/lib/response.js @@ -210,7 +210,7 @@ res.send = function send(body) { if (req.fresh) this.statusCode = 304; // strip irrelevant headers - if (204 === this.statusCode || 304 === this.statusCode) { + if (this.statusCode === 204 || this.statusCode === 304) { this.removeHeader('Content-Type'); this.removeHeader('Content-Length'); this.removeHeader('Transfer-Encoding'); diff --git a/lib/router/index.js b/lib/router/index.js index abb3a6f589..eb1aa17f8e 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -113,14 +113,15 @@ proto.param = function param(name, fn) { } for (var i = 0; i < len; ++i) { - if (ret = params[i](name, fn)) { + ret = params[i](name, fn) + if (ret) { fn = ret; } } // ensure we end up with a // middleware function - if ('function' !== typeof fn) { + if (typeof fn !== 'function') { throw new Error('invalid param() call for ' + name + ', got ' + fn); } diff --git a/lib/utils.js b/lib/utils.js index 56e12b9b54..6660a3a845 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -54,9 +54,9 @@ exports.wetag = createETagGenerator({ weak: true }) */ exports.isAbsolute = function(path){ - if ('/' === path[0]) return true; - if (':' === path[1] && ('\\' === path[2] || '/' === path[2])) return true; // Windows device path - if ('\\\\' === path.substring(0, 2)) return true; // Microsoft Azure absolute path + if (path[0] === '/') return true; + if (path[1] === ':' && (path[2] === '\\' || path[2] === '/')) return true; // Windows device path + if (path.substring(0, 2) === '\\\\') return true; // Microsoft Azure absolute path }; /** @@ -129,7 +129,7 @@ function acceptParams (str) { for (var i = 1; i < parts.length; ++i) { var pms = parts[i].split(/ *= */); - if ('q' === pms[0]) { + if (pms[0] === 'q') { ret.quality = parseFloat(pms[1]); } else { ret.params[pms[0]] = pms[1]; diff --git a/test/app.param.js b/test/app.param.js index b4ccc8a2d1..76a6d7cc02 100644 --- a/test/app.param.js +++ b/test/app.param.js @@ -12,8 +12,8 @@ describe('app', function(){ app.param(function(name, regexp){ if (Object.prototype.toString.call(regexp) === '[object RegExp]') { // See #1557 return function(req, res, next, val){ - var captures; - if (captures = regexp.exec(String(val))) { + var captures = regexp.exec(String(val)); + if (captures) { req.params[name] = captures[1]; next(); } else {