From 3fc8706007d896dcbde69c0ce924a6a5eb66aba6 Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Mon, 4 Dec 2023 08:52:48 -0700 Subject: refactor: implement biome (#1467) - add `biome.json` - add `biome:check` and `biome:check:fix` commands to `package.json` - add `biome:check:fix` command to run as part of `prepare-code` command - install `@biomejs/biome` dependency - add `@npmcli/move-file` v2.0.1 to `pnpm.allowedDeprecatedVersions` - fix or comment out various reported lint issues --- biome.json | 36 +++++++++++ esbuild.mjs | 10 +-- package.json | 7 ++- pnpm-lock.yaml | 71 ++++++++++++++++++++++ src/components/auth/SetupAssistant.tsx | 7 +-- src/components/auth/Welcome.tsx | 2 +- src/components/layout/Sidebar.tsx | 1 + src/components/services/tabs/TabItem.tsx | 2 +- src/components/settings/services/ServiceItem.tsx | 30 ++------- src/components/ui/Link.tsx | 1 + src/components/ui/Radio.tsx | 1 + src/components/ui/button/index.tsx | 1 + src/components/ui/input/index.tsx | 1 + src/components/ui/select/index.tsx | 1 + src/components/ui/textarea/index.tsx | 2 + src/components/ui/toggle/index.tsx | 1 + .../workspaces/components/WorkspaceDrawerItem.tsx | 3 +- .../app/Controllers/Http/RecipeController.js | 8 +-- .../app/Controllers/Http/ServiceController.js | 7 +-- src/internal-server/start/migrate.js | 3 +- 20 files changed, 145 insertions(+), 50 deletions(-) create mode 100644 biome.json diff --git a/biome.json b/biome.json new file mode 100644 index 000000000..0e7563225 --- /dev/null +++ b/biome.json @@ -0,0 +1,36 @@ +{ + "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", + "formatter": { + "enabled": false + }, + "organizeImports": { + "enabled": false + }, + "linter": { + "ignore": ["build", "coverage", "node_modules", "recipes", "*.json"], + "rules": { + "style": { + "noNonNullAssertion": "off", + "noInferrableTypes": "off", + "noParameterAssign": "off" + }, + "complexity": { + "useLiteralKeys": "off", + "noUselessConstructor": "off", + "noForEach": "off", + "noBannedTypes": "off" + }, + "suspicious": { + "noEmptyInterface": "off", + "noExplicitAny": "off", + "noArrayIndexKey": "off" + }, + "performance": { + "noDelete": "off" + }, + "a11y": { + "useKeyWithClickEvents": "off" + } + } + } +} diff --git a/esbuild.mjs b/esbuild.mjs index ae940b586..b29f15621 100755 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -4,11 +4,11 @@ import { sassPlugin } from 'esbuild-sass-plugin'; import { copy } from 'esbuild-plugin-copy'; import glob from 'tiny-glob'; import livereload from 'gulp-livereload'; -import * as fs from 'fs'; +import * as fs from 'node:fs'; import * as buildInfo from 'preval-build-info'; import fsPkg from 'fs-extra'; import chalk from 'chalk'; -import { performance } from 'perf_hooks'; +import { performance } from 'node:perf_hooks'; import moment from 'moment'; const { log } = console; @@ -80,11 +80,11 @@ const runEsbuild = async () => { const myArgs = process.argv.slice(2); const isDev = myArgs.includes('--watch'); - log(chalk.blue(`Starting with args`), myArgs); + log(chalk.blue('Starting with args'), myArgs); if (fs.existsSync(outDir)) { fs.rmSync(outDir, { force: true, recursive: true }); - log(chalk.blue(`Cleaning`), outDir); + log(chalk.blue('Cleaning'), outDir); } copyManualAssets(); @@ -112,7 +112,7 @@ const runEsbuild = async () => { if (error) { log(chalk.red(`watch build failed: ${error}`)); } else { - log(chalk.blue(`watch build success:`), result); + log(chalk.blue('watch build success:'), result); livereload.reload(); } }, diff --git a/package.json b/package.json index f52cd8163..f2bcd7f18 100644 --- a/package.json +++ b/package.json @@ -34,13 +34,15 @@ "typecheck": "tsc --noEmit", "lint": "eslint \"{src,test,scripts}/**/*.{js,jsx,mjs,ts,tsx}\" --quiet", "lint:fix": "pnpm lint --cache --fix", + "biome:check": "pnpm biome check .", + "biome:check:fix": "pnpm biome:check --apply-unsafe", "extract": "formatjs extract \"src/**/*.{js,jsx,mjs,ts,tsx}\" --ignore=\"**/*.d.ts\" --out-file temp.json --flatten --id-interpolation-pattern '[sha512:contenthash:base64:6]' --preserve-whitespace", "compile": "formatjs compile \"temp.json\" --out-file src/i18n/locales/en-US.json", "manage-translations": "pnpm extract && pnpm compile && rimraf temp.json", "build": "preval-build-info-cli && node esbuild.mjs && electron-builder", "contributors": "all-contributors", "reformat-files": "prettier --ignore-path .eslintignore --write --cache \"**/*.{js,jsx,mjs,ts,tsx,scss}\"", - "prepare-code": "pnpm typecheck && pnpm lint:fix && pnpm reformat-files && pnpm manage-translations", + "prepare-code": "pnpm typecheck && pnpm lint:fix && pnpm biome:check:fix && pnpm reformat-files && pnpm manage-translations", "link-readme": "ts-node scripts/link-readme.ts", "minify-images": "./scripts/minify-images.sh", "start:server": "ts-node src/internal-server/test.ts", @@ -134,6 +136,7 @@ "ws": "8.14.2" }, "devDependencies": { + "@biomejs/biome": "1.4.1", "@commitlint/cli": "17.7.1", "@commitlint/config-conventional": "17.7.0", "@electron/notarize": "1.2.3", @@ -216,7 +219,7 @@ "har-validator": "5.1.5", "uuid": "3.4.0", "@sinonjs/fake-timers": "10.2.0", - "@npmcli/move-file": "1.1.2", + "@npmcli/move-file": "1.1.2 || 2.0.1", "source-map-resolve": "0.5.3", "source-map-url": "0.4.1", "resolve-url": "0.2.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aa412d57d..c29b28eb0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -267,6 +267,9 @@ optionalDependencies: version: 2.3.0 devDependencies: + '@biomejs/biome': + specifier: 1.4.1 + version: 1.4.1 '@commitlint/cli': specifier: 17.7.1 version: 17.7.1 @@ -995,6 +998,74 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true + /@biomejs/biome@1.4.1: + resolution: {integrity: sha512-JccVAwPbhi37pdxbAGmaOBjUTKEwEjWAhl7rKkVVuXHo4MLASXJ5HR8BTgrImi4/7rTBsGz1tgVD1Kwv1CHGRg==} + engines: {node: '>=14.*'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@biomejs/cli-darwin-arm64': 1.4.1 + '@biomejs/cli-darwin-x64': 1.4.1 + '@biomejs/cli-linux-arm64': 1.4.1 + '@biomejs/cli-linux-x64': 1.4.1 + '@biomejs/cli-win32-arm64': 1.4.1 + '@biomejs/cli-win32-x64': 1.4.1 + dev: true + + /@biomejs/cli-darwin-arm64@1.4.1: + resolution: {integrity: sha512-PZWy2Idndqux38p6AXSDQM2ldRAWi32bvb7bMbTN0ALzpWYMYnxd71ornatumSSJYoNhKmxzDLq+jct7nZJ79w==} + engines: {node: '>=14.*'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@biomejs/cli-darwin-x64@1.4.1: + resolution: {integrity: sha512-soj3BWhnsM1M2JlzR09cibUzG1owJqetwj/Oo7yg0foijo9lNH9XWXZfJBYDKgW/6Fomn+CC2EcUS+hisQzt9g==} + engines: {node: '>=14.*'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@biomejs/cli-linux-arm64@1.4.1: + resolution: {integrity: sha512-YIZqfJUg4F+fPsBTXxgD7EU2E5OAYbmYSl/snf4PevwfQCWE/omOFZv+NnIQmjYj9I7ParDgcJvanoA3/kO0JQ==} + engines: {node: '>=14.*'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@biomejs/cli-linux-x64@1.4.1: + resolution: {integrity: sha512-9YOZw3qBd/KUj63A6Hn2zZgzGb2nbESM0qNmeMXgmqinVKM//uc4OgY5TuKITuGjMSvcVxxd4dX1IzYjV9qvNQ==} + engines: {node: '>=14.*'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@biomejs/cli-win32-arm64@1.4.1: + resolution: {integrity: sha512-nWQbvkNKxYn/kCQ0yVF8kCaS3VzaGvtFSmItXiMknU4521LDjJ7tNWH12Gol+pIslrCbd4E1LhJa0a3ThRsBVg==} + engines: {node: '>=14.*'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@biomejs/cli-win32-x64@1.4.1: + resolution: {integrity: sha512-88fR2CQxQ4YLs2BUDuywWYQpUKgU3A3sTezANFc/4LGKQFFLV2yX+F7QAdZVkMHfA+RD9Xg178HomM/6mnTNPA==} + engines: {node: '>=14.*'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@colors/colors@1.5.0: resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} engines: {node: '>=0.1.90'} diff --git a/src/components/auth/SetupAssistant.tsx b/src/components/auth/SetupAssistant.tsx index fdcbba45e..c25495471 100644 --- a/src/components/auth/SetupAssistant.tsx +++ b/src/components/auth/SetupAssistant.tsx @@ -39,10 +39,9 @@ const messages = defineMessages({ }, }); -const transition = - window && window.matchMedia('(prefers-reduced-motion: no-preference)') - ? 'all 0.25s' - : 'none'; +const transition = window?.matchMedia('(prefers-reduced-motion: no-preference)') + ? 'all 0.25s' + : 'none'; const styles = theme => ({ root: { diff --git a/src/components/auth/Welcome.tsx b/src/components/auth/Welcome.tsx index 259e3c335..c1a2db386 100644 --- a/src/components/auth/Welcome.tsx +++ b/src/components/auth/Welcome.tsx @@ -91,8 +91,8 @@ class Welcome extends Component { className="settings__hr-sections" style={{ marginTop: 24, marginBottom: 24, borderStyle: 'solid' }} /> - {/* eslint-disable-next-line react/button-has-type */}