Tighten xo rules

Signed-off-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
XhmikosR
2025-02-22 18:25:56 +02:00
parent b647049dc0
commit f8a0a1d4ec
28 changed files with 1152 additions and 1130 deletions

View File

@@ -7,7 +7,7 @@
/* global utils:false, apiFailure:false */
var tableApi;
let tableApi;
// How many IPs do we show at most per device?
const MAXIPDISPLAY = 3;
@@ -16,7 +16,7 @@ const DAY_IN_SECONDS = 24 * 60 * 60;
function handleAjaxError(xhr, textStatus) {
if (textStatus === "timeout") {
alert("The server took too long to send the data.");
} else if (xhr.responseText.indexOf("Connection refused") === -1) {
} else if (!xhr.responseText.includes("Connection refused")) {
alert("An unknown error occurred while loading the data.\n" + xhr.responseText);
} else {
alert("An error occurred while loading the data: Connection refused. Is FTL running?");
@@ -32,7 +32,7 @@ function getTimestamp() {
}
function valueToHex(c) {
var hex = Math.round(c).toString(16);
const hex = Math.round(c).toString(16);
return hex.length === 1 ? "0" + hex : hex;
}
@@ -49,7 +49,7 @@ function mixColors(ratio, rgb1, rgb2) {
}
function parseColor(input) {
var match = input.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);
const match = input.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);
if (match) {
return [match[1], match[2], match[3]];
@@ -66,7 +66,7 @@ function deleteNetworkEntry() {
$.ajax({
url: document.body.dataset.apiurl + "/network/devices/" + id,
method: "DELETE",
success: function () {
success() {
utils.enableAll();
utils.showAlert(
"success",
@@ -76,7 +76,7 @@ function deleteNetworkEntry() {
);
tableApi.row(tr).remove().draw(false).ajax.reload(null, false);
},
error: function (data, exception) {
error(data, exception) {
apiFailure(data);
utils.enableAll();
utils.showAlert(
@@ -90,24 +90,24 @@ function deleteNetworkEntry() {
});
}
$(function () {
$(() => {
tableApi = $("#network-entries").DataTable({
rowCallback: function (row, data) {
var color;
var index;
var iconClasses;
var lastQuery = parseInt(data.lastQuery, 10);
var diff = getTimestamp() - lastQuery;
var networkRecent = $(".network-recent").css("background-color");
var networkOld = $(".network-old").css("background-color");
var networkOlder = $(".network-older").css("background-color");
var networkNever = $(".network-never").css("background-color");
rowCallback(row, data) {
let color;
let index;
let iconClasses;
const lastQuery = Number.parseInt(data.lastQuery, 10);
const diff = getTimestamp() - lastQuery;
const networkRecent = $(".network-recent").css("background-color");
const networkOld = $(".network-old").css("background-color");
const networkOlder = $(".network-older").css("background-color");
const networkNever = $(".network-never").css("background-color");
if (lastQuery > 0) {
if (diff <= DAY_IN_SECONDS) {
// Last query came in within the last 24 hours
// Color: light-green to light-yellow
var ratio = Number(diff) / DAY_IN_SECONDS;
const ratio = Number(diff) / DAY_IN_SECONDS;
color = rgbToHex(mixColors(ratio, parseColor(networkRecent), parseColor(networkOld)));
iconClasses = "fas fa-check";
} else {
@@ -135,11 +135,11 @@ $(function () {
// Set number of queries to localized string (add thousand separators)
$("td:eq(5)", row).html(data.numQueries.toLocaleString());
var ips = [],
iptitles = [];
const ips = [];
const iptitles = [];
// Sort IPs, IPv4 before IPv6, then alphabetically
data.ips.sort(function (a, b) {
data.ips.sort((a, b) => {
if (a.ip.includes(":") && !b.ip.includes(":")) {
return 1;
}
@@ -152,8 +152,8 @@ $(function () {
});
for (index = 0; index < data.ips.length; index++) {
var ip = data.ips[index],
iptext = ip.ip;
const ip = data.ips[index];
let iptext = ip.ip;
if (ip.name !== null && ip.name.length > 0) {
iptext = iptext + " (" + ip.name + ")";
@@ -194,7 +194,7 @@ $(function () {
// Add delete button
$(row).attr("data-id", data.id);
$(row).attr("data-hwaddr", data.hwaddr);
var button =
const button =
'<button type="button" class="btn btn-danger btn-xs" id="deleteNetworkEntry_' +
data.id +
'">' +
@@ -229,7 +229,7 @@ $(function () {
{
data: "firstSeen",
width: "8%",
render: function (data, type) {
render(data, type) {
if (type === "display") {
return utils.datetime(data);
}
@@ -240,7 +240,7 @@ $(function () {
{
data: "lastQuery",
width: "8%",
render: function (data, type) {
render(data, type) {
if (type === "display") {
return utils.datetime(data);
}
@@ -254,7 +254,7 @@ $(function () {
{ data: "ips[].name", visible: false, class: "hide" },
],
drawCallback: function () {
drawCallback() {
$('button[id^="deleteNetworkEntry_"]').on("click", deleteNetworkEntry);
// Remove visible dropdown to prevent orphaning
$("body > .bootstrap-select.dropdown").remove();
@@ -265,10 +265,10 @@ $(function () {
],
stateSave: true,
stateDuration: 0,
stateSaveCallback: function (settings, data) {
stateSaveCallback(settings, data) {
utils.stateSaveCallback("network_table", data);
},
stateLoadCallback: function () {
stateLoadCallback() {
return utils.stateLoadCallback("network_table");
},
columnDefs: [
@@ -284,7 +284,7 @@ $(function () {
],
});
// Disable autocorrect in the search box
var input = document.querySelector("input[type=search]");
const input = document.querySelector("input[type=search]");
input.setAttribute("autocomplete", "off");
input.setAttribute("autocorrect", "off");
input.setAttribute("autocapitalize", "off");