Skip to content

Commit

Permalink
use biome
Browse files Browse the repository at this point in the history
  • Loading branch information
u1-liquid committed Nov 24, 2024
1 parent b4865fd commit 8f0710a
Show file tree
Hide file tree
Showing 71 changed files with 528 additions and 1,599 deletions.
9 changes: 1 addition & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
"postCreateCommand": "sudo chmod 755 .devcontainer/init.sh && .devcontainer/init.sh",
"customizations": {
"vscode": {
"extensions": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"Vue.volar",
"Orta.vscode-jest",
"dbaeumer.vscode-eslint",
"mrmlnc.vscode-json5"
]
"extensions": ["biomejs.biome", "editorconfig.editorconfig", "Vue.volar", "Orta.vscode-jest", "mrmlnc.vscode-json5"]
}
}
}
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
[*.{json,yml,yaml}]
indent_style = space
4 changes: 1 addition & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ on:
- packages/frontend/**
- packages/sw/**
- packages/misskey-js/**
- packages/shared/.eslintrc.js
pull_request:
paths:
- packages/backend/**
- packages/frontend/**
- packages/sw/**
- packages/misskey-js/**
- packages/shared/.eslintrc.js

jobs:
pnpm_install:
Expand Down Expand Up @@ -63,7 +61,7 @@ jobs:
cache: 'pnpm'
- run: corepack enable
- run: pnpm i --frozen-lockfile
- run: pnpm --filter ${{ matrix.workspace }} run eslint
- run: pnpm --filter ${{ matrix.workspace }} run biome ci --reporter=github --max-diagnostics=none

typecheck:
needs: [pnpm_install]
Expand Down
8 changes: 1 addition & 7 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{
"recommendations": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"Vue.volar",
"Orta.vscode-jest",
"mrmlnc.vscode-json5"
]
"recommendations": ["biomejs.biome", "editorconfig.editorconfig", "Vue.volar", "Orta.vscode-jest", "mrmlnc.vscode-json5"]
}
154 changes: 154 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
"files": {
"ignore": [
"*.min.js",
"api.json",
"built",
"nsfw-model",
"packages/backend/built",
"packages/backend/nsfw-model",
"packages/frontend/built",
"packages/sw/built",
"packages/misskey-js/built",
"packages/misskey-reversi/built",
"packages/misskey-bubble-game/built",
"locales/index.d.ts",
"packages/misskey-js/generator/api.json"
]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"ignore": ["packages/misskey-js/src/autogen"],
"rules": {
"recommended": true,
"complexity": {
"noForEach": "info",
"noUselessConstructor": {
"level": "info",
"fix": "none"
},
"noUselessLabel": {
"level": "info",
"fix": "none"
},
"noUselessUndefinedInitialization": {
"level": "info",
"fix": "none"
},
"useArrowFunction": {
"level": "info",
"fix": "none"
},
"useLiteralKeys": {
"level": "info",
"fix": "none"
},
"useOptionalChain": {
"level": "info",
"fix": "none"
}
},
"performance": {
"noDelete": {
"level": "info",
"fix": "none"
}
},
"style": {
"noCommaOperator": "warn",
"noNegationElse": {
"level": "off",
"fix": "none"
},
"noNonNullAssertion": {
"level": "info",
"fix": "none"
},
"noParameterAssign": "info",
"noUselessElse": {
"level": "info",
"fix": "none"
},
"useImportType": {
"level": "off",
"fix": "none"
},
"useNodejsImportProtocol": {
"level": "off",
"fix": "none"
},
"useTemplate": {
"level": "warn",
"fix": "safe"
}
},
"suspicious": {
"noAssignInExpressions": "info",
"noConfusingVoidType": {
"level": "warn",
"fix": "none"
},
"noDoubleEquals": {
"level": "warn",
"fix": "none",
"options": {
"ignoreNull": false
}
},
"noExplicitAny": "warn",
"noImplicitAnyLet": "warn"
}
}
},
"formatter": {
"enabled": true,
"lineWidth": 140,
"useEditorconfig": true
},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded",
"quoteStyle": "single"
},
"parser": {
"unsafeParameterDecoratorsEnabled": true
}
},
"overrides": [
{
"include": ["packages/backend/migration/*.js", "migration/*.js"],
"linter": {
"rules": {
"style": {
"noUnusedTemplateLiteral": {
"level": "off",
"fix": "none"
}
}
}
}
},
{
"include": ["*.vue"],
"linter": {
"rules": {
"style": {
"useConst": {
"level": "off",
"fix": "none"
},
"useImportType": {
"level": "off",
"fix": "none"
}
}
}
}
}
]
}
15 changes: 15 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md

pre-push:
commands:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc,pug,vue}"
run: pnpm dlx @biomejs/biome check --no-errors-on-unmatched --files-ignore-unknown=true --colors=off --diagnostic-level=error {push_files}

pre-commit:
commands:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc,pug,vue}"
run: pnpm dlx @biomejs/biome check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off --diagnostic-level=error {staged_files}
stage_fixed: true
17 changes: 10 additions & 7 deletions locales/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import * as fs from 'node:fs';
import * as yaml from 'js-yaml';

const merge = (...args) => args.reduce((a, c) => ({
...a,
...c,
...Object.entries(a)
.filter(([k]) => c && typeof c[k] === 'object')
.reduce((a, [k, v]) => (a[k] = merge(v, c[k]), a), {})
}), {});
const merge = (...args) => args.reduce((a, c) => {
for (const [k, v] of Object.entries(c)) {
if (typeof v === 'object' && typeof a[k] === 'object') {
a[k] = merge(a[k], v);
} else {
a[k] = v;
}
}
return a;
}, {});

const languages = [
'ar-SA',
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/MisskeyIO/misskey.git"
},
"packageManager": "pnpm@9.12.3",
"packageManager": "pnpm@9.14.2",
"workspaces": [
"packages/frontend",
"packages/backend",
Expand All @@ -33,6 +33,8 @@
"migrateandstart:docker": "pnpm migrate && exec pnpm start:docker",
"watch": "pnpm dev",
"dev": "node scripts/dev.mjs",
"biome": "biome",
"format": "biome check --write",
"lint": "pnpm -r lint",
"cy:open": "pnpm cypress open --browser --e2e --config-file=cypress.config.ts",
"cy:run": "pnpm cypress run",
Expand Down Expand Up @@ -68,12 +70,11 @@
"typescript": "5.6.3"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/node": "22.9.1",
"@typescript-eslint/eslint-plugin": "7.10.0",
"@typescript-eslint/parser": "7.10.0",
"cross-env": "7.0.3",
"cypress": "13.16.0",
"eslint": "8.57.1",
"lefthook": "1.8.4",
"ncp": "2.0.0",
"start-server-and-test": "2.0.8"
},
Expand Down
4 changes: 0 additions & 4 deletions packages/backend/.eslintignore

This file was deleted.

32 changes: 0 additions & 32 deletions packages/backend/.eslintrc.cjs

This file was deleted.

11 changes: 4 additions & 7 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
"restart": "pnpm build && pnpm start",
"dev": "nodemon -w src -e ts,js,mjs,cjs,json --exec \"cross-env NODE_ENV=development pnpm run restart\"",
"typecheck": "tsc --noEmit && tsc -p test --noEmit",
"eslint": "eslint --quiet \"src/**/*.ts\"",
"lint": "pnpm typecheck && pnpm eslint",
"biome": "biome",
"format": "biome check --write",
"lint": "pnpm typecheck && biome check",
"jest": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --config jest.config.unit.cjs",
"jest:e2e": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --config jest.config.e2e.cjs",
"jest-and-coverage": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --coverage --forceExit --config jest.config.unit.cjs",
Expand Down Expand Up @@ -191,8 +192,8 @@
"xmlbuilder": "15.1.1"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@jest/globals": "29.7.0",
"@misskey-dev/eslint-plugin": "1.0.0",
"@nestjs/platform-express": "10.4.8",
"@simplewebauthn/types": "11.0.0",
"@swc/jest": "0.2.37",
Expand Down Expand Up @@ -234,12 +235,8 @@
"@types/vary": "1.1.3",
"@types/web-push": "3.6.4",
"@types/ws": "8.5.13",
"@typescript-eslint/eslint-plugin": "7.10.0",
"@typescript-eslint/parser": "7.10.0",
"aws-sdk-client-mock": "4.1.0",
"cross-env": "7.0.3",
"eslint": "8.57.1",
"eslint-plugin-import": "2.31.0",
"execa": "9.5.1",
"fkill": "^9.0.0",
"jest": "29.7.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/core/FileInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ export class FileInfoService {
watcher.close();
});
command.run();
for (let i = 1; true; i++) { // eslint-disable-line @typescript-eslint/no-unnecessary-condition
let i = 0;
while (true) {
i++;
const current = `${i}.png`;
const next = `${i + 1}.png`;
const framePath = join(cwd, current);
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/activitypub/ApRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type PrivateKey = {
keyId: string;
};

// biome-ignore lint/complexity/noStaticOnlyClass: utility class
export class ApRequestCreator {
static createSignedPost(args: { key: PrivateKey, url: string, body: string, digest?: string, additionalHeaders: Record<string, string> }): Signed {
const u = new URL(args.url);
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export function bindThis(target: any, key: string, descriptor: any) {
return {
configurable: true,
get() {
// eslint-disable-next-line no-prototype-builtins
if (this === target.prototype || this.hasOwnProperty(key) ||
if (this === target.prototype || Object.hasOwn(this, key) ||
typeof fn !== 'function') {
return fn;
}
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/misc/acct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function parse(acct: string): Acct {
return { username: split[0], host: split[1] ?? null };
}

// biome-ignore lint/suspicious/noShadowRestrictedNames: desired behavior
export function toString(acct: Acct): string {
return acct.host == null ? acct.username : `${acct.username}@${acct.host}`;
}
Loading

0 comments on commit 8f0710a

Please sign in to comment.