Add code linting and formatting (#154)

This commit is contained in:
Piotr Rogowski 2023-09-14 22:19:57 +02:00 committed by GitHub
parent 8ffcbfa230
commit af720ef597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 224 additions and 54 deletions

View File

@ -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"
]
}
},

View File

@ -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

View File

@ -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 }}

View File

@ -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"

View File

@ -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

View File

@ -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"
]
}

10
.vscode/settings.json vendored
View File

@ -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",

View File

@ -30,6 +30,8 @@ Docusaurus guides: [https://docusaurus.io/docs/category/guides](https://docusaur
```bash
npm run lint
npm run lint:fix
```
### Build

44
biome.json Normal file
View File

@ -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"
}
}
}

View File

@ -1,7 +1,7 @@
{
"label": "Intro - Start Here",
"link": {
"type": "generated-index",
"description": "Where to start learning about FOME."
}
}
"label": "Intro - Start Here",
"link": {
"type": "generated-index",
"description": "Where to start learning about FOME."
}
}

View File

@ -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"
}
}
"label": "Fundamentals of FOME tuning",
"link": {
"type": "generated-index",
"description": "The place to learn how to start tuning your FOME Hardware"
}
}

View File

@ -4,4 +4,4 @@
"type": "generated-index",
"description": "Information on all sensor inputs and data outputs"
}
}
}

View File

@ -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: [
{

118
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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();

View File

@ -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
/*