From af720ef5973d5799dbff17ba31ba38e9c631e84b Mon Sep 17 00:00:00 2001 From: Piotr Rogowski Date: Thu, 14 Sep 2023 22:19:57 +0200 Subject: [PATCH] Add code linting and formatting (#154) --- .devcontainer/devcontainer.json | 3 +- .github/workflows/build.yml | 6 +- .github/workflows/deploy-preview.yml | 5 +- .github/workflows/deploy.yml | 8 +- .github/workflows/lint.yml | 18 +-- .vscode/extensions.json | 3 +- .vscode/settings.json | 10 ++ README.md | 2 + biome.json | 44 +++++++ docs/02-Intro-Start-Here/_category_.json | 12 +- .../03-Fundamentals-Of-Tuning/_category_.json | 12 +- docs/04-Sensors-And-Gauges/_category_.json | 2 +- docusaurus.config.js | 19 +-- package-lock.json | 118 ++++++++++++++++++ package.json | 6 +- scripts/linkValidator.js | 8 +- sidebars.js | 2 +- 17 files changed, 224 insertions(+), 54 deletions(-) create mode 100644 biome.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 31f8701..527287f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,7 +20,8 @@ // NOTE: keep this in sync with: .vscode/extensions.json "extensions": [ "davidanson.vscode-markdownlint", - "streetsidesoftware.code-spell-checker" + "streetsidesoftware.code-spell-checker", + "biomejs.biome" ] } }, diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83dd71b..50e008b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ concurrency: on: pull_request: - branches: [ master ] + branches: [master] jobs: validate: @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: ".nvmrc" + cache: "npm" - run: npm ci - run: npm run build diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 67bd9f9..d40b7ab 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -40,7 +40,6 @@ jobs: const fs = require('fs'); fs.writeFileSync('${{github.workspace}}/build.zip', Buffer.from(download.data)); - run: unzip build.zip -d build - - name: Deploy preview to Cloudflare Pages id: deploy uses: cloudflare/pages-action@v1 @@ -50,9 +49,9 @@ jobs: projectName: wiki directory: build gitHubToken: ${{ secrets.GITHUB_TOKEN }} # GitHub Deployments - wranglerVersion: '3' + wranglerVersion: "3" - - name: 'Comment on PR' + - name: "Comment on PR" uses: actions/github-script@v3 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2798466..7933bd0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,7 +7,7 @@ concurrency: on: push: - branches: [ master ] + branches: [master] env: PRINCE_VER: 15.1 @@ -25,8 +25,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: ".nvmrc" + cache: "npm" - name: Install PrinceXML run: | @@ -65,4 +65,4 @@ jobs: directory: build gitHubToken: ${{ secrets.GITHUB_TOKEN }} # GitHub Deployments branch: master - wranglerVersion: '3' + wranglerVersion: "3" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d702c82..b7dee0e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,20 +12,20 @@ concurrency: on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: - typescript: + code: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: ".nvmrc" + cache: "npm" - run: npm ci - run: npm run lint:ts @@ -36,8 +36,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: ".nvmrc" + cache: "npm" - run: npm ci - run: npm run lint:links @@ -48,7 +48,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: ".nvmrc" + cache: "npm" - run: npm ci - run: npm run lint:md diff --git a/.vscode/extensions.json b/.vscode/extensions.json index a75b9d6..a4dffcc 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,6 +2,7 @@ // NOTE: keep this in sync with: .devcontainer/devcontainer.json "recommendations": [ "davidanson.vscode-markdownlint", - "streetsidesoftware.code-spell-checker" + "streetsidesoftware.code-spell-checker", + "biomejs.biome" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index fe5988a..676b5b5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,17 @@ { + "typescript.tsdk": "./node_modules/typescript/lib", + "[typescript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "editor.formatOnSave": true, "cSpell.words": [ "Airmass", "autotune", "autotuner", + "biomejs", "bootloader", "CANBUS", "Colour", @@ -11,6 +20,7 @@ "Deadtime", "deadzone", "debugmode", + "devcontainer", "devcontainers", "DFCO", "dyno", diff --git a/README.md b/README.md index 3571495..0eaded8 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Docusaurus guides: [https://docusaurus.io/docs/category/guides](https://docusaur ```bash npm run lint + +npm run lint:fix ``` ### Build diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..a9392f1 --- /dev/null +++ b/biome.json @@ -0,0 +1,44 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.1.2/schema.json", + "organizeImports": { + "enabled": true + }, + "files": { + "ignore": [".devcontainer", ".vscode", "node_modules", ".docusaurus", "build", "pdf"] + }, + "linter": { + "enabled": true, + "rules": { + "all": true, + "style": { + "all": true, + "useEnumInitializers": "off", + "noNonNullAssertion": "off" + }, + "suspicious": { + "all": true, + "noConsoleLog": "off" + }, + "nursery": { + "all": true, + "useExhaustiveDependencies": "off" + }, + "complexity": { + "all": true, + "noForEach": "off" + } + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "lineWidth": 100, + "indentSize": 2 + }, + "javascript": { + "formatter": { + "quoteStyle": "single", + "trailingComma": "all" + } + } +} diff --git a/docs/02-Intro-Start-Here/_category_.json b/docs/02-Intro-Start-Here/_category_.json index 8117301..8bc1c74 100644 --- a/docs/02-Intro-Start-Here/_category_.json +++ b/docs/02-Intro-Start-Here/_category_.json @@ -1,7 +1,7 @@ { - "label": "Intro - Start Here", - "link": { - "type": "generated-index", - "description": "Where to start learning about FOME." - } - } \ No newline at end of file + "label": "Intro - Start Here", + "link": { + "type": "generated-index", + "description": "Where to start learning about FOME." + } +} diff --git a/docs/03-Fundamentals-Of-Tuning/_category_.json b/docs/03-Fundamentals-Of-Tuning/_category_.json index 3e74bb5..a67ebfd 100644 --- a/docs/03-Fundamentals-Of-Tuning/_category_.json +++ b/docs/03-Fundamentals-Of-Tuning/_category_.json @@ -1,7 +1,7 @@ { - "label": "Fundamentals of FOME tuning", - "link": { - "type": "generated-index", - "description": "The place to learn how to start tuning your FOME Hardware" - } - } \ No newline at end of file + "label": "Fundamentals of FOME tuning", + "link": { + "type": "generated-index", + "description": "The place to learn how to start tuning your FOME Hardware" + } +} diff --git a/docs/04-Sensors-And-Gauges/_category_.json b/docs/04-Sensors-And-Gauges/_category_.json index 3211079..f5fcc39 100644 --- a/docs/04-Sensors-And-Gauges/_category_.json +++ b/docs/04-Sensors-And-Gauges/_category_.json @@ -4,4 +4,4 @@ "type": "generated-index", "description": "Information on all sensor inputs and data outputs" } -} \ No newline at end of file +} diff --git a/docusaurus.config.js b/docusaurus.config.js index 22987e2..25bca5f 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -13,11 +13,8 @@ const pdfName = 'wiki.fome.pdf'; const pdfChecksum = () => { const data = fs.readFileSync(`static/pdf/${pdfName}`, 'utf8'); - return crypto - .createHash('md5') - .update(data, 'utf8') - .digest('hex'); -} + return crypto.createHash('md5').update(data, 'utf8').digest('hex'); +}; const pdfUrl = `${isBuild ? url : 'http://localhost:3000'}/pdf/${pdfName}?v=${pdfChecksum()}`; @@ -60,12 +57,9 @@ const config = { routeBasePath: '/', // Serve the docs at the site's root sidebarPath: require.resolve('./sidebars.js'), // Remove this to remove the "edit this page" links. - editUrl: - 'https://github.com/FOME-Tech/wiki/tree/master', + editUrl: 'https://github.com/FOME-Tech/wiki/tree/master', remarkPlugins: [require('remark-math')], - rehypePlugins: [ - [require('rehype-katex'), { output: 'mathml' }] - ], + rehypePlugins: [[require('rehype-katex'), { output: 'mathml' }]], }, blog: false, theme: { @@ -79,8 +73,7 @@ const config = { { href: 'https://cdn.jsdelivr.net/npm/katex@0.13.24/dist/katex.min.css', type: 'text/css', - integrity: - 'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM', + integrity: 'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM', crossorigin: 'anonymous', }, ], @@ -157,7 +150,7 @@ const config = { style: { height: 30, marginTop: -2, - } + }, }, items: [ { diff --git a/package-lock.json b/package-lock.json index 02f51a6..2964ae3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "remark-math": "^3.0.1" }, "devDependencies": { + "@biomejs/biome": "1.1.2", "@docusaurus/module-type-aliases": "^2.4.1", "@tsconfig/docusaurus": "^2.0.0", "docusaurus-prince-pdf": "^1.2.1", @@ -2068,6 +2069,123 @@ "node": ">=6.9.0" } }, + "node_modules/@biomejs/biome": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.1.2.tgz", + "integrity": "sha512-JEVWchqo0Xhl86IJgOh0xESWnNRUXBUDByCBR8TA4lIPzm/6U6Tv77+MblNkZ8MvwCtP6PlBNGdQcGKKabtuHA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.*" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.1.2", + "@biomejs/cli-darwin-x64": "1.1.2", + "@biomejs/cli-linux-arm64": "1.1.2", + "@biomejs/cli-linux-x64": "1.1.2", + "@biomejs/cli-win32-arm64": "1.1.2", + "@biomejs/cli-win32-x64": "1.1.2" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.1.2.tgz", + "integrity": "sha512-YyqWeNZchPxlvxtdo2vMBkzrwllaNS3+DZ6j01mUCVIZE9kAzF/edMV2O38L2AEtnRLU1TI1f71Jai3ThILClg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.1.2.tgz", + "integrity": "sha512-Sofxcu50AHJyQS6Xx3OF2egQQ7Un5YFVF5/umNFa+kSNrrCu/ucmzrk8FcGS2dOSs4L2LqD6ZDWjvbcikjzLYQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.1.2.tgz", + "integrity": "sha512-wtaQgpoVMZEKf1GlDlFGAJP1j6gnh4L4kJN8PQPOBAdKIUZ/YSjqVp0z28vli5xCQ57xCn1gH4Xoqw2gVYu1tQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.1.2.tgz", + "integrity": "sha512-TYIUjCXbY+kxnJgv8GESplMagB1GdOcMV21JGRATqnhUI4BvG6sjs3gfi+sdjLBQdbHhsISXW3yfUlv07HKqhg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.1.2.tgz", + "integrity": "sha512-yApn85KuJ+Ty5zxbqWnaifX4ONtZG+snu12RNKi8fxSVVCXzQ/k2PfsWQbsyvCG05qshSvNKtM54cuf+vhUIsw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.1.2.tgz", + "integrity": "sha512-qebNvIrFj2TJ+K0JVGo1HkgV2y5jis6aOZDC1SWuk53GnqjSLdR+p1v86ZByOjYr1v+tjc67EXmEepk06VVvpA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.*" + } + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", diff --git a/package.json b/package.json index 23740eb..1455afe 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,10 @@ "docusaurus": "docusaurus", "start": "docusaurus start --host 0.0.0.0", "build": "docusaurus build", - "lint": "npm run lint:ts && npm run lint:links && npm run lint:md", + "lint": "npm run lint:biome && npm run lint:ts && npm run lint:links && npm run lint:md", + "lint:biome": "biome check .", + "lint:fix": "biome format --write . && biome check --apply .", + "lint:fix:unsafe": "biome check . --apply-unsafe .", "lint:ts": "tsc", "lint:links": "node scripts/linkValidator.js", "lint:md": "npx markdownlint-cli docs", @@ -32,6 +35,7 @@ "remark-math": "^3.0.1" }, "devDependencies": { + "@biomejs/biome": "1.1.2", "@docusaurus/module-type-aliases": "^2.4.1", "@tsconfig/docusaurus": "^2.0.0", "docusaurus-prince-pdf": "^1.2.1", diff --git a/scripts/linkValidator.js b/scripts/linkValidator.js index 54dbf36..6958b54 100644 --- a/scripts/linkValidator.js +++ b/scripts/linkValidator.js @@ -34,14 +34,12 @@ const validateAbsoluteUrls = (files) => { console.log('❌ Failed\n'); console.log(red(`Absolute URLs to "${wikiUrl}" found in the following files:\n`)); errors.forEach((error) => { - console.log( - `[${error.fileName}:${error.lineNo}] ${error.lineContent.trim()}` - ); + console.log(`[${error.fileName}:${error.lineNo}] ${error.lineContent.trim()}`); }); process.exit(1); } -} +}; /** * Load all md and mdx files from / docs and process them @@ -54,6 +52,6 @@ const main = () => { // validateRelativeUrls(files); console.log('✅ Ok'); -} +}; main(); diff --git a/sidebars.js b/sidebars.js index aa87f6f..f76d9fc 100644 --- a/sidebars.js +++ b/sidebars.js @@ -14,7 +14,7 @@ /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ const sidebars = { // By default, Docusaurus generates a sidebar from the docs folder structure - mainSidebar: [{type: 'autogenerated', dirName: '.'}], + mainSidebar: [{ type: 'autogenerated', dirName: '.' }], // But you can create a sidebar manually /*