diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index beaaf776..00000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -index.js -src/lib -dist -libs/app.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 4da408b6..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = { - root: true, - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - extends: [ - 'plugin:@typescript-eslint/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript', - 'prettier', - ], - rules: { - '@typescript-eslint/no-var-requires': 'off', - '@typescript-eslint/no-namespace': 'off', - '@typescript-eslint/no-explicit-any': 'warn', - 'import/order': [ - 'error', - { - groups: [ - 'builtin', - 'external', - 'internal', - 'parent', - 'sibling', - 'index', - 'object', - 'unknown', - ], - alphabetize: { - order: 'asc', - caseInsensitive: true, - }, - 'newlines-between': 'always', - }, - ], - }, - settings: { - 'import/parsers': { - '@typescript-eslint/parser': ['.ts', '.tsx'], - }, - 'import/resolver': { - typescript: { - alwaysTryTypes: true, // always try to resolve types under `@types` directory even it doesn't contain any source code, like `@types/unist` - project: '.', - }, - }, - }, -}; diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index e3bff860..00000000 --- a/.prettierignore +++ /dev/null @@ -1,5 +0,0 @@ -index.js -src/lib -libs/app.js -dist -.yarn diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index a7394074..00000000 --- a/.prettierrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "singleQuote": true, - "semi": true, - "trailingComma": "all", - "tabWidth": 2, - "printWidth": 80 -} diff --git a/__tests__/__mocks__/webhooks.ts b/__tests__/__mocks__/webhooks.ts index 358d2208..81272715 100644 --- a/__tests__/__mocks__/webhooks.ts +++ b/__tests__/__mocks__/webhooks.ts @@ -5,9 +5,8 @@ import { GitHubEventWorker, IOctokitShape } from '@/queue/worker/github'; export class MockGitHubEventWorker extends GitHubEventWorker { async createGitHubApp(botId: string): Promise { - const appSetting = await GitHubKVManager.instance().getAppSettingById( - botId, - ); + const appSetting = + await GitHubKVManager.instance().getAppSettingById(botId); const webhooks = new Webhooks<{ secret: undefined; diff --git a/__tests__/fixtures/generated/index.ts b/__tests__/fixtures/generated/index.ts index e9a02112..3b4b1173 100644 --- a/__tests__/fixtures/generated/index.ts +++ b/__tests__/fixtures/generated/index.ts @@ -2,16 +2,16 @@ import { CommitCommentCreatedEvent, - DiscussionCreatedEvent, DiscussionCommentCreatedEvent, + DiscussionCreatedEvent, IssueCommentCreatedEvent, - PullRequestOpenedEvent, PullRequestClosedEvent, - PullRequestReviewSubmittedEvent, - PullRequestReviewDismissedEvent, + PullRequestOpenedEvent, PullRequestReviewCommentCreatedEvent, PullRequestReviewCommentDeletedEvent, PullRequestReviewCommentEditedEvent, + PullRequestReviewDismissedEvent, + PullRequestReviewSubmittedEvent, } from '@octokit/webhooks-types'; import _commit_comment_611372_0_created from './commit_comment_611372_0_created.json'; @@ -19,11 +19,11 @@ import _discussion_90_0_created from './discussion_90_0_created.json'; import _discussion_comment_90_0_created from './discussion_comment_90_0_created.json'; import _issue_comment_1_0_created from './issue_comment_1_0_created.json'; import _pull_request_2_0_opened from './pull_request_2_0_opened.json'; +import _pull_request_2_3_closed from './pull_request_2_3_closed.json'; +import _pull_request_2_4_closed from './pull_request_2_4_closed.json'; import _pull_request_2_12_opened from './pull_request_2_12_opened.json'; import _pull_request_2_13_opened from './pull_request_2_13_opened.json'; import _pull_request_2_14_opened from './pull_request_2_14_opened.json'; -import _pull_request_2_3_closed from './pull_request_2_3_closed.json'; -import _pull_request_2_4_closed from './pull_request_2_4_closed.json'; import _pull_request_2_review_comment_0_created from './pull_request_2_review_comment_0_created.json'; import _pull_request_2_review_comment_1_created from './pull_request_2_review_comment_1_created.json'; import _pull_request_2_review_comment_2_created from './pull_request_2_review_comment_2_created.json'; diff --git a/__tests__/fixtures/index.ts b/__tests__/fixtures/index.ts index 6c9d6bb7..c8da71de 100644 --- a/__tests__/fixtures/index.ts +++ b/__tests__/fixtures/index.ts @@ -1,11 +1,11 @@ import { + IssueCommentCreatedEvent, + IssuesOpenedEvent, PullRequestEditedEvent, - PullRequestReviewSubmittedEvent, + PullRequestOpenedEvent, PullRequestReviewCommentCreatedEvent, + PullRequestReviewSubmittedEvent, ReleasePublishedEvent, - IssuesOpenedEvent, - PullRequestOpenedEvent, - IssueCommentCreatedEvent, } from '@octokit/webhooks-types'; import _antd_mini_release_published from './antd_mini_release_published.json'; diff --git a/__tests__/github/render.test.ts b/__tests__/github/render.test.ts index d4cc9dcb..2386d5d1 100644 --- a/__tests__/github/render.test.ts +++ b/__tests__/github/render.test.ts @@ -1,4 +1,4 @@ -import { renderPrOrIssue, render } from '@/github/renderer'; +import { render, renderPrOrIssue } from '@/github/renderer'; import { issue2045, pr2060 } from '../fixtures'; diff --git a/__tests__/github/renderer/make-mark.test.ts b/__tests__/github/renderer/make-mark.test.ts index 6166cb7b..1c639a21 100644 --- a/__tests__/github/renderer/make-mark.test.ts +++ b/__tests__/github/renderer/make-mark.test.ts @@ -1,9 +1,9 @@ -import { readFile } from 'fs/promises'; import path from 'path'; +import { readFile } from 'fs/promises'; import { convertToDingMarkdown } from '@/github/dingtalk'; import { replaceGitHubText } from '@/github/gfm'; -import { parseMarkdown, makeMarkdown } from '@/github/renderer/make-mark'; +import { makeMarkdown, parseMarkdown } from '@/github/renderer/make-mark'; describe('github renderer make-mark', () => { it('parse and make', async () => { diff --git a/__tests__/github/templates/prOrIssue.test.ts b/__tests__/github/templates/prOrIssue.test.ts index 4d9fdf3b..1b4ee344 100644 --- a/__tests__/github/templates/prOrIssue.test.ts +++ b/__tests__/github/templates/prOrIssue.test.ts @@ -1,12 +1,12 @@ -import { handlePr, handleIssue } from '@/github/templates/prOrIssue'; +import { handleIssue, handlePr } from '@/github/templates/prOrIssue'; import { - pull_request_2_3_closed, + issue_opened_event, pull_request_2_0_opened, + pull_request_2_3_closed, pull_request_2_13_opened, - pull_request_edited_wip, pull_request_edited_base, - issue_opened_event, + pull_request_edited_wip, } from '../../fixtures'; import { ctx } from '../ctx'; diff --git a/__tests__/github/templates/release.test.ts b/__tests__/github/templates/release.test.ts index 8d5e1d5e..1539d2fe 100644 --- a/__tests__/github/templates/release.test.ts +++ b/__tests__/github/templates/release.test.ts @@ -1,6 +1,6 @@ import { handleRelease } from '@/github/templates/release'; -import { release_published, antd_mini_release_published } from '../../fixtures'; +import { antd_mini_release_published, release_published } from '../../fixtures'; import { ctx } from '../ctx'; describe('release related', () => { diff --git a/__tests__/github/templates/review.test.ts b/__tests__/github/templates/review.test.ts index c4ebb3e6..d2389bf1 100644 --- a/__tests__/github/templates/review.test.ts +++ b/__tests__/github/templates/review.test.ts @@ -1,5 +1,5 @@ -import { writeFile } from 'fs/promises'; import path from 'path'; +import { writeFile } from 'fs/promises'; import { convertToDingMarkdown } from '@/github/dingtalk'; import { handleReviewComment } from '@/github/templates/comment'; diff --git a/__tests__/github/utils.test.ts b/__tests__/github/utils.test.ts index a25ebb10..be052f76 100644 --- a/__tests__/github/utils.test.ts +++ b/__tests__/github/utils.test.ts @@ -1,8 +1,8 @@ import { sendToDing } from '@/github/dingtalk'; import { - replaceGitHubUrlToMarkdown, - replaceGitHubText, parseGitHubUrl, + replaceGitHubText, + replaceGitHubUrlToMarkdown, } from '@/github/gfm'; import { standardizeMarkdown } from '@/github/renderer/make-mark'; import { handlePr } from '@/github/templates/prOrIssue'; @@ -71,7 +71,7 @@ describe('github utils', () => { const urls = [] as string[]; jest .spyOn(DingUtils, 'send') - .mockImplementation(async (content, url): Promise => { + .mockImplementation(async (_content, url): Promise => { urls.push(url); }); diff --git a/__tests__/queue/index.test.ts b/__tests__/queue/index.test.ts index f4d9f666..6a0d0bc6 100644 --- a/__tests__/queue/index.test.ts +++ b/__tests__/queue/index.test.ts @@ -11,20 +11,20 @@ import { prepareEnv } from '../__mocks__'; import { MockMessageBatch } from '../__mocks__/queue/message'; import { MockGitHubEventWorker } from '../__mocks__/webhooks'; import { - pull_request_2_3_closed, + antd_mini_release_published, + discussion_90_0_created, + discussion_comment_90_0_created, + issue_opened_event, pull_request_2_0_opened, + pull_request_2_3_closed, pull_request_2_13_opened, - pull_request_edited_wip, - pull_request_edited_base, - issue_opened_event, - release_published, - antd_mini_release_published, pull_request_2_review_comment_0_created, - pull_request_review_4_submitted_changes_requested, pull_request_2_review_comment_1_created, - discussion_90_0_created, - discussion_comment_90_0_created, + pull_request_edited_base, + pull_request_edited_wip, + pull_request_review_4_submitted_changes_requested, pull_request_review_submitted_approved, + release_published, } from '../fixtures'; const botId = 'mock'; diff --git a/biome.jsonc b/biome.jsonc new file mode 100644 index 00000000..c6c2814a --- /dev/null +++ b/biome.jsonc @@ -0,0 +1,90 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.2/schema.json", + "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": true }, + "files": { "ignoreUnknown": false, "ignore": ["dist/**"] }, + "formatter": { + "enabled": true, + "useEditorconfig": true, + "formatWithErrors": false, + "indentStyle": "space", + "indentWidth": 2, + "lineEnding": "lf", + "lineWidth": 80, + "attributePosition": "auto", + "bracketSpacing": true, + "ignore": ["**/index.js", "src/lib", "libs/app.js", "**/.yarn"] + }, + "organizeImports": { "enabled": true }, + "linter": { + "enabled": true, + "rules": { + "recommended": false, + "complexity": { "noUselessTypeConstraint": "error" }, + "correctness": { + "noUnusedVariables": "error", + "useArrayLiterals": "off" + }, + "style": { + "noNamespace": "off", + "useAsConstAssertion": "error", + "useBlockStatements": "off" + }, + "suspicious": { + "noExplicitAny": "warn", + "noExtraNonNullAssertion": "error", + "noMisleadingInstantiator": "error", + "noUnsafeDeclarationMerging": "error", + "useNamespaceKeyword": "error" + } + }, + "ignore": ["**/index.js", "dist/**"] + }, + "javascript": { + "formatter": { + "jsxQuoteStyle": "double", + "quoteProperties": "asNeeded", + "trailingCommas": "all", + "semicolons": "always", + "arrowParentheses": "always", + "bracketSameLine": false, + "quoteStyle": "single", + "attributePosition": "auto", + "bracketSpacing": true + } + }, + "overrides": [ + { + "include": ["*.ts", "*.tsx", "*.mts", "*.cts"], + "linter": { + "rules": { + "correctness": { + "noConstAssign": "off", + "noGlobalObjectCalls": "off", + "noInvalidBuiltinInstantiation": "off", + "noInvalidConstructorSuper": "off", + "noNewSymbol": "off", + "noSetterReturn": "off", + "noUndeclaredVariables": "off", + "noUnreachable": "off", + "noUnreachableSuper": "off" + }, + "style": { + "noArguments": "error", + "noVar": "error", + "useConst": "error" + }, + "suspicious": { + "noDuplicateClassMembers": "off", + "noDuplicateObjectKeys": "off", + "noDuplicateParameters": "off", + "noFunctionAssign": "off", + "noImportAssign": "off", + "noRedeclare": "off", + "noUnsafeNegation": "off", + "useGetterReturn": "off" + } + } + } + } + ] +} diff --git a/build-cfworker.ts b/build-cfworker.ts index d797691d..cbfcdda9 100644 --- a/build-cfworker.ts +++ b/build-cfworker.ts @@ -1,9 +1,9 @@ import 'dotenv/config'; -import { context as createContext, Plugin } from 'esbuild'; +import { Plugin, context as createContext } from 'esbuild'; import mri from 'mri'; -import { buildParams, DEFAULT_BUILD_ARGS } from './build'; +import { DEFAULT_BUILD_ARGS, buildParams } from './build'; const argv = mri(process.argv.slice(2)); diff --git a/build-node.ts b/build-node.ts index acc7a89b..60d0bc83 100644 --- a/build-node.ts +++ b/build-node.ts @@ -3,7 +3,7 @@ import 'dotenv/config'; import { context as createContext } from 'esbuild'; import mri from 'mri'; -import { buildParams, DEFAULT_BUILD_ARGS } from './build'; +import { DEFAULT_BUILD_ARGS, buildParams } from './build'; const argv = mri(process.argv.slice(2)); diff --git a/lefthook.yml b/lefthook.yml index 2c5e6be6..238d56f7 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,13 +1,13 @@ pre-commit: parallel: true commands: - eslint: + lint: glob: '*.{js,ts,jsx,tsx}' - run: yarn eslint {staged_files} + run: yarn lint {staged_files} prettier: glob: '*.{js,ts,jsx,tsx,css,less,scss,vue,json,gql,md}' run: | - yarn prettier {staged_files} -w + yarn lint:fix {staged_files} git update-index --again commit-msg: diff --git a/libs/bot-commander/__tests__/index.test.ts b/libs/bot-commander/__tests__/index.test.ts index e415914f..fbaeff30 100644 --- a/libs/bot-commander/__tests__/index.test.ts +++ b/libs/bot-commander/__tests__/index.test.ts @@ -10,7 +10,7 @@ describe('bot-commander', () => { const center = new CommandCenter(); const deferred = new Deferred>(); - center.on('test', async (ctx, command) => { + center.on('test', async (_ctx, command) => { deferred.resolve(command); const text = removeCommandPrefix(command.command, 'test'); console.log(`🚀 ~ center.on ~ text:`, text); @@ -28,11 +28,11 @@ describe('bot-commander', () => { const deferred = new Deferred>(); center.intercept( () => { - center.on('test', async (ctx, command) => { + center.on('test', async (_ctx, command) => { deferred.resolve(command); }); }, - async (ctx, command) => { + async (_ctx, command) => { command.command = 'hacked'; return false; }, @@ -42,11 +42,11 @@ describe('bot-commander', () => { let intercepted = false; center.intercept( () => { - center.on('test2', async (ctx, command) => { + center.on('test2', async (_ctx, _command) => { triggered = true; }); }, - (ctx, command) => { + (_ctx, _command) => { intercepted = true; return true; }, diff --git a/libs/bot-commander/src/center.ts b/libs/bot-commander/src/center.ts index 64e3175b..ee379868 100644 --- a/libs/bot-commander/src/center.ts +++ b/libs/bot-commander/src/center.ts @@ -8,17 +8,17 @@ import { StopError, StopErrorWithReply } from './errors'; import { Registry } from './registry'; import { equalFunc, regex } from './rules'; import type { + BaseContext, + ICommand, IRegexResolveResult, IResolveResult, IStarResolveResult, - TStarHandler, + RegexContext, THandler, + TInterceptor, TRegexHandler, + TStarHandler, TTextHandler, - BaseContext, - ICommand, - RegexContext, - TInterceptor, } from './types'; interface InterceptorStore { diff --git a/libs/cfworker-builder/src/gen-toml.mjs b/libs/cfworker-builder/src/gen-toml.mjs index 8cfb8f89..bc5e2984 100644 --- a/libs/cfworker-builder/src/gen-toml.mjs +++ b/libs/cfworker-builder/src/gen-toml.mjs @@ -1,6 +1,6 @@ import 'dotenv/config'; -import { readFileSync, writeFileSync, watch as _watch } from 'fs'; +import { watch as _watch, readFileSync, writeFileSync } from 'fs'; import MagicString from 'magic-string'; diff --git a/libs/dingtalk-bot/src/index.ts b/libs/dingtalk-bot/src/index.ts index b4e26231..8d6ab084 100644 --- a/libs/dingtalk-bot/src/index.ts +++ b/libs/dingtalk-bot/src/index.ts @@ -9,7 +9,7 @@ function validateTimestamp(timestamp: string) { return true; } return false; - } catch (err) { + } catch (_err) { return false; } } diff --git a/libs/octo-service/src/index.ts b/libs/octo-service/src/index.ts index 356ef752..092887ca 100644 --- a/libs/octo-service/src/index.ts +++ b/libs/octo-service/src/index.ts @@ -556,7 +556,7 @@ export class GitHubService { per_page: 100, }); return data; - } catch (e) {} + } catch (_e) {} return []; } @@ -577,7 +577,7 @@ export class GitHubService { until, }); return data; - } catch (e) {} + } catch (_e) {} return []; } @@ -674,7 +674,7 @@ export class GitHubService { if (isMentor) { return TEAM_MEMBERS.MENTOR; } - } catch (e) {} + } catch (_e) {} try { const isCoreMember = ( @@ -687,7 +687,7 @@ export class GitHubService { if (isCoreMember) { return TEAM_MEMBERS.CORE_MEMBER; } - } catch (e) {} + } catch (_e) {} try { const isContributor = ( @@ -700,7 +700,7 @@ export class GitHubService { if (isContributor) { return TEAM_MEMBERS.CONTRIBUTOR; } - } catch (e) {} + } catch (_e) {} return TEAM_MEMBERS.NONE; } diff --git a/package.json b/package.json index 70327f92..b561b1ce 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,9 @@ "engines": { "node": "18.19.0" }, - "workspaces": [ - "libs/*" - ], + "workspaces": ["libs/*"], "scripts": { - "format": "prettier --write '**/*.{js,css,json,md}'", + "format": "yarn biome format --write", "build": "hereby", "build:libs": "hereby", "build:cfworker": "hereby", @@ -30,8 +28,8 @@ "predeploy:local": "yarn build", "deploy:local": "wrangler deploy", "publish:libs": "lerna publish", - "lint": "eslint . && prettier --check '*.{json,js}' 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'", - "lint:fix": "eslint . --fix && prettier . -w", + "lint": "biome check", + "lint:fix": "yarn biome check --write", "test": "jest --config jest.config.js --verbose", "test:cov": "yarn test --coverage", "extract-fixtures": "tsx scripts/extract-webhook-example.ts", @@ -66,6 +64,7 @@ "tsx": "^3.12.2" }, "devDependencies": { + "@biomejs/biome": "1.9.2", "@cloudflare/workers-types": "^4.20240620.0", "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", @@ -74,21 +73,14 @@ "@types/jest": "^29.4.0", "@types/lodash": "^4.14.191", "@types/node": "^18.11.18", - "@typescript-eslint/eslint-plugin": "^8.3.0", - "@typescript-eslint/parser": "^8.1.0", "dotenv": "^16.3.1", "esbuild": "^0.21.4", - "eslint": "^8.32.0", - "eslint-config-prettier": "^9.1.0", - "eslint-import-resolver-typescript": "^3.5.3", - "eslint-plugin-import": "^2.27.5", "execa": "^9.2.0", "hereby": "^1.9.0", "jest": "^29.4.1", "lefthook": "^1.3.8", "lerna": "^8.1.6", "nodemon": "^3.1.4", - "prettier": "^3.3.3", "smee-client": "^2.0.3", "string.prototype.replaceall": "^1.0.7", "ts-jest": "^29.0.5", diff --git a/scripts/generate-json-schemas-all.mjs b/scripts/generate-json-schemas-all.mjs index 39fbbcd8..1c0acd67 100644 --- a/scripts/generate-json-schemas-all.mjs +++ b/scripts/generate-json-schemas-all.mjs @@ -1,8 +1,8 @@ //@ts-check import { existsSync, mkdirSync } from 'fs'; -import {writeFile} from 'fs/promises'; -import { resolve, dirname as _dirname } from 'path'; +import { dirname as _dirname, resolve } from 'path'; +import { writeFile } from 'fs/promises'; import prettier from 'prettier'; import { createGenerator } from 'ts-json-schema-generator'; @@ -27,7 +27,6 @@ if (prettierConfigFile) { } } - async function usePrettier(schema) { return format(schema, { parser: 'json', diff --git a/scripts/resourceDownloader.ts b/scripts/resourceDownloader.ts index b7f38d17..d8e991cd 100644 --- a/scripts/resourceDownloader.ts +++ b/scripts/resourceDownloader.ts @@ -1,5 +1,5 @@ -import { writeFile } from 'fs/promises'; import path from 'path'; +import { writeFile } from 'fs/promises'; import { Octokit } from '@octokit/rest'; diff --git a/src/ai/conversation/kvManager.ts b/src/ai/conversation/kvManager.ts index d179959e..1a1d8406 100644 --- a/src/ai/conversation/kvManager.ts +++ b/src/ai/conversation/kvManager.ts @@ -1,6 +1,6 @@ import { ChatMessage } from 'chatgpt'; -import { KVManager, DingConversation } from '@/kv'; +import { DingConversation, KVManager } from '@/kv'; import { Message } from '@opensumi/dingtalk-bot/lib/types'; import { IConversationSetting } from './types'; diff --git a/src/api/controllers/configuration.tsx b/src/api/controllers/configuration.tsx index c8273494..387a934f 100644 --- a/src/api/controllers/configuration.tsx +++ b/src/api/controllers/configuration.tsx @@ -6,8 +6,8 @@ import { GitHubKVManager } from '@/kv/github'; import { EValidLevel, LevelSettingsMap, - SettingsNameMap, SettingType, + SettingsNameMap, } from '@/kv/types'; import UnauthorizedHTML from '@/public/configuration/401.html'; import ConfigurationHTML from '@/public/configuration/configuration.html'; @@ -140,10 +140,10 @@ export function route(hono: THono) { return c.html( html`${raw(ConfigurationHTML)}