From b42f36dfe6221a477f600ed39c764ba29a9abfba Mon Sep 17 00:00:00 2001 From: Michael Kochell <6913320+mickmister@users.noreply.github.com> Date: Wed, 17 Jan 2024 02:37:23 -0500 Subject: [PATCH] Add Biome tool and CI checks for linting etc. (#3) * add linter * run lint * add ci workflow for lint checks etc. * rename ci job --- .github/workflows/ci.yml | 21 +++ biome.json | 27 ++++ package-lock.json | 228 +++++++++++++++++++++++++++ package.json | 3 + server/src/express_app.ts | 18 ++- server/src/modules/jam.tsx | 82 +++++----- server/src/modules/login.tsx | 21 ++- server/src/types/app_dependencies.ts | 5 +- server/src/views/layout.tsx | 26 +-- tests-e2e/package.json | 1 - 10 files changed, 361 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 biome.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d39f44d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: CI +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + ci: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Install application dependencies + run: npm ci + + - name: Run biome ci process + run: npm run ci diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..b502d74 --- /dev/null +++ b/biome.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.5.2/schema.json", + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 4 + }, + "javascript": { + "formatter": { + "enabled": true, + "jsxQuoteStyle": "single", + "semicolons": "always", + "bracketSpacing": false, + "bracketSameLine": false, + "quoteStyle": "single" + } + } +} diff --git a/package-lock.json b/package-lock.json index 09ec96b..f203244 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "ws": "^8.16.0" }, "devDependencies": { + "@biomejs/biome": "1.5.2", "@kitajs/ts-html-plugin": "^1.3.3", "@types/express": "^4.17.21", "@types/express-ws": "^3.0.4", @@ -541,6 +542,161 @@ "node": ">=6.9.0" } }, + "node_modules/@biomejs/biome": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.5.2.tgz", + "integrity": "sha512-LhycxGQBQLmfv6M3e4tMfn/XKcUWyduDYOlCEBrHXJ2mMth2qzYt1JWypkWp+XmU/7Hl2dKvrP4mZ5W44+nWZw==", + "dev": true, + "hasInstallScript": true, + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.*" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.5.2", + "@biomejs/cli-darwin-x64": "1.5.2", + "@biomejs/cli-linux-arm64": "1.5.2", + "@biomejs/cli-linux-arm64-musl": "1.5.2", + "@biomejs/cli-linux-x64": "1.5.2", + "@biomejs/cli-linux-x64-musl": "1.5.2", + "@biomejs/cli-win32-arm64": "1.5.2", + "@biomejs/cli-win32-x64": "1.5.2" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.5.2.tgz", + "integrity": "sha512-3JVl08aHKsPyf0XL9SEj1lssIMmzOMAn2t1zwZKBiy/mcZdb0vuyMSTM5haMQ/90wEmrkYN7zux777PHEGrGiw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.5.2.tgz", + "integrity": "sha512-QAPW9rZb/AgucUx+ogMg+9eJNipQDqvabktC5Tx4Aqb/mFzS6eDqNP7O0SbGz3DtC5Y2LATEj6o6zKIQ4ZT+3w==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.5.2.tgz", + "integrity": "sha512-fVLrUgIlo05rO4cNu+Py5EwwmXnXhWH+8KrNlWkr2weMYjq85SihUsuWWKpmqU+bUVR+m5gwfcIXZVWYVCJMHw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.5.2.tgz", + "integrity": "sha512-Z29SjaOyO4QfajplNXSjLx17S79oPN42D094zjE24z7C7p3NxvLhKLygtSP9emgaXkcoESe2chOzF4IrGy/rlg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.5.2.tgz", + "integrity": "sha512-ixqJtUHtF0ho1+1DTZQLAEwHGSqvmvHhAAFXZQoaSdABn+IcITYExlFVA3bGvASy/xtPjRhTx42hVwPtLwMHwg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.5.2.tgz", + "integrity": "sha512-ZolquPEjWYUmGeERS8svHOOT7OXEeoriPnV8qptgWJmYF9EO9HUGRn1UtCvdVziDYK+u1A7PxjOdkY1B00ty5A==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.5.2.tgz", + "integrity": "sha512-DN4cXSAoFTdjOoh7f+JITj1uQgQSXt+1pVea9bFrpbgip+ZwkONqQq+jUcmFMMehbp9LuiVtNXFz/ReHn6FY7A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.5.2.tgz", + "integrity": "sha512-YvWWXZmk936FdrXqc2jcP6rfsXsNBIs9MKBQQoVXIihwNNRiAaBD9Iwa/ouU1b7Zxq2zETgeuRewVJickFuVOw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.*" + } + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", @@ -4468,6 +4624,78 @@ "to-fast-properties": "^2.0.0" } }, + "@biomejs/biome": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.5.2.tgz", + "integrity": "sha512-LhycxGQBQLmfv6M3e4tMfn/XKcUWyduDYOlCEBrHXJ2mMth2qzYt1JWypkWp+XmU/7Hl2dKvrP4mZ5W44+nWZw==", + "dev": true, + "requires": { + "@biomejs/cli-darwin-arm64": "1.5.2", + "@biomejs/cli-darwin-x64": "1.5.2", + "@biomejs/cli-linux-arm64": "1.5.2", + "@biomejs/cli-linux-arm64-musl": "1.5.2", + "@biomejs/cli-linux-x64": "1.5.2", + "@biomejs/cli-linux-x64-musl": "1.5.2", + "@biomejs/cli-win32-arm64": "1.5.2", + "@biomejs/cli-win32-x64": "1.5.2" + } + }, + "@biomejs/cli-darwin-arm64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.5.2.tgz", + "integrity": "sha512-3JVl08aHKsPyf0XL9SEj1lssIMmzOMAn2t1zwZKBiy/mcZdb0vuyMSTM5haMQ/90wEmrkYN7zux777PHEGrGiw==", + "dev": true, + "optional": true + }, + "@biomejs/cli-darwin-x64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.5.2.tgz", + "integrity": "sha512-QAPW9rZb/AgucUx+ogMg+9eJNipQDqvabktC5Tx4Aqb/mFzS6eDqNP7O0SbGz3DtC5Y2LATEj6o6zKIQ4ZT+3w==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-arm64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.5.2.tgz", + "integrity": "sha512-fVLrUgIlo05rO4cNu+Py5EwwmXnXhWH+8KrNlWkr2weMYjq85SihUsuWWKpmqU+bUVR+m5gwfcIXZVWYVCJMHw==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-arm64-musl": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.5.2.tgz", + "integrity": "sha512-Z29SjaOyO4QfajplNXSjLx17S79oPN42D094zjE24z7C7p3NxvLhKLygtSP9emgaXkcoESe2chOzF4IrGy/rlg==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-x64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.5.2.tgz", + "integrity": "sha512-ixqJtUHtF0ho1+1DTZQLAEwHGSqvmvHhAAFXZQoaSdABn+IcITYExlFVA3bGvASy/xtPjRhTx42hVwPtLwMHwg==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-x64-musl": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.5.2.tgz", + "integrity": "sha512-ZolquPEjWYUmGeERS8svHOOT7OXEeoriPnV8qptgWJmYF9EO9HUGRn1UtCvdVziDYK+u1A7PxjOdkY1B00ty5A==", + "dev": true, + "optional": true + }, + "@biomejs/cli-win32-arm64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.5.2.tgz", + "integrity": "sha512-DN4cXSAoFTdjOoh7f+JITj1uQgQSXt+1pVea9bFrpbgip+ZwkONqQq+jUcmFMMehbp9LuiVtNXFz/ReHn6FY7A==", + "dev": true, + "optional": true + }, + "@biomejs/cli-win32-x64": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.5.2.tgz", + "integrity": "sha512-YvWWXZmk936FdrXqc2jcP6rfsXsNBIs9MKBQQoVXIihwNNRiAaBD9Iwa/ouU1b7Zxq2zETgeuRewVJickFuVOw==", + "dev": true, + "optional": true + }, "@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", diff --git a/package.json b/package.json index 9cafbe6..dec22c3 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "main": "index.js", "devDependencies": { + "@biomejs/biome": "1.5.2", "@kitajs/ts-html-plugin": "^1.3.3", "@types/express": "^4.17.21", "@types/express-ws": "^3.0.4", @@ -24,6 +25,8 @@ "scripts": { "start": "node dist/server/index.js", "build": "ts-node esbuild.config.ts", + "lint": "biome lint server", + "ci": "biome ci server", "start-coverage": "nyc --reporter=lcov --reporter=text ts-node server/src/index.ts", "dev": "ts-node-dev --respawn --transpile-only server/src/index.ts", "build-coverage": "COVERAGE=true npm run build", diff --git a/server/src/express_app.ts b/server/src/express_app.ts index 3d4c134..dd02881 100644 --- a/server/src/express_app.ts +++ b/server/src/express_app.ts @@ -1,18 +1,20 @@ import express, {Router} from 'express'; import expressWs from 'express-ws'; +import {initJamRouterWebsocket, jamRouter, renderJamPage} from './modules/jam'; +import {loginRouter, renderLoginPage} from './modules/login'; import {AppDependencies} from './types/app_dependencies'; import {renderLayout} from './views/layout'; -import {loginRouter, renderLoginPage} from './modules/login'; -import {initJamRouterWebsocket, jamRouter, renderJamPage} from './modules/jam'; -const handlePage = (renderer: () => string | Promise): express.Handler => async (req, res, next) => { - const page = await Promise.resolve(renderer()); - const fullContent = renderLayout(page); +const handlePage = + (renderer: () => string | Promise): express.Handler => + async (req, res, next) => { + const page = await Promise.resolve(renderer()); + const fullContent = renderLayout(page); - res.setHeader('Content-Type', 'text/html'); - res.send(fullContent); -}; + res.setHeader('Content-Type', 'text/html'); + res.send(fullContent); + }; export const initApp = (deps: AppDependencies) => { const app = expressWs(express()).app; diff --git a/server/src/modules/jam.tsx b/server/src/modules/jam.tsx index ae7a05b..8c05874 100644 --- a/server/src/modules/jam.tsx +++ b/server/src/modules/jam.tsx @@ -16,23 +16,13 @@ enum ROUTES { type JamState = { availableChords: string[]; selectedChords: string[]; -} +}; const jamState: JamState = { - availableChords: [ - 'C', - 'Dm', - 'Em', - 'F', - 'G', - 'Am', - ], - selectedChords: [ - - ], + availableChords: ['C', 'Dm', 'Em', 'F', 'G', 'Am'], + selectedChords: [], }; - const connectedSockets: WebSocket[] = []; export const initJamRouterWebsocket = () => { @@ -49,30 +39,35 @@ export const initJamRouterWebsocket = () => { console.log('ws closed'); connectedSockets.splice(connectedSockets.indexOf(ws), 1); }); - }); }; const refreshAll = () => { - connectedSockets.forEach((ws) => { + for (const ws of connectedSockets) { ws.send(JamView().toString()); - }); -} + } +}; -jamRouter.post(ROUTES.JAM_ACTIONS_ADD_CHORD, (req, res) => { - const {chord} = req.query; - jamState.selectedChords.push(chord); +jamRouter.post( + ROUTES.JAM_ACTIONS_ADD_CHORD, + (req, res) => { + const {chord} = req.query; + jamState.selectedChords.push(chord); - res.send(JamView()); - refreshAll(); -}); + res.send(JamView()); + refreshAll(); + }, +); -jamRouter.post(ROUTES.JAM_ACTIONS_NEW_JAM, (req, res) => { - jamState.selectedChords = []; +jamRouter.post( + ROUTES.JAM_ACTIONS_NEW_JAM, + (req, res) => { + jamState.selectedChords = []; - res.send(JamView()); - refreshAll(); -}); + res.send(JamView()); + refreshAll(); + }, +); export const renderJamPage = () => { return JamPage(); @@ -81,18 +76,22 @@ export const renderJamPage = () => { export const JamPage = () => { return ( <> -
+
- ) -} + ); +}; export const JamView = () => { const chordNames = jamState.availableChords; const selectedChords = jamState.selectedChords; return ( -
+
@@ -104,42 +103,41 @@ const DraftViewSection = (props: {selectedChords: string[]}) => { return (
{props.selectedChords.map((chordName) => ( - + {chordName} ))}
); -} +}; const ChordSelectorSection = (props: {availableChords: string[]}) => { return (
{props.availableChords.map((chordName) => ( ))}
); -} +}; const NewJamButton = () => { return ( - ) + ); }; diff --git a/server/src/modules/login.tsx b/server/src/modules/login.tsx index bfe8fd6..37c6c75 100644 --- a/server/src/modules/login.tsx +++ b/server/src/modules/login.tsx @@ -1,7 +1,7 @@ /// -import express from 'express'; import Html from '@kitajs/html'; +import express from 'express'; export const loginRouter = express.Router(); @@ -12,16 +12,27 @@ loginRouter.post(loginSubmissionRoute, (req, res) => { }); export const renderLoginPage = () => { - return ; -} + return ; +}; export const LoginView = () => { return ( -
+
diff --git a/server/src/types/app_dependencies.ts b/server/src/types/app_dependencies.ts index 3bcfc59..ed92639 100644 --- a/server/src/types/app_dependencies.ts +++ b/server/src/types/app_dependencies.ts @@ -1,3 +1,2 @@ -export type AppDependencies = { - -} +// biome-ignore lint/complexity/noBannedTypes: Temporarily making an empty object +export type AppDependencies = {}; diff --git a/server/src/views/layout.tsx b/server/src/views/layout.tsx index b22efa8..f64af99 100644 --- a/server/src/views/layout.tsx +++ b/server/src/views/layout.tsx @@ -4,29 +4,31 @@ type HtmlContent = string | JSX.Element; type LayoutProps = { content: HtmlContent; -} +}; export const renderLayout = (content: HtmlContent) => { - return ( - - ); + return ; }; const Layout = ({content}: LayoutProps) => { return ( <> {''} - + - - + + Jam Tools -