diff --git a/.eslintrc.js b/.eslintrc.js index 50e5d4fcc..4dae14320 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,6 +22,8 @@ module.exports = { requireConfigFile: false, }, rules: { + "yoda": "error", + eqeqeq: [ "warn", "smart" ], "linebreak-style": [ "error", "unix" ], "camelcase": [ "warn", { "properties": "never", diff --git a/server/jobs/util-worker.js b/server/jobs/util-worker.js index 9426840d7..f122e6821 100644 --- a/server/jobs/util-worker.js +++ b/server/jobs/util-worker.js @@ -9,7 +9,7 @@ const log = function (any) { }; const exit = function (error) { - if (error && error != 0) { + if (error && error !== 0) { process.exit(error); } else { if (parentPort) { diff --git a/server/model/monitor.js b/server/model/monitor.js index 6659e1eae..bbb80da4a 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -262,7 +262,7 @@ class Monitor extends BeanModel { log.debug("monitor", "Cert Info Query Time: " + (dayjs().valueOf() - certInfoStartTime) + "ms"); } - if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID == this.id) { + if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID === this.id) { log.info("monitor", res.data); } @@ -302,24 +302,24 @@ class Monitor extends BeanModel { let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); bean.ping = dayjs().valueOf() - startTime; - if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA" || this.dns_resolve_type == "TXT") { + if (this.dns_resolve_type === "A" || this.dns_resolve_type === "AAAA" || this.dns_resolve_type === "TXT") { dnsMessage += "Records: "; dnsMessage += dnsRes.join(" | "); - } else if (this.dns_resolve_type == "CNAME" || this.dns_resolve_type == "PTR") { + } else if (this.dns_resolve_type === "CNAME" || this.dns_resolve_type === "PTR") { dnsMessage = dnsRes[0]; - } else if (this.dns_resolve_type == "CAA") { + } else if (this.dns_resolve_type === "CAA") { dnsMessage = dnsRes[0].issue; - } else if (this.dns_resolve_type == "MX") { + } else if (this.dns_resolve_type === "MX") { dnsRes.forEach(record => { dnsMessage += `Hostname: ${record.exchange} - Priority: ${record.priority} | `; }); dnsMessage = dnsMessage.slice(0, -2); - } else if (this.dns_resolve_type == "NS") { + } else if (this.dns_resolve_type === "NS") { dnsMessage += "Servers: "; dnsMessage += dnsRes.join(" | "); - } else if (this.dns_resolve_type == "SOA") { + } else if (this.dns_resolve_type === "SOA") { dnsMessage += `NS-Name: ${dnsRes.nsname} | Hostmaster: ${dnsRes.hostmaster} | Serial: ${dnsRes.serial} | Refresh: ${dnsRes.refresh} | Retry: ${dnsRes.retry} | Expire: ${dnsRes.expire} | MinTTL: ${dnsRes.minttl}`; - } else if (this.dns_resolve_type == "SRV") { + } else if (this.dns_resolve_type === "SRV") { dnsRes.forEach(record => { dnsMessage += `Name: ${record.name} | Port: ${record.port} | Priority: ${record.priority} | Weight: ${record.weight} | `; }); diff --git a/server/notification-providers/alerta.js b/server/notification-providers/alerta.js index c3eafec36..2b85d67a6 100644 --- a/server/notification-providers/alerta.js +++ b/server/notification-providers/alerta.js @@ -46,11 +46,11 @@ class Alerta extends NotificationProvider { resource: monitorJSON["name"], }, data ); - if (heartbeatJSON["status"] == DOWN) { + if (heartbeatJSON["status"] === DOWN) { datadup.severity = notification.alertaAlertState; // critical datadup.text = "Service " + monitorJSON["type"] + " is down."; await axios.post(alertaUrl, datadup, config); - } else if (heartbeatJSON["status"] == UP) { + } else if (heartbeatJSON["status"] === UP) { datadup.severity = notification.alertaRecoverState; // cleaned datadup.text = "Service " + monitorJSON["type"] + " is up."; await axios.post(alertaUrl, datadup, config); diff --git a/server/notification-providers/aliyun-sms.js b/server/notification-providers/aliyun-sms.js index 6a2063200..9a14240c4 100644 --- a/server/notification-providers/aliyun-sms.js +++ b/server/notification-providers/aliyun-sms.js @@ -64,7 +64,7 @@ class AliyunSMS extends NotificationProvider { }; let result = await axios(config); - if (result.data.Message == "OK") { + if (result.data.Message === "OK") { return true; } return false; diff --git a/server/notification-providers/bark.js b/server/notification-providers/bark.js index a4c525120..8920c2957 100644 --- a/server/notification-providers/bark.js +++ b/server/notification-providers/bark.js @@ -28,12 +28,12 @@ class Bark extends NotificationProvider { barkEndpoint = barkEndpoint.substring(0, barkEndpoint.length - 1); } - if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == UP) { + if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) { let title = "UptimeKuma Monitor Up"; return await this.postNotification(title, msg, barkEndpoint); } - if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == DOWN) { + if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) { let title = "UptimeKuma Monitor Down"; return await this.postNotification(title, msg, barkEndpoint); } diff --git a/server/notification-providers/dingding.js b/server/notification-providers/dingding.js index cf08f14bf..ef7dba0dc 100644 --- a/server/notification-providers/dingding.js +++ b/server/notification-providers/dingding.js @@ -50,7 +50,7 @@ class DingDing extends NotificationProvider { }; let result = await axios(config); - if (result.data.errmsg == "ok") { + if (result.data.errmsg === "ok") { return true; } return false; diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index f5c22a446..dd63e74b6 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -35,7 +35,7 @@ class Discord extends NotificationProvider { } // If heartbeatJSON is not null, we go into the normal alerting loop. - if (heartbeatJSON["status"] == DOWN) { + if (heartbeatJSON["status"] === DOWN) { let discorddowndata = { username: discordDisplayName, embeds: [{ @@ -70,7 +70,7 @@ class Discord extends NotificationProvider { await axios.post(notification.discordWebhookUrl, discorddowndata); return okMsg; - } else if (heartbeatJSON["status"] == UP) { + } else if (heartbeatJSON["status"] === UP) { let discordupdata = { username: discordDisplayName, embeds: [{ diff --git a/server/notification-providers/feishu.js b/server/notification-providers/feishu.js index 05fc9c186..73781ca4e 100644 --- a/server/notification-providers/feishu.js +++ b/server/notification-providers/feishu.js @@ -21,7 +21,7 @@ class Feishu extends NotificationProvider { return okMsg; } - if (heartbeatJSON["status"] == DOWN) { + if (heartbeatJSON["status"] === DOWN) { let downdata = { msg_type: "post", content: { @@ -48,7 +48,7 @@ class Feishu extends NotificationProvider { return okMsg; } - if (heartbeatJSON["status"] == UP) { + if (heartbeatJSON["status"] === UP) { let updata = { msg_type: "post", content: { diff --git a/server/notification-providers/line.js b/server/notification-providers/line.js index 6a09b5024..e594e1742 100644 --- a/server/notification-providers/line.js +++ b/server/notification-providers/line.js @@ -27,7 +27,7 @@ class Line extends NotificationProvider { ] }; await axios.post(lineAPIUrl, testMessage, config); - } else if (heartbeatJSON["status"] == DOWN) { + } else if (heartbeatJSON["status"] === DOWN) { let downMessage = { "to": notification.lineUserID, "messages": [ @@ -38,7 +38,7 @@ class Line extends NotificationProvider { ] }; await axios.post(lineAPIUrl, downMessage, config); - } else if (heartbeatJSON["status"] == UP) { + } else if (heartbeatJSON["status"] === UP) { let upMessage = { "to": notification.lineUserID, "messages": [ diff --git a/server/notification-providers/lunasea.js b/server/notification-providers/lunasea.js index 82d2fde5b..b53f32419 100644 --- a/server/notification-providers/lunasea.js +++ b/server/notification-providers/lunasea.js @@ -20,7 +20,7 @@ class LunaSea extends NotificationProvider { return okMsg; } - if (heartbeatJSON["status"] == DOWN) { + if (heartbeatJSON["status"] === DOWN) { let downdata = { "title": "UptimeKuma Alert: " + monitorJSON["name"], "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], @@ -29,7 +29,7 @@ class LunaSea extends NotificationProvider { return okMsg; } - if (heartbeatJSON["status"] == UP) { + if (heartbeatJSON["status"] === UP) { let updata = { "title": "UptimeKuma Alert: " + monitorJSON["name"], "body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], diff --git a/server/notification-providers/mattermost.js b/server/notification-providers/mattermost.js index fe7b685e1..2076ad213 100644 --- a/server/notification-providers/mattermost.js +++ b/server/notification-providers/mattermost.js @@ -29,7 +29,7 @@ class Mattermost extends NotificationProvider { const mattermostIconEmoji = notification.mattermosticonemo; const mattermostIconUrl = notification.mattermosticonurl; - if (heartbeatJSON["status"] == DOWN) { + if (heartbeatJSON["status"] === DOWN) { let mattermostdowndata = { username: mattermostUserName, text: "Uptime Kuma Alert", @@ -73,7 +73,7 @@ class Mattermost extends NotificationProvider { mattermostdowndata ); return okMsg; - } else if (heartbeatJSON["status"] == UP) { + } else if (heartbeatJSON["status"] === UP) { let mattermostupdata = { username: mattermostUserName, text: "Uptime Kuma Alert", diff --git a/server/notification-providers/octopush.js b/server/notification-providers/octopush.js index 68416b9a9..0eda940ba 100644 --- a/server/notification-providers/octopush.js +++ b/server/notification-providers/octopush.js @@ -10,7 +10,7 @@ class Octopush extends NotificationProvider { try { // Default - V2 - if (notification.octopushVersion == 2 || !notification.octopushVersion) { + if (notification.octopushVersion === 2 || !notification.octopushVersion) { let config = { headers: { "api-key": notification.octopushAPIKey, @@ -31,13 +31,13 @@ class Octopush extends NotificationProvider { "sender": notification.octopushSenderName }; await axios.post("https://api.octopush.com/v1/public/sms-campaign/send", data, config); - } else if (notification.octopushVersion == 1) { + } else if (notification.octopushVersion === 1) { let data = { "user_login": notification.octopushDMLogin, "api_key": notification.octopushDMAPIKey, "sms_recipients": notification.octopushDMPhoneNumber, "sms_sender": notification.octopushDMSenderName, - "sms_type": (notification.octopushDMSMSType == "sms_premium") ? "FR" : "XXX", + "sms_type": (notification.octopushDMSMSType === "sms_premium") ? "FR" : "XXX", "transactional": "1", //octopush not supporting non ascii char "sms_text": msg.replace(/[^\x00-\x7F]/g, ""), diff --git a/server/notification-providers/onebot.js b/server/notification-providers/onebot.js index c08cc01e8..6c62eccb5 100644 --- a/server/notification-providers/onebot.js +++ b/server/notification-providers/onebot.js @@ -27,7 +27,7 @@ class OneBot extends NotificationProvider { "auto_escape": true, "message": pushText, }; - if (notification.msgType == "group") { + if (notification.msgType === "group") { data["message_type"] = "group"; data["group_id"] = notification.recieverId; } else { diff --git a/server/notification-providers/pushbullet.js b/server/notification-providers/pushbullet.js index 07b4ed682..7f7a1c8d0 100644 --- a/server/notification-providers/pushbullet.js +++ b/server/notification-providers/pushbullet.js @@ -25,14 +25,14 @@ class Pushbullet extends NotificationProvider { "body": "Testing Successful.", }; await axios.post(pushbulletUrl, testdata, config); - } else if (heartbeatJSON["status"] == DOWN) { + } else if (heartbeatJSON["status"] === DOWN) { let downdata = { "type": "note", "title": "UptimeKuma Alert: " + monitorJSON["name"], "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], }; await axios.post(pushbulletUrl, downdata, config); - } else if (heartbeatJSON["status"] == UP) { + } else if (heartbeatJSON["status"] === UP) { let updata = { "type": "note", "title": "UptimeKuma Alert: " + monitorJSON["name"], diff --git a/server/notification-providers/pushdeer.js b/server/notification-providers/pushdeer.js index 620c1b20a..bbd83f4bf 100644 --- a/server/notification-providers/pushdeer.js +++ b/server/notification-providers/pushdeer.js @@ -13,9 +13,9 @@ class PushDeer extends NotificationProvider { let valid = msg != null && monitorJSON != null && heartbeatJSON != null; let title; - if (valid && heartbeatJSON.status == UP) { + if (valid && heartbeatJSON.status === UP) { title = "## Uptime Kuma: " + monitorJSON.name + " up"; - } else if (valid && heartbeatJSON.status == DOWN) { + } else if (valid && heartbeatJSON.status === DOWN) { title = "## Uptime Kuma: " + monitorJSON.name + " down"; } else { title = "## Uptime Kuma Message"; @@ -38,7 +38,7 @@ class PushDeer extends NotificationProvider { if (res.data.content.result.length === 0) { let error = "Invalid PushDeer key"; this.throwGeneralAxiosError(error); - } else if (JSON.parse(res.data.content.result[0]).success != "ok") { + } else if (JSON.parse(res.data.content.result[0]).success !== "ok") { let error = "Unknown error"; this.throwGeneralAxiosError(error); } diff --git a/server/notification-providers/wecom.js b/server/notification-providers/wecom.js index b377cedd9..deca278cd 100644 --- a/server/notification-providers/wecom.js +++ b/server/notification-providers/wecom.js @@ -26,10 +26,10 @@ class WeCom extends NotificationProvider { composeMessage(heartbeatJSON, msg) { let title; - if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == UP) { + if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) { title = "UptimeKuma Monitor Up"; } - if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == DOWN) { + if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) { title = "UptimeKuma Monitor Down"; } if (msg != null) { diff --git a/server/prometheus.js b/server/prometheus.js index ead5c44c4..fe0896f61 100644 --- a/server/prometheus.js +++ b/server/prometheus.js @@ -49,8 +49,8 @@ class Prometheus { if (typeof tlsInfo !== "undefined") { try { - let isValid = 0; - if (tlsInfo.valid == true) { + let isValid; + if (tlsInfo.valid === true) { isValid = 1; } else { isValid = 0; diff --git a/server/util-server.js b/server/util-server.js index ac827663e..a27809dfd 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -92,7 +92,7 @@ exports.dnsResolve = function (hostname, resolverServer, rrtype) { const resolver = new Resolver(); resolver.setServers([ resolverServer ]); return new Promise((resolve, reject) => { - if (rrtype == "PTR") { + if (rrtype === "PTR") { resolver.reverse(hostname, (err, records) => { if (err) { reject(err);