diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-11-21 16:20:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-21 16:20:26 +0000 |
commit | c9d4f710c06457fc1d366c09ae1975a7d3004944 (patch) | |
tree | 74c111256ad419c5744b9d0196910fdebefad2d6 | |
parent | 9fa95f12a66c773f1d2bcda7cb2d2034f1a5b22c (diff) | |
parent | eab17b201a5ec7cbe13c15a7cf2b1bbd9480816a (diff) | |
download | rspamd-c9d4f710c06457fc1d366c09ae1975a7d3004944.tar.gz rspamd-c9d4f710c06457fc1d366c09ae1975a7d3004944.zip |
Merge pull request #4712 from moisseev/webui
[Minor] Use consistent object key/value spacing
-rw-r--r-- | .eslintrc.json | 16 | ||||
-rw-r--r-- | interface/js/app/config.js | 2 | ||||
-rw-r--r-- | interface/js/app/graph.js | 18 | ||||
-rw-r--r-- | interface/js/app/history.js | 35 | ||||
-rw-r--r-- | interface/js/app/rspamd.js | 20 | ||||
-rw-r--r-- | interface/js/app/stats.js | 10 | ||||
-rw-r--r-- | interface/js/app/symbols.js | 34 | ||||
-rw-r--r-- | interface/js/app/upload.js | 6 | ||||
-rw-r--r-- | interface/js/main.js | 20 |
9 files changed, 77 insertions, 84 deletions
diff --git a/.eslintrc.json b/.eslintrc.json index a8cc237e0..5ae3238ea 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,11 +18,8 @@ "capitalized-comments": "off", "curly": ["error", "multi-line"], "func-names": "off", - // "func-style": ["error", "declaration"], + "func-style": ["error", "declaration"], "id-length": ["error", { "min": 1 }], - // "@stylistic/key-spacing": ["error", { - // "singleLine": { "afterColon": false } - // }], "line-comment-position": "off", "logical-assignment-operators": ["error", "never"], "max-params": ["warn", 6], @@ -35,9 +32,8 @@ "no-plusplus": "off", "no-ternary": "off", "object-shorthand": "off", - "one-var": "off", + "one-var": ["error", { "initialized": "never" }], "prefer-arrow-callback": "off", - "prefer-destructuring": "off", "prefer-named-capture-group": "off", "prefer-object-has-own": "off", "prefer-spread": "off", @@ -57,7 +53,7 @@ "@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 5 }], "@stylistic/no-extra-parens": ["error", "functions"], "@stylistic/object-property-newline": ["error", { "allowAllPropertiesOnSameLine": true }], - "@stylistic/padded-blocks": "off", + "@stylistic/padded-blocks": ["error", "never"], "@stylistic/quote-props" : ["error", "consistent-as-needed"], "@stylistic/quotes": ["error", "double", { "avoidEscape": true }], "@stylistic/semi": ["error", "always"], @@ -68,16 +64,12 @@ // Temporarily disabled rules - "func-style": "off", "max-lines": "off", "max-lines-per-function": "off", "no-invalid-this": "off", "prefer-exponentiation-operator": "off", "sort-keys": "off", - "sort-vars": "off", - "@stylistic/function-paren-newline": "off", - "@stylistic/key-spacing": "off", - "@stylistic/one-var-declaration-per-line": "off" + "@stylistic/function-paren-newline": "off" } } diff --git a/interface/js/app/config.js b/interface/js/app/config.js index e0adb365b..9f62c97db 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -120,7 +120,7 @@ define(["jquery", "app/rspamd"], $listmaps.closest(".card").hide(); rspamd.query("maps", { success: function (json) { - const data = json[0].data; + const [{data}] = json; $listmaps.empty(); $("#modalBody").empty(); const $tbody = $("<tbody>"); diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index 154317fd7..a661d4a19 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -132,12 +132,12 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"], enabled: true }, columns: [ - {name:"label", title:"Action"}, - {name:"value", title:"Messages", defaultContent:""}, - {name:"min", title:"Minimum, <span class=\"unit\">" + unit + "</span>", defaultContent:""}, - {name:"avg", title:"Average, <span class=\"unit\">" + unit + "</span>", defaultContent:""}, - {name:"max", title:"Maximum, <span class=\"unit\">" + unit + "</span>", defaultContent:""}, - {name:"last", title:"Last, " + unit}, + {name: "label", title: "Action"}, + {name: "value", title: "Messages", defaultContent: ""}, + {name: "min", title: "Minimum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, + {name: "avg", title: "Average, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, + {name: "max", title: "Maximum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, + {name: "last", title: "Last, " + unit}, ], rows: rows.map(function (curr, i) { return { @@ -163,7 +163,7 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"], } function updateWidgets(data) { - let rrd_summary = {rows:[]}; + let rrd_summary = {rows: []}; let unit = "msg/s"; if (data) { @@ -209,7 +209,7 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"], .map(function (d) { return d.data; }); if (neighbours_data.length === 1) { - data = neighbours_data[0]; + [data] = neighbours_data; } else { let time_match = true; neighbours_data.reduce(function (res, curr, _, arr) { @@ -241,7 +241,7 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"], complete: function () { $("#refresh").removeAttr("disabled").removeClass("disabled"); }, errorMessage: "Cannot receive throughput data", errorOnceId: "alerted_graph_", - data: {type:type} + data: {type: type} }); }; diff --git a/interface/js/app/history.js b/interface/js/app/history.js index 66e94a989..568c69763 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -33,9 +33,7 @@ define(["jquery", "app/rspamd", "d3", "footable"], function process_history_legacy(data) { const items = []; - const compare = function (e1, e2) { - return e1.name.localeCompare(e2.name); - }; + function compare(e1, e2) { return e1.name.localeCompare(e2.name); } $("#selSymOrder_history, label[for='selSymOrder_history']").hide(); @@ -59,7 +57,7 @@ define(["jquery", "app/rspamd", "d3", "footable"], items.push(item); }); - return {items:items}; + return {items: items}; } function columns_v2() { @@ -342,7 +340,7 @@ define(["jquery", "app/rspamd", "d3", "footable"], .map(function (d) { return d.data; }); if (neighbours_data.length && !differentVersions(neighbours_data)) { let data = {}; - const version = neighbours_data[0].version; + const [{version}] = neighbours_data; if (version) { data.rows = [].concat.apply([], neighbours_data .map(function (e) { @@ -356,7 +354,7 @@ define(["jquery", "app/rspamd", "d3", "footable"], $("#legacy-history-badge").show(); } const o = process_history_data(data); - const items = o.items; + const {items} = o; rspamd.symbols.history = o.symbols; if (Object.prototype.hasOwnProperty.call(rspamd.tables, "history") && @@ -382,22 +380,23 @@ define(["jquery", "app/rspamd", "d3", "footable"], function initErrorsTable(rows) { rspamd.tables.errors = FooTable.init("#errorsLog", { columns: [ - { - sorted: true, + {sorted: true, direction: "DESC", name: "ts", title: "Time", style: {"font-size": "11px", "width": 300, "maxWidth": 300}, - sortValue: function (val) { return Number(val.options.sortValue); } - }, - {name:"type", - title:"Worker type", - breakpoints:"xs sm", - style:{"font-size":"11px", "width":150, "maxWidth":150}}, - {name:"pid", title:"PID", breakpoints:"xs sm", style:{"font-size":"11px", "width":110, "maxWidth":110}}, - {name:"module", title:"Module", style:{"font-size":"11px"}}, - {name:"id", title:"Internal ID", style:{"font-size":"11px"}}, - {name:"message", title:"Message", breakpoints:"xs sm", style:{"font-size":"11px"}}, + sortValue: function (val) { return Number(val.options.sortValue); }}, + {name: "type", + title: "Worker type", + breakpoints: "xs sm", + style: {"font-size": "11px", "width": 150, "maxWidth": 150}}, + {name: "pid", + title: "PID", + breakpoints: "xs sm", + style: {"font-size": "11px", "width": 110, "maxWidth": 110}}, + {name: "module", title: "Module", style: {"font-size": "11px"}}, + {name: "id", title: "Internal ID", style: {"font-size": "11px"}}, + {name: "message", title: "Message", breakpoints: "xs sm", style: {"font-size": "11px"}}, ], rows: rows, paging: { diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index ed732449d..64eab27a0 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -276,7 +276,6 @@ function ($, NProgress) { if (changeTablePageSize && $("#historyTable_" + table + " tbody").is(":parent")) { // Table is not empty - clearTimeout(pageSizeTimerId); const t = FooTable.get("#historyTable_" + table); if (t) { @@ -339,7 +338,7 @@ function ($, NProgress) { $("#preloader").addClass("d-none"); $("#navBar, #mainUI").removeClass("d-none"); - $(".nav-tabs-sticky").stickyTabs({initialTab:"#status_nav"}); + $(".nav-tabs-sticky").stickyTabs({initialTab: "#status_nav"}); }, errorMessage: "Cannot get server status", server: "All SERVERS" @@ -366,7 +365,7 @@ function ($, NProgress) { const req_params = { jsonp: false, data: o.data, - headers: $.extend({Password:getPassword()}, o.headers), + headers: $.extend({Password: getPassword()}, o.headers), url: neighbours_status[ind].url + req_url, xhr: function () { const xhr = $.ajaxSettings.xhr(); @@ -493,7 +492,7 @@ function ($, NProgress) { Password: password }, success: function (json) { - const data = json[0].data; + const [{data}] = json; $("#connectPassword").val(""); if (data.auth === "ok") { sessionStorage.setItem("read_only", data.read_only); @@ -564,7 +563,7 @@ function ($, NProgress) { if (o.server === "All SERVERS") { queryServer(neighbours_status, 0, "neighbours", { success: function (json) { - const data = json[0].data; + const [{data}] = json; if (jQuery.isEmptyObject(data)) { neighbours = { local: { @@ -658,7 +657,8 @@ function ($, NProgress) { }, $create: function () { this._super(); - const self = this, $form_grp = $("<div/>", { + const self = this; + const $form_grp = $("<div/>", { class: "form-group d-inline-flex align-items-center" }).append($("<label/>", { class: "sr-only", @@ -695,7 +695,7 @@ function ($, NProgress) { }); }, _onStatusDropdownChanged: function (e) { - const self = e.data.self; + const {self} = e.data; const selected = self.$action.val(); if (selected !== self.def) { const not = self.$not.is(":checked"); @@ -853,7 +853,7 @@ function ($, NProgress) { full += item.rcpt_mime.join(", "); shrt += item.rcpt_mime.slice(0, rcpt_lim).join(",​") + more("rcpt_mime"); } - return {full:full, shrt:shrt}; + return {full: full, shrt: shrt}; } function get_symbol_class(name, score) { @@ -920,7 +920,7 @@ function ($, NProgress) { items.push(item); }); - return {items:items, symbols:unsorted_symbols}; + return {items: items, symbols: unsorted_symbols}; }; ui.waitForRowsDisplayed = function (table, rows_total, callback, iteration) { @@ -1054,7 +1054,7 @@ function ($, NProgress) { $(".dropdown-menu a").click(function (e) { e.preventDefault(); const classList = $(this).attr("class"); - const menuClass = (/\b(?:dynamic|history|preset)\b/).exec(classList)[0]; + const [menuClass] = (/\b(?:dynamic|history|preset)\b/).exec(classList); $(".dropdown-menu a.active." + menuClass).removeClass("active"); $(this).addClass("active"); tabClick("#autoRefresh"); diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js index e6b7bc897..c445793d9 100644 --- a/interface/js/app/stats.js +++ b/interface/js/app/stats.js @@ -58,7 +58,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"], const servers = JSON.parse(sessionStorage.getItem("Credentials")); let data = {}; if (servers && servers[checked_server]) { - data = servers[checked_server].data; + ({data} = servers[checked_server]); } const stat_w = []; @@ -122,7 +122,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"], uptime = msToTime(val.data.uptime); } if ("version" in val.data) { - version = val.data.version; + ({version} = val.data); } if (key === "All SERVERS") { short_id = ""; @@ -249,7 +249,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"], const creds = JSON.parse(sessionStorage.getItem("Credentials")); // Controller doesn't return the 'actions' object until at least one message is scanned if (creds && creds[checked_server] && creds[checked_server].data.scanned) { - const actions = creds[checked_server].data.actions; + const {actions} = creds[checked_server].data; ["no action", "soft reject", "add header", "rewrite subject", "greylist", "reject"] .forEach(function (action) { @@ -295,7 +295,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"], }; function process_node_stat(e) { - const data = neighbours_status[e].data; + const {data} = neighbours_status[e]; // Controller doesn't return the 'actions' object until at least one message is scanned if (data.scanned) { for (const action in neighbours_sum.actions) { @@ -315,7 +315,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"], const alerted = "alerted_stats_legacy_" + neighbours_status[e].name; promises.push($.ajax({ url: neighbours_status[e].url + "auth", - headers: {Password:rspamd.getPassword()}, + headers: {Password: rspamd.getPassword()}, success: function (data) { sessionStorage.removeItem(alerted); ["config_id", "version", "uptime"].forEach(function (p) { diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js index df3d28fad..be6ad8d81 100644 --- a/interface/js/app/symbols.js +++ b/interface/js/app/symbols.js @@ -141,20 +141,21 @@ define(["jquery", "app/rspamd", "footable"], ui.getSymbols = function (checked_server) { rspamd.query("symbols", { success: function (json) { - const data = json[0].data; + const [{data}] = json; const items = process_symbols_data(data); /* eslint-disable consistent-this, no-underscore-dangle, one-var-declaration-per-line */ FooTable.groupFilter = FooTable.Filtering.extend({ construct: function (instance) { this._super(instance); - this.groups = items[1]; + [,this.groups] = items; this.def = "Any group"; this.$group = null; }, $create: function () { this._super(); - const self = this, $form_grp = $("<div/>", { + const self = this; + const $form_grp = $("<div/>", { class: "form-group" }).append($("<label/>", { class: "sr-only", @@ -175,7 +176,8 @@ define(["jquery", "app/rspamd", "footable"], }); }, _onStatusDropdownChanged: function (e) { - const self = e.data.self, selected = $(this).val(); + const {self} = e.data; + const selected = $(this).val(); if (selected !== self.def) { self.addFilter("group", selected, ["group"]); } else { @@ -197,17 +199,17 @@ define(["jquery", "app/rspamd", "footable"], rspamd.tables.symbols = FooTable.init("#symbolsTable", { columns: [ - {sorted:true, direction:"ASC", name:"group", title:"Group", style:{"font-size":"11px"}}, - {name:"symbol", title:"Symbol", style:{"font-size":"11px"}}, - {name:"description", title:"Description", breakpoints:"xs sm", style:{"font-size":"11px"}}, - {name:"weight", title:"Score", style:{"font-size":"11px"}}, - {name:"frequency", - title:"Frequency", - breakpoints:"xs sm", - style:{"font-size":"11px"}, - sortValue:function (value) { return Number(value).toFixed(2); }}, - {name:"time", title:"Avg. time", breakpoints:"xs sm", style:{"font-size":"11px"}}, - {name:"save", title:"Save", style:{"font-size":"11px"}}, + {sorted: true, direction: "ASC", name: "group", title: "Group", style: {"font-size": "11px"}}, + {name: "symbol", title: "Symbol", style: {"font-size": "11px"}}, + {name: "description", title: "Description", breakpoints: "xs sm", style: {"font-size": "11px"}}, + {name: "weight", title: "Score", style: {"font-size": "11px"}}, + {name: "frequency", + title: "Frequency", + breakpoints: "xs sm", + style: {"font-size": "11px"}, + sortValue: function (value) { return Number(value).toFixed(2); }}, + {name: "time", title: "Avg. time", breakpoints: "xs sm", style: {"font-size": "11px"}}, + {name: "save", title: "Save", style: {"font-size": "11px"}}, ], rows: items[0], paging: { @@ -252,7 +254,7 @@ define(["jquery", "app/rspamd", "footable"], const checked_server = rspamd.getSelector("selSrv"); rspamd.query("symbols", { success: function (data) { - const items = process_symbols_data(data[0].data)[0]; + const [items] = process_symbols_data(data[0].data); rspamd.tables.symbols.rows.load(items); }, server: (checked_server === "All SERVERS") ? "local" : checked_server diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js index 3800ca23f..9893477f1 100644 --- a/interface/js/app/upload.js +++ b/interface/js/app/upload.js @@ -171,8 +171,8 @@ define(["jquery", "app/rspamd"], rspamd.alertMessage("alert-success", "Data successfully scanned"); const rows_total = $("#historyTable_scan > tbody > tr:not(.footable-detail-row)").length + 1; - const o = rspamd.process_history_v2({rows:[json]}, "scan"); - const items = o.items; + const o = rspamd.process_history_v2({rows: [json]}, "scan"); + const {items} = o; rspamd.symbols.scan.push(o.symbols[0]); if (Object.prototype.hasOwnProperty.call(rspamd.tables, "scan")) { @@ -269,7 +269,7 @@ define(["jquery", "app/rspamd"], $("#scanForm")[0].reset(); $("#scanResult").hide(); $("#scanOutput tbody").remove(); - $("html, body").animate({scrollTop:0}, 1000); + $("html, body").animate({scrollTop: 0}, 1000); return false; }); diff --git a/interface/js/main.js b/interface/js/main.js index 4bc488895..1d5ec5c3c 100644 --- a/interface/js/main.js +++ b/interface/js/main.js @@ -20,17 +20,17 @@ requirejs.config({ stickytabs: "jquery.stickytabs.min" }, shim: { - app: {deps:["jquery"]}, - codejar: {exports: "CodeJar", deps:["linenumbers"]}, - bootstrap: {exports:"bootstrap", deps:["jquery"]}, // Popovers require jQuery - d3: {exports:"d3"}, - d3evolution: {exports:"D3Evolution", deps:["d3.global", "jquery"]}, - d3pie: {exports:"D3Pie", deps:["d3.global", "jquery"]}, - fontawesome: {exports: "FontAwesome", deps:["fontawesome_solid"]}, - footable: {deps:["bootstrap", "jquery"]}, - linenumbers: {exports: "withLineNumbers", deps:["prism"]}, + app: {deps: ["jquery"]}, + codejar: {exports: "CodeJar", deps: ["linenumbers"]}, + bootstrap: {exports: "bootstrap", deps: ["jquery"]}, // Popovers require jQuery + d3: {exports: "d3"}, + d3evolution: {exports: "D3Evolution", deps: ["d3.global", "jquery"]}, + d3pie: {exports: "D3Pie", deps: ["d3.global", "jquery"]}, + fontawesome: {exports: "FontAwesome", deps: ["fontawesome_solid"]}, + footable: {deps: ["bootstrap", "jquery"]}, + linenumbers: {exports: "withLineNumbers", deps: ["prism"]}, prism: {exports: "Prism"}, - stickytabs: {deps:["jquery"]} + stickytabs: {deps: ["jquery"]} }, waitSeconds: 30, }); |