Node.js based forum software built for the modern web
ESlint guard-for-in, no-nested-ternary and operator-linebreak
Peter Jaszkowiak32dc7c23ea9f
diff --git a/.eslintrc b/.eslintrcindex d09a88ac00..65071de80a 100644--- a/.eslintrc+++ b/.eslintrc@@ -83,9 +83,9 @@"no-eq-null": "off","no-redeclare": "off","no-unreachable": "off",- "no-nested-ternary": "off",- "operator-linebreak": "off",- "guard-for-in": "off",+ // "no-nested-ternary": "off",+ // "operator-linebreak": "off",+ // "guard-for-in": "off",// "no-unneeded-ternary": "off",// "no-sequences": "off",// "no-extend-native": "off",diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.jsindex 729c6e42d4..40fed9da2b 100644--- a/public/src/modules/helpers.js+++ b/public/src/modules/helpers.js@@ -1,11 +1,6 @@'use strict';(function (exports) {- // export the class if we are in a Node-like system.- if (typeof module === 'object' && module.exports === exports) {- exports = module.exports/* = SemVer*/;- }-var helpers = {};helpers.displayMenuItem = function (data, index) {@@ -276,12 +271,13 @@});};- // Use the define() function if we're in AMD land- if (typeof define === 'function' && define.amd) {+ // export the class if we are in a Node-like system.+ if (typeof module === 'object' && module.exports === exports) {+ exports = module.exports/* = SemVer*/;+ } else if (typeof define === 'function' && define.amd) {+ // Use the define() function if we're in AMD landdefine('helpers', exports);+ } else if (typeof window === 'object') {+ window.helpers = exports;}-}(- typeof exports === 'object' ? exports :- typeof define === 'function' && define.amd ? {} :- window.helpers = {}-));+}(typeof exports === 'object' ? exports : {}));diff --git a/public/src/modules/settings.js b/public/src/modules/settings.jsindex c11abb2f7b..67dbb8896b 100644--- a/public/src/modules/settings.js+++ b/public/src/modules/settings.js@@ -131,7 +131,11 @@ define('settings', function () {for (var i = 0; i < array.length; i += 1) {var value = array[i];if (trim) {- value = value === true ? 1 : value === false ? 0 : typeof value.trim === 'function' ? value.trim() : value;+ if (value === !!value) {+ value = +value;+ } else if (value && typeof value.trim === 'function') {+ value = value.trim();+ }}if (empty || (value != null ? value.length : void 0)) {cleaned.push(value);diff --git a/public/src/modules/settings/array.js b/public/src/modules/settings/array.jsindex 3a0bdea922..2c96d734be 100644--- a/public/src/modules/settings/array.js+++ b/public/src/modules/settings/array.js@@ -48,13 +48,15 @@ define('settings/array', function () {delete attributes['data-type'];delete attributes.tagName;for (var name in attributes) {- var val = attributes[name];- if (name.search('data-') === 0) {- element.data(name.substring(5), val);- } else if (name.search('prop-') === 0) {- element.prop(name.substring(5), val);- } else {- element.attr(name, val);+ if (attributes.hasOwnProperty(name)) {+ var val = attributes[name];+ if (name.search('data-') === 0) {+ element.data(name.substring(5), val);+ } else if (name.search('prop-') === 0) {+ element.prop(name.substring(5), val);+ } else {+ element.attr(name, val);+ }}}helper.fillField(element, value);diff --git a/public/src/modules/settings/key.js b/public/src/modules/settings/key.jsindex c387b89430..73839a087b 100644--- a/public/src/modules/settings/key.js+++ b/public/src/modules/settings/key.js@@ -118,7 +118,15 @@ define('settings/key', function () {if (key.m) {str += (short ? 'M' : 'Meta') + separator;}- return str + (human ? key.char : key.code ? '#' + key.code : '');++ var out;+ if (human) {+ out = key.char;+ } else if (key.code) {+ out = '#' + key.code || '';+ }++ return str + out;}/**diff --git a/public/src/modules/settings/object.js b/public/src/modules/settings/object.jsindex d7f7bbda23..ed94a8401a 100644--- a/public/src/modules/settings/object.js+++ b/public/src/modules/settings/object.js@@ -30,13 +30,15 @@ define('settings/object', function () {delete attributes['data-type'];delete attributes.tagName;for (var name in attributes) {- var val = attributes[name];- if (name.search('data-') === 0) {- element.data(name.substring(5), val);- } else if (name.search('prop-') === 0) {- element.prop(name.substring(5), val);- } else {- element.attr(name, val);+ if (attributes.hasOwnProperty(name)) {+ var val = attributes[name];+ if (name.search('data-') === 0) {+ element.data(name.substring(5), val);+ } else if (name.search('prop-') === 0) {+ element.prop(name.substring(5), val);+ } else {+ element.attr(name, val);+ }}}helper.fillField(element, value);@@ -80,17 +82,19 @@ define('settings/object', function () {}if (Array.isArray(properties)) {for (propertyIndex in properties) {- attributes = properties[propertyIndex];- if (typeof attributes !== 'object') {- attributes = {};- }- propertyName = attributes['data-prop'] || attributes['data-property'] || propertyIndex;- if (value[propertyName] === void 0 && attributes['data-new'] !== void 0) {- value[propertyName] = attributes['data-new'];+ if (properties.hasOwnProperty(propertyIndex)) {+ attributes = properties[propertyIndex];+ if (typeof attributes !== 'object') {+ attributes = {};+ }+ propertyName = attributes['data-prop'] || attributes['data-property'] || propertyIndex;+ if (value[propertyName] === void 0 && attributes['data-new'] !== void 0) {+ value[propertyName] = attributes['data-new'];+ }+ addObjectPropertyElement(element, key, attributes, propertyName, value[propertyName], separator.clone(), function (el) {+ element.append(el);+ });}- addObjectPropertyElement(element, key, attributes, propertyName, value[propertyName], separator.clone(), function (el) {- element.append(el);- });}}},diff --git a/src/controllers/admin/info.js b/src/controllers/admin/info.jsindex 96783a9c87..572dcd93c2 100644--- a/src/controllers/admin/info.js+++ b/src/controllers/admin/info.js@@ -22,7 +22,13 @@ infoController.get = function (req, res, next) {data.push(info[key]);});data.sort(function (a, b) {- return (a.os.hostname < b.os.hostname) ? -1 : (a.os.hostname > b.os.hostname) ? 1 : 0;+ if (a.os.hostname < b.os.hostname) {+ return -1;+ }+ if (a.os.hostname > b.os.hostname) {+ return 1;+ }+ return 0;});res.render('admin/development/info', { info: data, infoJSON: JSON.stringify(data, null, 4), host: os.hostname(), port: nconf.get('port') });}, 500);diff --git a/src/plugins.js b/src/plugins.jsindex dd2423f70f..915f9fdca6 100644--- a/src/plugins.js+++ b/src/plugins.js@@ -256,7 +256,7 @@ var middleware;apiReturn[i].id = apiReturn[i].name;apiReturn[i].installed = false;apiReturn[i].active = false;- apiReturn[i].url = apiReturn[i].url ? apiReturn[i].url : apiReturn[i].repository ? apiReturn[i].repository.url : '';+ apiReturn[i].url = apiReturn[i].url || (apiReturn[i].repository ? apiReturn[i].repository.url : '');pluginMap[apiReturn[i].name] = apiReturn[i];}diff --git a/src/posts/flags.js b/src/posts/flags.jsindex 4bab4cc771..214a155278 100644--- a/src/posts/flags.js+++ b/src/posts/flags.js@@ -240,29 +240,31 @@ module.exports = function (Posts) {// Parse out flag data into its own object inside each post hashasync.map(posts, function (postObj, next) {for (var prop in postObj) {- postObj.flagData = postObj.flagData || {};-- if (postObj.hasOwnProperty(prop) && prop.startsWith('flag:')) {- postObj.flagData[prop.slice(5)] = postObj[prop];-- if (prop === 'flag:state') {- switch (postObj[prop]) {- case 'open':- postObj.flagData.labelClass = 'info';- break;- case 'wip':- postObj.flagData.labelClass = 'warning';- break;- case 'resolved':- postObj.flagData.labelClass = 'success';- break;- case 'rejected':- postObj.flagData.labelClass = 'danger';- break;+ if (postObj.hasOwnProperty(prop)) {+ postObj.flagData = postObj.flagData || {};++ if (prop.startsWith('flag:')) {+ postObj.flagData[prop.slice(5)] = postObj[prop];++ if (prop === 'flag:state') {+ switch (postObj[prop]) {+ case 'open':+ postObj.flagData.labelClass = 'info';+ break;+ case 'wip':+ postObj.flagData.labelClass = 'warning';+ break;+ case 'resolved':+ postObj.flagData.labelClass = 'success';+ break;+ case 'rejected':+ postObj.flagData.labelClass = 'danger';+ break;+ }}- }- delete postObj[prop];+ delete postObj[prop];+ }}}