From d71c0864478ba430cd7e8489152b9bb09bf41d50 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 17 Apr 2022 15:27:35 +0800 Subject: [PATCH] Standardize array bracket spacing --- .eslintrc.js | 43 +++++++++++++----------- babel.config.js | 4 +-- config/vite.config.js | 6 ++-- extra/beta/update-version.js | 10 +++--- extra/close-incorrect-issue.js | 2 +- extra/update-version.js | 6 ++-- extra/update-wiki-version.js | 8 ++--- package.json | 1 + server/client.js | 2 +- server/jobs/clear-old-data.js | 2 +- server/model/monitor.js | 2 +- server/notification-providers/alerta.js | 2 +- server/notification-providers/apprise.js | 2 +- server/notification-providers/gorush.js | 2 +- server/proxy.js | 12 +++---- server/server.js | 4 +-- server/util-server.js | 4 +-- src/components/Confirm.vue | 2 +- src/components/CopyableInput.vue | 2 +- src/components/CountUp.vue | 2 +- src/components/HiddenInput.vue | 2 +- src/components/NotificationDialog.vue | 2 +- src/components/ProxyDialog.vue | 2 +- src/i18n.js | 2 +- src/mixins/socket.js | 4 +-- src/pages/EditMonitor.vue | 10 +++--- 26 files changed, 73 insertions(+), 67 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cdd49e6e0..50e5d4fcc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,40 +22,45 @@ module.exports = { requireConfigFile: false, }, rules: { - "linebreak-style": ["error", "unix"], - "camelcase": ["warn", { + "linebreak-style": [ "error", "unix" ], + "camelcase": [ "warn", { "properties": "never", "ignoreImports": true }], - "no-unused-vars": ["warn", { + "no-unused-vars": [ "warn", { "args": "none" }], indent: [ "error", 4, { - ignoredNodes: ["TemplateLiteral"], + ignoredNodes: [ "TemplateLiteral" ], SwitchCase: 1, }, ], - quotes: ["warn", "double"], + quotes: [ "warn", "double" ], semi: "error", - "vue/html-indent": ["warn", 4], // default: 2 + "vue/html-indent": [ "warn", 4 ], // default: 2 "vue/max-attributes-per-line": "off", "vue/singleline-html-element-content-newline": "off", "vue/html-self-closing": "off", "vue/require-component-is": "off", // not allow is="style" https://github.com/vuejs/eslint-plugin-vue/issues/462#issuecomment-430234675 "vue/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly - "no-multi-spaces": ["error", { + "no-multi-spaces": [ "error", { ignoreEOLComments: true, }], - "space-before-function-paren": ["error", { + "array-bracket-spacing": [ "warn", "always", { + "singleValue": true, + "objectsInArrays": false, + "arraysInArrays": false + }], + "space-before-function-paren": [ "error", { "anonymous": "always", "named": "never", "asyncArrow": "always" }], "curly": "error", - "object-curly-spacing": ["error", "always"], + "object-curly-spacing": [ "error", "always" ], "object-curly-newline": "off", "object-property-newline": "error", "comma-spacing": "error", @@ -66,36 +71,36 @@ module.exports = { "space-infix-ops": "warn", "arrow-spacing": "warn", "no-trailing-spaces": "warn", - "no-constant-condition": ["error", { + "no-constant-condition": [ "error", { "checkLoops": false, }], "space-before-blocks": "warn", //'no-console': 'warn', "no-extra-boolean-cast": "off", - "no-multiple-empty-lines": ["warn", { + "no-multiple-empty-lines": [ "warn", { "max": 1, "maxBOF": 0, }], - "lines-between-class-members": ["warn", "always", { + "lines-between-class-members": [ "warn", "always", { exceptAfterSingleLine: true, }], "no-unneeded-ternary": "error", - "array-bracket-newline": ["error", "consistent"], - "eol-last": ["error", "always"], + "array-bracket-newline": [ "error", "consistent" ], + "eol-last": [ "error", "always" ], //'prefer-template': 'error', - "comma-dangle": ["warn", "only-multiline"], - "no-empty": ["error", { + "comma-dangle": [ "warn", "only-multiline" ], + "no-empty": [ "error", { "allowEmptyCatch": true }], "no-control-regex": "off", - "one-var": ["error", "never"], - "max-statements-per-line": ["error", { "max": 1 }] + "one-var": [ "error", "never" ], + "max-statements-per-line": [ "error", { "max": 1 }] }, "overrides": [ { "files": [ "src/languages/*.js", "src/icon.js" ], "rules": { - "comma-dangle": ["error", "always-multiline"], + "comma-dangle": [ "error", "always-multiline" ], } }, diff --git a/babel.config.js b/babel.config.js index d2ad8213a..6bb8a01a5 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,11 +1,11 @@ const config = {}; if (process.env.TEST_FRONTEND) { - config.presets = ["@babel/preset-env"]; + config.presets = [ "@babel/preset-env" ]; } if (process.env.TEST_BACKEND) { - config.plugins = ["babel-plugin-rewire"]; + config.plugins = [ "babel-plugin-rewire" ]; } module.exports = config; diff --git a/config/vite.config.js b/config/vite.config.js index a9701d426..9fdc5fabf 100644 --- a/config/vite.config.js +++ b/config/vite.config.js @@ -10,15 +10,15 @@ export default defineConfig({ plugins: [ vue(), legacy({ - targets: ["ie > 11"], - additionalLegacyPolyfills: ["regenerator-runtime/runtime"] + targets: [ "ie > 11" ], + additionalLegacyPolyfills: [ "regenerator-runtime/runtime" ] }) ], css: { postcss: { "parser": postCssScss, "map": false, - "plugins": [postcssRTLCSS] + "plugins": [ postcssRTLCSS ] } }, }); diff --git a/extra/beta/update-version.js b/extra/beta/update-version.js index 3ab47ea90..b8de95df6 100644 --- a/extra/beta/update-version.js +++ b/extra/beta/update-version.js @@ -31,7 +31,7 @@ if (! exists) { function commit(version) { let msg = "Update to " + version; - let res = childProcess.spawnSync("git", ["commit", "-m", msg, "-a"]); + let res = childProcess.spawnSync("git", [ "commit", "-m", msg, "-a" ]); let stdout = res.stdout.toString().trim(); console.log(stdout); @@ -39,15 +39,15 @@ function commit(version) { throw new Error("commit error"); } - res = childProcess.spawnSync("git", ["push", "origin", "master"]); + res = childProcess.spawnSync("git", [ "push", "origin", "master" ]); console.log(res.stdout.toString().trim()); } function tag(version) { - let res = childProcess.spawnSync("git", ["tag", version]); + let res = childProcess.spawnSync("git", [ "tag", version ]); console.log(res.stdout.toString().trim()); - res = childProcess.spawnSync("git", ["push", "origin", version]); + res = childProcess.spawnSync("git", [ "push", "origin", version ]); console.log(res.stdout.toString().trim()); } @@ -56,7 +56,7 @@ function tagExists(version) { throw new Error("invalid version"); } - let res = childProcess.spawnSync("git", ["tag", "-l", version]); + let res = childProcess.spawnSync("git", [ "tag", "-l", version ]); return res.stdout.toString().trim() === version; } diff --git a/extra/close-incorrect-issue.js b/extra/close-incorrect-issue.js index a15a5da37..ae38bccc2 100644 --- a/extra/close-incorrect-issue.js +++ b/extra/close-incorrect-issue.js @@ -29,7 +29,7 @@ const github = require("@actions/github"); owner: issue.owner, repo: issue.repo, issue_number: issue.number, - labels: ["invalid-format"] + labels: [ "invalid-format" ] }); // Add the issue closing comment diff --git a/extra/update-version.js b/extra/update-version.js index abca92e26..f17ad2007 100644 --- a/extra/update-version.js +++ b/extra/update-version.js @@ -41,7 +41,7 @@ if (! exists) { function commit(version) { let msg = "Update to " + version; - let res = childProcess.spawnSync("git", ["commit", "-m", msg, "-a"]); + let res = childProcess.spawnSync("git", [ "commit", "-m", msg, "-a" ]); let stdout = res.stdout.toString().trim(); console.log(stdout); @@ -51,7 +51,7 @@ function commit(version) { } function tag(version) { - let res = childProcess.spawnSync("git", ["tag", version]); + let res = childProcess.spawnSync("git", [ "tag", version ]); console.log(res.stdout.toString().trim()); } @@ -66,7 +66,7 @@ function tagExists(version) { throw new Error("invalid version"); } - let res = childProcess.spawnSync("git", ["tag", "-l", version]); + let res = childProcess.spawnSync("git", [ "tag", "-l", version ]); return res.stdout.toString().trim() === version; } diff --git a/extra/update-wiki-version.js b/extra/update-wiki-version.js index f318839f5..d0f10561f 100644 --- a/extra/update-wiki-version.js +++ b/extra/update-wiki-version.js @@ -16,23 +16,23 @@ function updateWiki(newVersion) { safeDelete(wikiDir); - childProcess.spawnSync("git", ["clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir]); + childProcess.spawnSync("git", [ "clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir ]); let content = fs.readFileSync(howToUpdateFilename).toString(); // Replace the version: https://regex101.com/r/hmj2Bc/1 content = content.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`); fs.writeFileSync(howToUpdateFilename, content); - childProcess.spawnSync("git", ["add", "-A"], { + childProcess.spawnSync("git", [ "add", "-A" ], { cwd: wikiDir, }); - childProcess.spawnSync("git", ["commit", "-m", `Update to ${newVersion}`], { + childProcess.spawnSync("git", [ "commit", "-m", `Update to ${newVersion}` ], { cwd: wikiDir, }); console.log("Pushing to Github"); - childProcess.spawnSync("git", ["push"], { + childProcess.spawnSync("git", [ "push" ], { cwd: wikiDir, }); diff --git a/package.json b/package.json index 305d79b81..96e8b5052 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "install-legacy": "npm install --legacy-peer-deps", "update-legacy": "npm update --legacy-peer-deps", "lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .", + "lint-fix:js": "eslint --ext \".js,.vue\" --fix --ignore-path .gitignore .", "lint:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore", "lint": "npm run lint:js && npm run lint:style", "dev": "vite --host --config ./config/vite.config.js", diff --git a/server/client.js b/server/client.js index 3a2d6df27..31b10e844 100644 --- a/server/client.js +++ b/server/client.js @@ -98,7 +98,7 @@ async function sendImportantHeartbeatList(socket, monitorID, toUser = false, ove async function sendProxyList(socket) { const timeLogger = new TimeLogger(); - const list = await R.find("proxy", " user_id = ? ", [socket.userID]); + const list = await R.find("proxy", " user_id = ? ", [ socket.userID ]); io.to(socket.userID).emit("proxyList", list.map(bean => bean.export())); timeLogger.print("Send Proxy List"); diff --git a/server/jobs/clear-old-data.js b/server/jobs/clear-old-data.js index 7c368014d..0ec5ffa5f 100644 --- a/server/jobs/clear-old-data.js +++ b/server/jobs/clear-old-data.js @@ -30,7 +30,7 @@ const DEFAULT_KEEP_PERIOD = 180; try { await R.exec( "DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ", - [parsedPeriod] + [ parsedPeriod ] ); } catch (e) { log(`Failed to clear old data: ${e.message}`); diff --git a/server/model/monitor.js b/server/model/monitor.js index 875721139..6659e1eae 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -90,7 +90,7 @@ class Monitor extends BeanModel { } async getTags() { - return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [this.id]); + return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [ this.id ]); } /** diff --git a/server/notification-providers/alerta.js b/server/notification-providers/alerta.js index bcee80df7..c3eafec36 100644 --- a/server/notification-providers/alerta.js +++ b/server/notification-providers/alerta.js @@ -40,7 +40,7 @@ class Alerta extends NotificationProvider { await axios.post(alertaUrl, postData, config); } else { let datadup = Object.assign( { - correlate: ["service_up", "service_down"], + correlate: [ "service_up", "service_down" ], event: monitorJSON["type"], group: "uptimekuma-" + monitorJSON["type"], resource: monitorJSON["name"], diff --git a/server/notification-providers/apprise.js b/server/notification-providers/apprise.js index aa8daca64..2d795d4e5 100644 --- a/server/notification-providers/apprise.js +++ b/server/notification-providers/apprise.js @@ -6,7 +6,7 @@ class Apprise extends NotificationProvider { name = "apprise"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let s = childProcess.spawnSync("apprise", [ "-vv", "-b", msg, notification.appriseURL]); + let s = childProcess.spawnSync("apprise", [ "-vv", "-b", msg, notification.appriseURL ]); let output = (s.stdout) ? s.stdout.toString() : "ERROR: maybe apprise not found"; diff --git a/server/notification-providers/gorush.js b/server/notification-providers/gorush.js index 58da5525e..6d756e46c 100644 --- a/server/notification-providers/gorush.js +++ b/server/notification-providers/gorush.js @@ -18,7 +18,7 @@ class Gorush extends NotificationProvider { let data = { "notifications": [ { - "tokens": [notification.gorushDeviceToken], + "tokens": [ notification.gorushDeviceToken ], "platform": platformMapping[notification.gorushPlatform], "message": msg, // Optional diff --git a/server/proxy.js b/server/proxy.js index af72402d1..3de6425c4 100644 --- a/server/proxy.js +++ b/server/proxy.js @@ -7,7 +7,7 @@ const server = require("./server"); class Proxy { - static SUPPORTED_PROXY_PROTOCOLS = ["http", "https", "socks", "socks5", "socks4"] + static SUPPORTED_PROXY_PROTOCOLS = [ "http", "https", "socks", "socks5", "socks4" ] /** * Saves and updates given proxy entity @@ -21,7 +21,7 @@ class Proxy { let bean; if (proxyID) { - bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [proxyID, userID]); + bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [ proxyID, userID ]); if (!bean) { throw new Error("proxy not found"); @@ -71,14 +71,14 @@ class Proxy { * @return {Promise} */ static async delete(proxyID, userID) { - const bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [proxyID, userID]); + const bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [ proxyID, userID ]); if (!bean) { throw new Error("proxy not found"); } // Delete removed proxy from monitors if exists - await R.exec("UPDATE monitor SET proxy_id = null WHERE proxy_id = ?", [proxyID]); + await R.exec("UPDATE monitor SET proxy_id = null WHERE proxy_id = ?", [ proxyID ]); // Delete proxy from list await R.trash(bean); @@ -172,12 +172,12 @@ class Proxy { */ async function applyProxyEveryMonitor(proxyID, userID) { // Find all monitors with id and proxy id - const monitors = await R.getAll("SELECT id, proxy_id FROM monitor WHERE user_id = ?", [userID]); + const monitors = await R.getAll("SELECT id, proxy_id FROM monitor WHERE user_id = ?", [ userID ]); // Update proxy id not match with given proxy id for (const monitor of monitors) { if (monitor.proxy_id !== proxyID) { - await R.exec("UPDATE monitor SET proxy_id = ? WHERE id = ?", [proxyID, monitor.id]); + await R.exec("UPDATE monitor SET proxy_id = ? WHERE id = ?", [ proxyID, monitor.id ]); } } } diff --git a/server/server.js b/server/server.js index 8a286d70d..eae21deeb 100644 --- a/server/server.js +++ b/server/server.js @@ -108,7 +108,7 @@ if (hostname) { log.info("server", "Custom hostname: " + hostname); } -const port = [args.port, process.env.UPTIME_KUMA_PORT, process.env.PORT, 3001] +const port = [ args.port, process.env.UPTIME_KUMA_PORT, process.env.PORT, 3001 ] .map(portValue => parseInt(portValue)) .find(portValue => !isNaN(portValue)); @@ -1237,7 +1237,7 @@ try { const exists = proxies.find(item => item.id === proxy.id); // Do not process when proxy already exists in import handle is skip and keep - if (["skip", "keep"].includes(importHandle) && !exists) { + if ([ "skip", "keep" ].includes(importHandle) && !exists) { return; } diff --git a/server/util-server.js b/server/util-server.js index 482fbaead..ac827663e 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -90,7 +90,7 @@ exports.pingAsync = function (hostname, ipv6 = false) { exports.dnsResolve = function (hostname, resolverServer, rrtype) { const resolver = new Resolver(); - resolver.setServers([resolverServer]); + resolver.setServers([ resolverServer ]); return new Promise((resolve, reject) => { if (rrtype == "PTR") { resolver.reverse(hostname, (err, records) => { @@ -345,7 +345,7 @@ exports.doubleCheckPassword = async (socket, currentPassword) => { exports.startUnitTest = async () => { console.log("Starting unit test..."); const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm"; - const child = childProcess.spawn(npm, ["run", "jest"]); + const child = childProcess.spawn(npm, [ "run", "jest" ]); child.stdout.on("data", (data) => { console.log(data.toString()); diff --git a/src/components/Confirm.vue b/src/components/Confirm.vue index fe5bf2884..1bfe7fe4a 100644 --- a/src/components/Confirm.vue +++ b/src/components/Confirm.vue @@ -42,7 +42,7 @@ export default { default: "No", }, }, - emits: ["yes"], + emits: [ "yes" ], data: () => ({ modal: null, }), diff --git a/src/components/CopyableInput.vue b/src/components/CopyableInput.vue index 08b60dddd..1bccfa2ce 100644 --- a/src/components/CopyableInput.vue +++ b/src/components/CopyableInput.vue @@ -57,7 +57,7 @@ export default { default: undefined, }, }, - emits: ["update:modelValue"], + emits: [ "update:modelValue" ], data() { return { visibility: "password", diff --git a/src/components/CountUp.vue b/src/components/CountUp.vue index 5a0deb745..41edc4a0e 100644 --- a/src/components/CountUp.vue +++ b/src/components/CountUp.vue @@ -10,7 +10,7 @@ import { sleep } from "../util.ts"; export default { props: { - value: [String, Number], + value: [ String, Number ], time: { type: Number, default: 0.3, diff --git a/src/components/HiddenInput.vue b/src/components/HiddenInput.vue index a9a789ce3..d2327b9df 100644 --- a/src/components/HiddenInput.vue +++ b/src/components/HiddenInput.vue @@ -48,7 +48,7 @@ export default { default: undefined, }, }, - emits: ["update:modelValue"], + emits: [ "update:modelValue" ], data() { return { visibility: "password", diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 96ab85803..7a1f1a100 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -78,7 +78,7 @@ export default { Confirm, }, props: {}, - emits: ["added"], + emits: [ "added" ], data() { return { model: null, diff --git a/src/components/ProxyDialog.vue b/src/components/ProxyDialog.vue index a6c234657..3070925c1 100644 --- a/src/components/ProxyDialog.vue +++ b/src/components/ProxyDialog.vue @@ -105,7 +105,7 @@ export default { Confirm, }, props: {}, - emits: ["added"], + emits: [ "added" ], data() { return { model: null, diff --git a/src/i18n.js b/src/i18n.js index 5505e5c2b..83a319918 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -43,7 +43,7 @@ for (let lang in languageList) { }; } -const rtlLangs = ["fa"]; +const rtlLangs = [ "fa" ]; export const currentLocale = () => localStorage.locale || languageList[navigator.language] && navigator.language diff --git a/src/mixins/socket.js b/src/mixins/socket.js index e77a0cd40..633daa73f 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -89,7 +89,7 @@ export default { } socket = io(wsHost, { - transports: ["websocket"], + transports: [ "websocket" ], }); socket.on("info", (info) => { @@ -108,7 +108,7 @@ export default { socket.on("monitorList", (data) => { // Add Helper function - Object.entries(data).forEach(([monitorID, monitor]) => { + Object.entries(data).forEach(([ monitorID, monitor ]) => { monitor.getUrl = () => { try { return new URL(monitor.url); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 4518e57e7..129609eee 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -393,17 +393,17 @@ export default { }, bodyPlaceholder() { - return this.$t("Example:", [` + return this.$t("Example:", [ ` { "key": "value" -}`]); +}` ]); }, headersPlaceholder() { - return this.$t("Example:", [` + return this.$t("Example:", [ ` { "HeaderName": "HeaderValue" -}`]); +}` ]); } }, @@ -488,7 +488,7 @@ export default { upsideDown: false, expiryNotification: false, maxredirects: 10, - accepted_statuscodes: ["200-299"], + accepted_statuscodes: [ "200-299" ], dns_resolve_type: "A", dns_resolve_server: "1.1.1.1", proxyId: null,