From a81d48b75e684bb62216902309d40c92de31527d Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 16 Jan 2023 15:09:07 -0800 Subject: [PATCH] chore: style formatting and linting fixes (#366) * chore(formatting-settings): ensure formatting is handled properly * chore(lint): fix lint errors * chore(lint): lint css files too * chore(lint): fix style of src/styles.css --- .vscode/settings.json | 32 +++++-- package-lock.json | 218 ++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +- scripts/beautify.mjs | 43 +++++++++ scripts/build-sw.mjs | 6 +- src/index.html | 66 ++++++------- src/styles.css | 130 +++++++++++++------------ 7 files changed, 391 insertions(+), 108 deletions(-) create mode 100644 scripts/beautify.mjs diff --git a/.vscode/settings.json b/.vscode/settings.json index f461b68f..fc93c981 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,25 @@ { - "editor.tabSize": 2, - "typescript.format.semicolons": "remove", - "javascript.format.semicolons": "remove", - "typescript.suggest.includeAutomaticOptionalChainCompletions": true, - "editor.formatOnSave": true, - "eslint.codeActionsOnSave.rules": [], - "files.exclude": { - "package-lock.json": true - } + "editor.tabSize": 2, + "typescript.format.semicolons": "remove", + "javascript.format.semicolons": "remove", + "typescript.suggest.includeAutomaticOptionalChainCompletions": true, + "editor.formatOnSave": false, + "eslint.codeActionsOnSave.rules": [], + "files.exclude": { + "package-lock.json": true + }, + "standard.enable": true, + "standard.enableGlobally": false, + "standard.run": "onSave", + "standard.autoFixOnSave": true, + "editor.defaultFormatter": "standard.vscode-standard", + "[html]": { + "editor.defaultFormatter": "standard.vscode-standard", + }, + "[json]": { + "editor.defaultFormatter": "standard.vscode-standard", + }, + "[javascript]": { + "editor.defaultFormatter": "standard.vscode-standard", + } } diff --git a/package-lock.json b/package-lock.json index b9b181a2..d25bac32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "fetch-ponyfill": "^7.1.0", "ipfs": "^0.65.0", "ipfs-geoip": "^9.0.0", + "js-beautify": "^1.14.7", "typescript": "^4.8.4", "workbox-build": "6.5.4", "workbox-window": "6.5.4" @@ -11265,6 +11266,46 @@ "dev": true, "optional": true }, + "node_modules/editorconfig": { + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz", + "integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==", + "dev": true, + "dependencies": { + "commander": "^2.19.0", + "lru-cache": "^4.1.5", + "semver": "^5.6.0", + "sigmund": "^1.0.1" + }, + "bin": { + "editorconfig": "bin/editorconfig" + } + }, + "node_modules/editorconfig/node_modules/lru-cache": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "dev": true, + "dependencies": { + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" + } + }, + "node_modules/editorconfig/node_modules/semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true, + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/editorconfig/node_modules/yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", + "dev": true + }, "node_modules/ejs": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz", @@ -17649,6 +17690,81 @@ "node": ">=6" } }, + "node_modules/js-beautify": { + "version": "1.14.7", + "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.14.7.tgz", + "integrity": "sha512-5SOX1KXPFKx+5f6ZrPsIPEY7NwKeQz47n3jm2i+XeHx9MoRsfQenlOP13FQhWvg8JRS0+XLO6XYUQ2GX+q+T9A==", + "dev": true, + "dependencies": { + "config-chain": "^1.1.13", + "editorconfig": "^0.15.3", + "glob": "^8.0.3", + "nopt": "^6.0.0" + }, + "bin": { + "css-beautify": "js/bin/css-beautify.js", + "html-beautify": "js/bin/html-beautify.js", + "js-beautify": "js/bin/js-beautify.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/js-beautify/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/js-beautify/node_modules/glob": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", + "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/js-beautify/node_modules/minimatch": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-bNH9mmM9qsJ2X4r2Nat1B//1dJVcn3+iBLa3IgqJ7EbGaDNepL9QSHOxN4ng33s52VMMhhIfgCYDk3C4ZmlDAg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/js-beautify/node_modules/nopt": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz", + "integrity": "sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==", + "dev": true, + "dependencies": { + "abbrev": "^1.0.0" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, "node_modules/js-sdsl": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.5.tgz", @@ -27895,6 +28011,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha512-fCvEXfh6NWpm+YSuY2bpXb/VIihqWA6hLsgboC+0nl71Q7N7o2eaCW8mJa/NLvQhs6jpd3VZV4UiUQlV6+lc8g==", + "dev": true + }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -39220,6 +39342,42 @@ } } }, + "editorconfig": { + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz", + "integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==", + "dev": true, + "requires": { + "commander": "^2.19.0", + "lru-cache": "^4.1.5", + "semver": "^5.6.0", + "sigmund": "^1.0.1" + }, + "dependencies": { + "lru-cache": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "dev": true, + "requires": { + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" + } + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", + "dev": true + } + } + }, "ejs": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz", @@ -44025,6 +44183,60 @@ "integrity": "sha512-YqvUxoOcVPnCp0VU1/56f+iKSdvIRJYPznH22BdXV3xMk75SFXhWeJkZ8C9XxUWt1b5x2X1SxuFygW1U0FmkEQ==", "dev": true }, + "js-beautify": { + "version": "1.14.7", + "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.14.7.tgz", + "integrity": "sha512-5SOX1KXPFKx+5f6ZrPsIPEY7NwKeQz47n3jm2i+XeHx9MoRsfQenlOP13FQhWvg8JRS0+XLO6XYUQ2GX+q+T9A==", + "dev": true, + "requires": { + "config-chain": "^1.1.13", + "editorconfig": "^0.15.3", + "glob": "^8.0.3", + "nopt": "^6.0.0" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0" + } + }, + "glob": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", + "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + } + }, + "minimatch": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-bNH9mmM9qsJ2X4r2Nat1B//1dJVcn3+iBLa3IgqJ7EbGaDNepL9QSHOxN4ng33s52VMMhhIfgCYDk3C4ZmlDAg==", + "dev": true, + "requires": { + "brace-expansion": "^2.0.1" + } + }, + "nopt": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz", + "integrity": "sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==", + "dev": true, + "requires": { + "abbrev": "^1.0.0" + } + } + } + }, "js-sdsl": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.5.tgz", @@ -51433,6 +51645,12 @@ "object-inspect": "^1.9.0" } }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha512-fCvEXfh6NWpm+YSuY2bpXb/VIihqWA6hLsgboC+0nl71Q7N7o2eaCW8mJa/NLvQhs6jpd3VZV4UiUQlV6+lc8g==", + "dev": true + }, "signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", diff --git a/package.json b/package.json index 7076cd24..26a9b360 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,8 @@ "scripts": { "start": "npm run build && npx -y serve -l 3000 dist", "copy-assets": "cp-cli src/index.html dist/index.html && cp-cli src/styles.css dist/styles.css", - "lint": "aegir lint", + "lint": "aegir lint && npx -y standard && node scripts/beautify.mjs", + "lint:fix": "aegir lint --fix && npx -y standard --fix && node scripts/beautify.mjs --fix", "release": "aegir release", "sw": "node scripts/build-sw.mjs", "build": "aegir build && npm run copy-assets && npm run sw", @@ -133,6 +134,7 @@ "fetch-ponyfill": "^7.1.0", "ipfs": "^0.65.0", "ipfs-geoip": "^9.0.0", + "js-beautify": "^1.14.7", "typescript": "^4.8.4", "workbox-build": "6.5.4", "workbox-window": "6.5.4" diff --git a/scripts/beautify.mjs b/scripts/beautify.mjs new file mode 100644 index 00000000..091fded8 --- /dev/null +++ b/scripts/beautify.mjs @@ -0,0 +1,43 @@ +import jsBeautify from 'js-beautify' +import { promises as fs } from 'fs' + +const saveFile = process.argv.slice(2).includes('--fix') + +const files = { + 'src/index.html': jsBeautify.html, + 'src/styles.css': jsBeautify.css +} + +async function beautificationFn (filePath, fn) { + console.log(`Checking ${filePath} formatting...`) + const sourceCode = await fs.readFile(filePath, 'utf8') + + console.log(`Beautifying ${filePath}...`) + const beautifiedCode = fn(sourceCode, { + indent_size: 2, + space_in_empty_paren: true, + indent_char: ' ', + indent_with_tabs: false, + editorconfig: false, + eol: '\n', + end_with_newline: true, + indent_level: 0 + }) + + // lint mode.. fail if not beautified + if (sourceCode === beautifiedCode) { + console.log(`${filePath} is already beautified`) + return + } else if (!saveFile) { + throw new Error(`${filePath} is not beautified`) + } + + if (saveFile) { + console.log(`Saving beautified ${filePath}`) + await fs.writeFile(filePath, beautifiedCode, 'utf8') + } +} + +for (const [filePath, fn] of Object.entries(files)) { + await beautificationFn(filePath, fn) +} diff --git a/scripts/build-sw.mjs b/scripts/build-sw.mjs index 0cda6ede..aea5bdf1 100644 --- a/scripts/build-sw.mjs +++ b/scripts/build-sw.mjs @@ -1,4 +1,4 @@ -import {generateSW} from 'workbox-build'; +import { generateSW } from 'workbox-build' generateSW({ globDirectory: 'dist/', @@ -11,8 +11,8 @@ generateSW({ runtimeCaching: [ { urlPattern: /\.(?:png|jpg|jpeg|svg)$/, - handler: 'NetworkFirst', + handler: 'NetworkFirst' } ], swDest: 'dist/sw.js' -}); +}) diff --git a/src/index.html b/src/index.html index 51e5764b..529de6bb 100644 --- a/src/index.html +++ b/src/index.html @@ -1,5 +1,6 @@ + Public Gateway Checker | IPFS @@ -10,8 +11,9 @@ - + +
@@ -24,7 +26,7 @@

Public Gateways

- +
@@ -35,12 +37,12 @@

Public Gateways

SECURITY NOTES

@@ -58,31 +60,31 @@

Public Gateways

ΔT
-