From e514ce57b5dfba541564828ef6373c0912a9f7cd Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sun, 8 Jul 2018 10:47:56 +0300 Subject: [WebUI] Avoid using "undefined" property of the global object --- .eslintrc.json | 1 - interface/js/app/graph.js | 2 +- interface/js/app/history.js | 6 +++--- interface/js/app/rspamd.js | 12 ++++++------ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c5f2bc59c..71e2b443d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -78,7 +78,6 @@ "no-redeclare": "off", "no-shadow": "off", "no-undef": "off", - "no-undefined": "off", "no-underscore-dangle": "off", "no-use-before-define": "off", "one-var-declaration-per-line": "off", diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index de90c4a73..c5fba91b1 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -205,7 +205,7 @@ define(["jquery", "d3evolution", "footable"], drawRrdTable(rrd_summary, unit); } - if (graphs.graph === undefined) { + if (!graphs.graph) { graphs.graph = initGraph(); } diff --git a/interface/js/app/history.js b/interface/js/app/history.js index e89108185..7677550bd 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -612,7 +612,7 @@ define(["jquery", "footable", "humanize"], }); } else if (ft.history) { ft.history.destroy(); - ft.history = undefined; + delete ft.history; } }); } @@ -676,11 +676,11 @@ define(["jquery", "footable", "humanize"], } if (ft.history) { ft.history.destroy(); - ft.history = undefined; + delete ft.history; } if (ft.errors) { ft.errors.destroy(); - ft.errors = undefined; + delete ft.errors; } if (checked_server === "All SERVERS") { rspamd.queryNeighbours("errors", function () { diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index c60c5889d..9b29ffd6d 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -47,27 +47,27 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, function disconnect() { if (graphs.chart) { graphs.chart.destroy(); - graphs.chart = undefined; + delete graphs.chart; } if (graphs.rrd_pie) { graphs.rrd_pie.destroy(); - graphs.rrd_pie = undefined; + delete graphs.rrd_pie; } if (graphs.graph) { graphs.graph.destroy(); - graphs.graph = undefined; + delete graphs.graph; } if (tables.history) { tables.history.destroy(); - tables.history = undefined; + delete tables.history; } if (tables.errors) { tables.errors.destroy(); - tables.errors = undefined; + delete tables.errors; } if (tables.symbols) { tables.symbols.destroy(); - tables.symbols = undefined; + delete tables.symbols; } stopTimers(); -- cgit v1.2.3 From 97f21fc116b5c2bb416d8bd212a2ee06ddceee68 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sun, 8 Jul 2018 11:58:27 +0300 Subject: [WebUI] Fix variable assignment I think `var full = shrt = "";` is `var full = (shrt = "");` effectively, so `full = true`. --- .eslintrc.json | 1 - interface/js/app/history.js | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 71e2b443d..2c32e16a7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -72,7 +72,6 @@ "no-implicit-coercion": "off", "no-inline-comments": "off", "no-loop-func": "off", - "no-multi-assign": "off", "no-negated-condition": "off", "no-param-reassign": "off", "no-redeclare": "off", diff --git a/interface/js/app/history.js b/interface/js/app/history.js index 7677550bd..4a8cddb0c 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -137,7 +137,8 @@ define(["jquery", "footable", "humanize"], return (l > rcpt_lim) ? " … (" + l + ")" : ""; } function format_rcpt(smtp, mime) { - var full = shrt = ""; + var full = ""; + var shrt = ""; if (smtp) { full = "[" + item.rcpt_smtp.join(", ") + "] "; shrt = "[" + item.rcpt_smtp.slice(0, rcpt_lim).join(",​") + more("rcpt_smtp") + "]"; -- cgit v1.2.3 From 9819f6a164133a8d8774265bb323e12bf8ce7300 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sun, 8 Jul 2018 12:01:18 +0300 Subject: [WebUI] Add missed declarations --- interface/js/app/history.js | 4 ++-- interface/js/app/stats.js | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/interface/js/app/history.js b/interface/js/app/history.js index 4a8cddb0c..be2471c57 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -39,13 +39,13 @@ define(["jquery", "footable", "humanize"], var htmlEscaper = /[&<>"'/`=]/g; var symbolDescriptions = {}; - EscapeHTML = function (string) { + var EscapeHTML = function (string) { return ("" + string).replace(htmlEscaper, function (match) { return htmlEscapes[match]; }); }; - escape_HTML_array = function (arr) { + var escape_HTML_array = function (arr) { arr.forEach(function (d, i) { arr[i] = EscapeHTML(d); }); }; diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js index c75b20441..a074d47f8 100644 --- a/interface/js/app/stats.js +++ b/interface/js/app/stats.js @@ -27,12 +27,13 @@ define(["jquery", "d3pie", "humanize"], // @ ms to date function msToTime(seconds) { /* eslint-disable no-bitwise */ - years = seconds / 31536000 >> 0; // 3600*24*365 - months = seconds % 31536000 / 2628000 >> 0; // 3600*24*365/12 - days = seconds % 31536000 % 2628000 / 86400 >> 0; // 24*3600 - hours = seconds % 31536000 % 2628000 % 86400 / 3600 >> 0; - minutes = seconds % 31536000 % 2628000 % 86400 % 3600 / 60 >> 0; + var years = seconds / 31536000 >> 0; // 3600*24*365 + var months = seconds % 31536000 / 2628000 >> 0; // 3600*24*365/12 + var days = seconds % 31536000 % 2628000 / 86400 >> 0; // 24*3600 + var hours = seconds % 31536000 % 2628000 % 86400 / 3600 >> 0; + var minutes = seconds % 31536000 % 2628000 % 86400 % 3600 / 60 >> 0; /* eslint-enable no-bitwise */ + var out; if (years > 0) { if (months > 0) { out = years + "yr " + months + "mth"; -- cgit v1.2.3 From 28401018a84cb1d526ab334ecdf44584a064bb6a Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sun, 8 Jul 2018 12:19:17 +0300 Subject: [WebUI] Remove unused variable --- interface/js/app/rspamd.js | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 9b29ffd6d..8f6bc412b 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -144,7 +144,6 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, $("#historyLog tbody").remove(); $("#errorsLog tbody").remove(); $("#symbolsTable tbody").remove(); - password = ""; } function isLogged() { -- cgit v1.2.3 From 4d2b29abcbe0f61cdf89af0d92cec0003d325a81 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sun, 8 Jul 2018 12:21:37 +0300 Subject: [Test] Specify JS Globals --- .eslintrc.json | 4 +++- interface/js/app/config.js | 4 +++- interface/js/app/graph.js | 2 ++ interface/js/app/history.js | 2 ++ interface/js/app/rspamd.js | 3 +++ interface/js/app/symbols.js | 2 ++ interface/js/main.js | 4 +++- 7 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2c32e16a7..32530cd18 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,6 +3,9 @@ "browser": true }, "extends": "eslint:all", + "globals": { + "define": false + }, "rules": { "array-bracket-newline": ["error", "consistent"], "camelcase": "off", @@ -76,7 +79,6 @@ "no-param-reassign": "off", "no-redeclare": "off", "no-shadow": "off", - "no-undef": "off", "no-underscore-dangle": "off", "no-use-before-define": "off", "one-var-declaration-per-line": "off", diff --git a/interface/js/app/config.js b/interface/js/app/config.js index fe9d27a16..a64e8f3ab 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -22,6 +22,8 @@ THE SOFTWARE. */ +/* global $span:true, $tbody:true */ + define(["jquery"], function ($) { var interface = {}; @@ -240,7 +242,7 @@ define(["jquery"], $("#modalTitle").html(item.uri); $("#" + item.map).first().show(); $("#modalDialog .progress").hide(); - $("#modalDialog").modal(show = true, backdrop = true, keyboard = show); + $("#modalDialog").modal({backdrop: true, keyboard: "show", show: true}); if (item.editable === false) { $("#modalSave").hide(); $("#modalSaveAll").hide(); diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index c5fba91b1..6a63500fc 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -23,6 +23,8 @@ THE SOFTWARE. */ +/* global d3:false */ + define(["jquery", "d3evolution", "footable"], function ($, D3Evolution) { var rrd_pie_config = { diff --git a/interface/js/app/history.js b/interface/js/app/history.js index be2471c57..8147c39a1 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -22,6 +22,8 @@ THE SOFTWARE. */ +/* global FooTable:false */ + define(["jquery", "footable", "humanize"], function ($, _, Humanize) { var interface = {}; diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 8f6bc412b..b935cf6c2 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -22,6 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +/* global jQuery:false, Visibility:false */ + define(["jquery", "d3pie", "visibility", "app/stats", "app/graph", "app/config", "app/symbols", "app/history", "app/upload"], function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js index 358deb0e5..a639127f4 100644 --- a/interface/js/app/symbols.js +++ b/interface/js/app/symbols.js @@ -22,6 +22,8 @@ THE SOFTWARE. */ +/* global FooTable:false */ + define(["jquery", "footable"], function ($) { var interface = {}; diff --git a/interface/js/main.js b/interface/js/main.js index af7c63b83..515645667 100644 --- a/interface/js/main.js +++ b/interface/js/main.js @@ -1,3 +1,5 @@ +/* global d3:false, require:false, requirejs:false */ // eslint-disable-line no-unused-vars + requirejs.config({ baseUrl: "js/lib", paths: { @@ -26,7 +28,7 @@ document.title = window.location.hostname + " - Rspamd Web Interface"; define("d3.global", ["d3"], function (_) { - d3 = _; + d3 = _; // eslint-disable-line no-global-assign }); // Load main UI -- cgit v1.2.3