From 493cdc19ba5481eb28a1e2cb2d877b8d76c7cb9a Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 29 Jan 2024 23:28:03 +0800 Subject: [PATCH] chore: recover format --- .eslintrc.json | 11 ++- .husky/pre-commit | 1 + babel.config.js | 5 +- lib/index.ts | 20 ++--- lib/utils/git-hash.ts | 2 +- package.json | 11 ++- pnpm-lock.yaml | 196 ++++++++++++++++++++++++++++++++++++++++++ test/app.ts | 6 +- 8 files changed, 229 insertions(+), 23 deletions(-) create mode 100644 .husky/pre-commit diff --git a/.eslintrc.json b/.eslintrc.json index c37b0f81e2..16ddfe3595 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,8 @@ { - "extends": ["eslint:recommended", "plugin:n/recommended", "plugin:unicorn/recommended", "plugin:prettier/recommended", "plugin:yml/recommended"], - "plugins": ["prettier", "@stylistic/js", "unicorn"], + "extends": ["eslint:recommended", "plugin:n/recommended", "plugin:unicorn/recommended", "plugin:prettier/recommended", "plugin:yml/recommended", "plugin:@typescript-eslint/recommended"], + "parser": "@typescript-eslint/parser", + "root": true, + "plugins": ["prettier", "@stylistic/js", "unicorn", "@typescript-eslint"], "parserOptions": { "ecmaVersion": "latest", "sourceType": "module" @@ -111,7 +113,10 @@ "n/no-process-exit": 0, "n/no-unpublished-require": ["error", { "allowModules": ["tosource"] }], "prettier/prettier": 0, - "yml/quotes": ["error", { "prefer": "single" }] + "yml/quotes": ["error", { "prefer": "single" }], + "@typescript-eslint/no-var-requires": 0, + "@typescript-eslint/no-explicit-any": 0, + "n/no-missing-import": 0 }, "overrides": [ { diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000000..2312dc587f --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npx lint-staged diff --git a/babel.config.js b/babel.config.js index e7118c30a9..a3092abe53 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,6 +1,3 @@ module.exports = { - presets: [ - ['@babel/preset-env', {targets: {node: 'current'}}], - '@babel/preset-typescript', - ], + presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'], }; diff --git a/lib/index.ts b/lib/index.ts index e846fd95f5..7364ba4861 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,16 +1,16 @@ -import { serve } from '@hono/node-server' -import logger from '@/utils/logger' -import { config } from '@/config' -import app from '@/app' +import { serve } from '@hono/node-server'; +import logger from '@/utils/logger'; +import { config } from '@/config'; +import app from '@/app'; -const port = config.connect.port +const port = config.connect.port; -logger.info(`🎉 RSSHub is running on port ${port}! Cheers!`) +logger.info(`🎉 RSSHub is running on port ${port}! Cheers!`); logger.info('💖 Can you help keep this open source project alive? Please sponsor 👉 https://docs.rsshub.app/support'); serve({ - fetch: app.fetch, - port -}) + fetch: app.fetch, + port, +}); -export default app +export { default } from '@/app'; diff --git a/lib/utils/git-hash.ts b/lib/utils/git-hash.ts index 2eafc589dd..85e255faa6 100644 --- a/lib/utils/git-hash.ts +++ b/lib/utils/git-hash.ts @@ -1,6 +1,6 @@ import gitRevSync from 'git-rev-sync'; -let gitHash = process.env.HEROKU_SLUG_COMMIT?.slice(0, 7) || process.env.VERCEL_GIT_COMMIT_SHA?.slice(0, 7) +let gitHash = process.env.HEROKU_SLUG_COMMIT?.slice(0, 7) || process.env.VERCEL_GIT_COMMIT_SHA?.slice(0, 7); if (!gitHash) { try { gitHash = gitRevSync.short(); diff --git a/package.json b/package.json index fa006236b2..70f0568205 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "build:maintainer": "node scripts/workflow/build-maintainer.js", "build:radar": "node scripts/workflow/build-radar.js", "dev": "cross-env NODE_ENV=dev tsx watch lib/index.ts", - "format": "eslint --cache --fix \"**/*.{js,yml}\" && node website/docs/.format/format.mjs && prettier \"**/*.{js,json}\" --write", - "format:check": "eslint --cache \"**/*.{js,yml}\" && prettier \"**/*.{js,json}\" --check", + "format": "eslint --cache --fix \"**/*.{ts,js,yml}\" && node website/docs/.format/format.mjs && prettier \"**/*.{ts,js,json}\" --write", + "format:check": "eslint --cache \"**/*.{ts,js,yml}\" && prettier \"**/*.{ts,js,json}\" --check", "format:staged": "lint-staged", "jest": "cross-env NODE_ENV=test jest --runInBand --forceExit --detectOpenHandles", "jest:coverage": "cross-env NODE_ENV=test jest --coverage --reporters=default --reporters=jest-junit --runInBand --forceExit --detectOpenHandles", @@ -41,6 +41,10 @@ "eslint --cache --fix", "prettier --ignore-unknown --ignore-path ./.gitignore --write" ], + "*.ts": [ + "eslint --cache --fix", + "prettier --ignore-unknown --ignore-path ./.gitignore --write" + ], "*.md?(x)": "node website/docs/.format/format.mjs --staged", "*.yml": "eslint --cache --fix" }, @@ -182,6 +186,8 @@ "@types/supertest": "6.0.2", "@types/tiny-async-pool": "2.0.3", "@types/tough-cookie": "4.0.5", + "@typescript-eslint/eslint-plugin": "6.19.1", + "@typescript-eslint/parser": "6.19.1", "@vercel/nft": "0.26.2", "cross-env": "7.0.3", "eslint": "8.56.0", @@ -216,6 +222,7 @@ "tosource": "2.0.0-alpha.3", "ts-jest": "29.1.2", "tsx": "4.7.0", + "typescript": "5.3.3", "unified": "9.2.2", "unist-util-visit": "4.1.2", "unist-util-visit-parents": "5.1.3" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0dcf450bdf..0292674df2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -322,6 +322,12 @@ devDependencies: '@types/tough-cookie': specifier: 4.0.5 version: 4.0.5 + '@typescript-eslint/eslint-plugin': + specifier: 6.19.1 + version: 6.19.1(@typescript-eslint/parser@6.19.1)(eslint@8.56.0)(typescript@5.3.3) + '@typescript-eslint/parser': + specifier: 6.19.1 + version: 6.19.1(eslint@8.56.0)(typescript@5.3.3) '@vercel/nft': specifier: 0.26.2 version: 0.26.2 @@ -424,6 +430,9 @@ devDependencies: tsx: specifier: 4.7.0 version: 4.7.0 + typescript: + specifier: 5.3.3 + version: 5.3.3 unified: specifier: 9.2.2 version: 9.2.2 @@ -2993,6 +3002,10 @@ packages: '@types/node': 20.11.5 dev: false + /@types/semver@7.5.6: + resolution: {integrity: sha512-dn1l8LaMea/IjDoHNd9J52uBbInB796CDffS6VdIxvqYCPSG0V0DzHp76GpaWnlhg88uYyPbXCDIowa86ybd5A==} + dev: true + /@types/send@0.17.1: resolution: {integrity: sha512-Cwo8LE/0rnvX7kIIa3QHCkcuF21c05Ayb0ZfxPiv0W8VRiZiNW/WuRupHKpqqGVGf7SUA44QSOUKaEd9lIrd/Q==} dependencies: @@ -3064,6 +3077,138 @@ packages: dev: false optional: true + /@typescript-eslint/eslint-plugin@6.19.1(@typescript-eslint/parser@6.19.1)(eslint@8.56.0)(typescript@5.3.3): + resolution: {integrity: sha512-roQScUGFruWod9CEyoV5KlCYrubC/fvG8/1zXuT0WTcxX87GnMMmnksMwSg99lo1xiKrBzw2icsJPMAw1OtKxg==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + '@typescript-eslint/parser': ^6.0.0 || ^6.0.0-alpha + eslint: ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@eslint-community/regexpp': 4.8.0 + '@typescript-eslint/parser': 6.19.1(eslint@8.56.0)(typescript@5.3.3) + '@typescript-eslint/scope-manager': 6.19.1 + '@typescript-eslint/type-utils': 6.19.1(eslint@8.56.0)(typescript@5.3.3) + '@typescript-eslint/utils': 6.19.1(eslint@8.56.0)(typescript@5.3.3) + '@typescript-eslint/visitor-keys': 6.19.1 + debug: 4.3.4 + eslint: 8.56.0 + graphemer: 1.4.0 + ignore: 5.2.4 + natural-compare: 1.4.0 + semver: 7.5.4 + ts-api-utils: 1.0.3(typescript@5.3.3) + typescript: 5.3.3 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/parser@6.19.1(eslint@8.56.0)(typescript@5.3.3): + resolution: {integrity: sha512-WEfX22ziAh6pRE9jnbkkLGp/4RhTpffr2ZK5bJ18M8mIfA8A+k97U9ZyaXCEJRlmMHh7R9MJZWXp/r73DzINVQ==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/scope-manager': 6.19.1 + '@typescript-eslint/types': 6.19.1 + '@typescript-eslint/typescript-estree': 6.19.1(typescript@5.3.3) + '@typescript-eslint/visitor-keys': 6.19.1 + debug: 4.3.4 + eslint: 8.56.0 + typescript: 5.3.3 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/scope-manager@6.19.1: + resolution: {integrity: sha512-4CdXYjKf6/6aKNMSly/BP4iCSOpvMmqtDzRtqFyyAae3z5kkqEjKndR5vDHL8rSuMIIWP8u4Mw4VxLyxZW6D5w==} + engines: {node: ^16.0.0 || >=18.0.0} + dependencies: + '@typescript-eslint/types': 6.19.1 + '@typescript-eslint/visitor-keys': 6.19.1 + dev: true + + /@typescript-eslint/type-utils@6.19.1(eslint@8.56.0)(typescript@5.3.3): + resolution: {integrity: sha512-0vdyld3ecfxJuddDjACUvlAeYNrHP/pDeQk2pWBR2ESeEzQhg52DF53AbI9QCBkYE23lgkhLCZNkHn2hEXXYIg==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/typescript-estree': 6.19.1(typescript@5.3.3) + '@typescript-eslint/utils': 6.19.1(eslint@8.56.0)(typescript@5.3.3) + debug: 4.3.4 + eslint: 8.56.0 + ts-api-utils: 1.0.3(typescript@5.3.3) + typescript: 5.3.3 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/types@6.19.1: + resolution: {integrity: sha512-6+bk6FEtBhvfYvpHsDgAL3uo4BfvnTnoge5LrrCj2eJN8g3IJdLTD4B/jK3Q6vo4Ql/Hoip9I8aB6fF+6RfDqg==} + engines: {node: ^16.0.0 || >=18.0.0} + dev: true + + /@typescript-eslint/typescript-estree@6.19.1(typescript@5.3.3): + resolution: {integrity: sha512-aFdAxuhzBFRWhy+H20nYu19+Km+gFfwNO4TEqyszkMcgBDYQjmPJ61erHxuT2ESJXhlhrO7I5EFIlZ+qGR8oVA==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/types': 6.19.1 + '@typescript-eslint/visitor-keys': 6.19.1 + debug: 4.3.4 + globby: 11.1.0 + is-glob: 4.0.3 + minimatch: 9.0.3 + semver: 7.5.4 + ts-api-utils: 1.0.3(typescript@5.3.3) + typescript: 5.3.3 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/utils@6.19.1(eslint@8.56.0)(typescript@5.3.3): + resolution: {integrity: sha512-JvjfEZuP5WoMqwh9SPAPDSHSg9FBHHGhjPugSRxu5jMfjvBpq5/sGTD+9M9aQ5sh6iJ8AY/Kk/oUYVEMAPwi7w==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: ^7.0.0 || ^8.0.0 + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@8.56.0) + '@types/json-schema': 7.0.12 + '@types/semver': 7.5.6 + '@typescript-eslint/scope-manager': 6.19.1 + '@typescript-eslint/types': 6.19.1 + '@typescript-eslint/typescript-estree': 6.19.1(typescript@5.3.3) + eslint: 8.56.0 + semver: 7.5.4 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + + /@typescript-eslint/visitor-keys@6.19.1: + resolution: {integrity: sha512-gkdtIO+xSO/SmI0W68DBg4u1KElmIUo3vXzgHyGPs6cxgB0sa3TlptRAAE0hUY1hM6FcDKEv7aIwiTGm76cXfQ==} + engines: {node: ^16.0.0 || >=18.0.0} + dependencies: + '@typescript-eslint/types': 6.19.1 + eslint-visitor-keys: 3.4.3 + dev: true + /@ungap/structured-clone@1.2.0: resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} dev: true @@ -3278,6 +3423,11 @@ packages: engines: {node: '>=0.10.0'} dev: false + /array-union@2.1.0: + resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} + engines: {node: '>=8'} + dev: true + /art-template@4.13.2: resolution: {integrity: sha512-04ws5k+ndA5DghfheY4c8F1304XJKeTcaXqZCLpxFkNMSkaR3ChW1pX2i9d3sEEOZuLy7de8lFriRaik1jEeOQ==} engines: {node: '>= 1.0.0'} @@ -3529,6 +3679,12 @@ packages: balanced-match: 1.0.2 concat-map: 0.0.1 + /brace-expansion@2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + dependencies: + balanced-match: 1.0.2 + dev: true + /braces@3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} engines: {node: '>=8'} @@ -4412,6 +4568,13 @@ packages: engines: {node: '>=0.3.1'} dev: true + /dir-glob@3.0.1: + resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} + engines: {node: '>=8'} + dependencies: + path-type: 4.0.0 + dev: true + /directory-import@3.2.1: resolution: {integrity: sha512-hIMc9WJHs4HRZbBiNAvKGxkhjaJ2wOaFcFA0K+yj16GyBJDg28e6QgQ3hFuFB0ZRETNYZu3u85rmxIxoxWEwbA==} engines: {node: '>=18.17.0'} @@ -5502,6 +5665,18 @@ packages: type-fest: 0.20.2 dev: true + /globby@11.1.0: + resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==} + engines: {node: '>=10'} + dependencies: + array-union: 2.1.0 + dir-glob: 3.0.1 + fast-glob: 3.3.1 + ignore: 5.2.4 + merge2: 1.4.1 + slash: 3.0.0 + dev: true + /google-auth-library@9.0.0: resolution: {integrity: sha512-IQGjgQoVUAfOk6khqTVMLvWx26R+yPw9uLyb1MNyMQpdKiKt0Fd9sp4NWoINjyGHR8S3iw12hMTYK7O8J07c6Q==} engines: {node: '>=14'} @@ -8265,6 +8440,13 @@ packages: dependencies: brace-expansion: 1.1.11 + /minimatch@9.0.3: + resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minipass@3.3.6: resolution: {integrity: sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==} engines: {node: '>=8'} @@ -8804,6 +8986,11 @@ packages: resolution: {integrity: sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==} dev: false + /path-type@4.0.0: + resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} + engines: {node: '>=8'} + dev: true + /peberminta@0.9.0: resolution: {integrity: sha512-XIxfHpEuSJbITd1H3EeQwpcZbTLHc+VVr8ANI9t5sit565tsI4/xK3KWTUFE2e6QiangUkh3B0jihzmGnNrRsQ==} dev: false @@ -10386,6 +10573,15 @@ packages: resolution: {integrity: sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==} dev: true + /ts-api-utils@1.0.3(typescript@5.3.3): + resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} + engines: {node: '>=16.13.0'} + peerDependencies: + typescript: '>=4.2.0' + dependencies: + typescript: 5.3.3 + dev: true + /ts-custom-error@2.2.2: resolution: {integrity: sha512-I0FEdfdatDjeigRqh1JFj67bcIKyRNm12UVGheBjs2pXgyELg2xeiQLVaWu1pVmNGXZVnz/fvycSU41moBIpOg==} engines: {node: '>=8.0.0'} diff --git a/test/app.ts b/test/app.ts index afa6995466..9c04db3360 100644 --- a/test/app.ts +++ b/test/app.ts @@ -4,8 +4,8 @@ import app from '../lib/app'; describe('index', () => { it('serve index', async () => { - const res = await app.request('/') - expect(res.status).toBe(200) - expect(await res.text()).toContain('Welcome to RSSHub!') + const res = await app.request('/'); + expect(res.status).toBe(200); + expect(await res.text()).toContain('Welcome to RSSHub!'); }); });