From a0a50677da13e303d800c75fb20ccd5c9f7e7b62 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Sat, 18 Feb 2017 14:00:29 -0700
Subject: [PATCH] ESlint n-loop-func, yoda
---
.eslintrc | 6 +++---
public/src/overrides.js | 2 +-
public/src/utils.js | 6 +++---
src/controllers/accounts/settings.js | 8 ++++----
src/middleware/render.js | 4 ++--
src/socket.io/categories.js | 17 ++++++++---------
6 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index 1def8e8e04..1bd5d05c88 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -49,6 +49,7 @@
"no-restricted-syntax": "off",
"no-shadow": "off",
"no-script-url": "off",
+ "no-use-before-define": "off",
// "linebreak-style": "off",
// "one-var": "off",
@@ -74,9 +75,8 @@
"block-scoped-var": "off",
"operator-assignment": "off",
"default-case": "off",
- "yoda": "off",
- "no-use-before-define": "off",
- "no-loop-func": "off",
+ // "yoda": "off",
+ // "no-loop-func": "off",
// "no-void": "off",
// "valid-jsdoc": "off",
// "no-cond-assign": "off",
diff --git a/public/src/overrides.js b/public/src/overrides.js
index e1e192274a..144fb63ef3 100644
--- a/public/src/overrides.js
+++ b/public/src/overrides.js
@@ -3,7 +3,7 @@
var overrides = overrides || {};
-if ('undefined' !== typeof window) {
+if (typeof window !== 'undefined') {
(function ($) {
require(['translator'], function (translator) {
$.fn.getCursorPosition = function () {
diff --git a/public/src/utils.js b/public/src/utils.js
index 9d4692668d..292ba3694a 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -5,7 +5,7 @@
var fs;
var XRegExp;
- if ('undefined' === typeof window) {
+ if (typeof window === 'undefined') {
fs = require('fs');
XRegExp = require('xregexp');
@@ -448,7 +448,7 @@
},
};
- if ('undefined' !== typeof window) {
+ if (typeof window !== 'undefined') {
window.utils = module.exports;
}
@@ -479,7 +479,7 @@
return this.replace(/\s+$/g, '');
};
}
-}('undefined' === typeof module ? {
+}(typeof module === 'undefined' ? {
module: {
exports: {},
},
diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js
index c35658b08f..974e20c0dc 100644
--- a/src/controllers/accounts/settings.js
+++ b/src/controllers/accounts/settings.js
@@ -75,10 +75,10 @@ settingsController.get = function (req, res, callback) {
}
userData.dailyDigestFreqOptions = [
- { value: 'off', name: '[[user:digest_off]]', selected: 'off' === userData.settings.dailyDigestFreq },
- { value: 'day', name: '[[user:digest_daily]]', selected: 'day' === userData.settings.dailyDigestFreq },
- { value: 'week', name: '[[user:digest_weekly]]', selected: 'week' === userData.settings.dailyDigestFreq },
- { value: 'month', name: '[[user:digest_monthly]]', selected: 'month' === userData.settings.dailyDigestFreq },
+ { value: 'off', name: '[[user:digest_off]]', selected: userData.settings.dailyDigestFreq === 'off' },
+ { value: 'day', name: '[[user:digest_daily]]', selected: userData.settings.dailyDigestFreq === 'day' },
+ { value: 'week', name: '[[user:digest_weekly]]', selected: userData.settings.dailyDigestFreq === 'week' },
+ { value: 'month', name: '[[user:digest_monthly]]', selected: userData.settings.dailyDigestFreq === 'month' },
];
diff --git a/src/middleware/render.js b/src/middleware/render.js
index 9109e8daaf..48d4a0b526 100644
--- a/src/middleware/render.js
+++ b/src/middleware/render.js
@@ -23,11 +23,11 @@ module.exports = function (middleware) {
};
options = options || {};
- if ('function' === typeof options) {
+ if (typeof options === 'function') {
fn = options;
options = {};
}
- if ('function' !== typeof fn) {
+ if (typeof fn !== 'function') {
fn = defaultFn;
}
diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js
index 2c0ef102b4..b1c95af7e9 100644
--- a/src/socket.io/categories.js
+++ b/src/socket.io/categories.js
@@ -204,16 +204,15 @@ function ignoreOrWatch(fn, socket, cid, callback) {
// filter to subcategories of cid
- var any = true;
- while (any) {
- any = false;
- categoryData.forEach(function (c) {
- if (cids.indexOf(c.cid) === -1 && cids.indexOf(c.parentCid) !== -1) {
- cids.push(c.cid);
- any = true;
- }
+ var cat;
+ do {
+ cat = categoryData.find(function (c) {
+ return cids.indexOf(c.cid) === -1 && cids.indexOf(c.parentCid) !== -1;
});
- }
+ if (cat) {
+ cids.push(cat.cid);
+ }
+ } while (cat);
async.each(cids, function (cid, next) {
fn(socket.uid, cid, next);