From eca9ae89a7a540ccffcabf313ea36bc0b32c7683 Mon Sep 17 00:00:00 2001 From: TechQuery Date: Wed, 19 Mar 2025 00:04:29 +0800 Subject: [PATCH] [refactor] MDX walker supports Async & Front Matter [migrate] upgrade ESLint configuration, MobX-Lark & other latest Upstream packages [remove] some useless Example files --- .env | 1 + eslint.config.mjs | 91 +- package.json | 42 +- pages/_document.tsx | 2 +- pages/api/Lark/bitable/v1/[...slug].ts | 1 + pages/api/Lark/core.ts | 29 +- pages/api/core.ts | 75 ++ pages/api/hello.ts | 12 - pages/api/rich-edit.json | 16 - pages/article/Wiki | 2 +- pages/article/index.tsx | 68 +- pages/pagination.tsx | 2 +- pnpm-lock.yaml | 1659 +++++++++++++++++++----- 13 files changed, 1519 insertions(+), 481 deletions(-) delete mode 100644 pages/api/hello.ts delete mode 100644 pages/api/rich-edit.json diff --git a/.env b/.env index b69254bc2..e645fba4d 100644 --- a/.env +++ b/.env @@ -1,5 +1,6 @@ NEXT_PUBLIC_SITE_NAME=freecodecamp-chengdu.github.io NEXT_PUBLIC_SITE_SUMMARY=Lark project scaffold based on TypeScript, React, Next.js, Bootstrap & Workbox. +NEXT_PUBLIC_LOGO = https://github.com/FreeCodeCamp-Chengdu.png NEXT_PUBLIC_SENTRY_DSN = SENTRY_ORG = diff --git a/eslint.config.mjs b/eslint.config.mjs index 5b45f5340..f28e328e8 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,24 +1,32 @@ -// @ts-check -import { fixupPluginRules } from '@eslint/compat'; -import { FlatCompat } from '@eslint/eslintrc'; +import cspellPlugin from '@cspell/eslint-plugin'; import eslint from '@eslint/js'; +// @ts-expect-error eslint-plugin-next doesn't come with TypeScript definitions +import nextPlugin from '@next/eslint-plugin-next'; +import stylistic from '@stylistic/eslint-plugin'; import eslintConfigPrettier from 'eslint-config-prettier'; -import reactPlugin from 'eslint-plugin-react'; +import react from 'eslint-plugin-react'; import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort'; import globals from 'globals'; import tsEslint from 'typescript-eslint'; import { fileURLToPath } from 'url'; -const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url)), - flatCompat = new FlatCompat(); +/** + * @see{@link https://github.com/typescript-eslint/typescript-eslint/blob/main/eslint.config.mjs} + * @see{@link https://github.com/vercel/next.js/issues/71763#issuecomment-2476838298} + */ + +const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url)); export default tsEslint.config( // register all of the plugins up-front { plugins: { - '@typescript-eslint': tsEslint.plugin, - react: fixupPluginRules(reactPlugin), + '@cspell': cspellPlugin, + '@stylistic': stylistic, 'simple-import-sort': simpleImportSortPlugin, + '@typescript-eslint': tsEslint.plugin, + react, + '@next/next': nextPlugin, }, }, { @@ -34,7 +42,6 @@ export default tsEslint.config( // extends ... eslint.configs.recommended, ...tsEslint.configs.recommended, - ...flatCompat.extends('plugin:@next/next/core-web-vitals'), // base config { @@ -47,13 +54,65 @@ export default tsEslint.config( }, }, rules: { + // spellchecker + '@cspell/spellchecker': [ + 'warn', + { + cspell: { + language: 'en', + dictionaries: [ + 'typescript', + 'node', + 'html', + 'css', + 'bash', + 'npm', + 'pnpm', + ], + }, + }, + ], + // stylistic + '@stylistic/padding-line-between-statements': [ + 'error', + { blankLine: 'always', prev: '*', next: 'return' }, + { blankLine: 'always', prev: 'directive', next: '*' }, + { blankLine: 'any', prev: 'directive', next: 'directive' }, + { + blankLine: 'always', + prev: '*', + next: ['enum', 'interface', 'type'], + }, + ], + 'arrow-body-style': ['error', 'as-needed'], 'no-empty-pattern': 'warn', + 'no-console': ['error', { allow: ['warn', 'error', 'info'] }], + 'no-restricted-syntax': [ + 'error', + { + selector: "TSPropertySignature[key.name='children']", + message: + 'Please use PropsWithChildren instead of defining children manually', + }, + ], + 'consistent-return': 'warn', + 'prefer-destructuring': ['error', { object: true, array: true }], + // simple-import-sort 'simple-import-sort/exports': 'error', 'simple-import-sort/imports': 'error', + // TypeScript '@typescript-eslint/no-unused-vars': 'warn', '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-empty-object-type': 'off', '@typescript-eslint/no-unsafe-declaration-merging': 'warn', + '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], + // React + 'react/no-unescaped-entities': 'off', + 'react/self-closing-comp': ['error', { component: true, html: true }], + 'react/jsx-curly-brace-presence': [ + 'error', + { props: 'never', children: 'never' }, + ], 'react/jsx-no-target-blank': 'warn', 'react/jsx-sort-props': [ 'error', @@ -63,19 +122,11 @@ export default tsEslint.config( noSortAlphabetically: true, }, ], + // Next.js + ...nextPlugin.configs.recommended.rules, + ...nextPlugin.configs['core-web-vitals'].rules, '@next/next/no-sync-scripts': 'warn', }, }, - { - files: ['**/*.js'], - extends: [tsEslint.configs.disableTypeChecked], - rules: { - // turn off other type-aware rules - '@typescript-eslint/internal/no-poorly-typed-ts-props': 'off', - - // turn off rules that don't apply to JS code - '@typescript-eslint/explicit-function-return-type': 'off', - }, - }, eslintConfigPrettier, ); diff --git a/package.json b/package.json index 00141df36..3168eadf7 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,11 @@ "dependencies": { "@mdx-js/loader": "^3.1.0", "@mdx-js/react": "^3.1.0", - "@next/mdx": "^15.2.1", - "@sentry/nextjs": "^9.4.0", + "@next/mdx": "^15.2.3", + "@sentry/nextjs": "^9.6.0", "copy-webpack-plugin": "^13.0.0", "core-js": "^3.41.0", - "file-type": "^20.4.0", + "file-type": "^20.4.1", "idea-react": "^2.0.0-rc.8", "koajax": "^3.1.1", "less": "^4.2.2", @@ -21,16 +21,16 @@ "lodash": "^4.17.21", "marked": "^15.0.7", "mime": "^4.0.6", - "mobx": "^6.13.6", + "mobx": "^6.13.7", "mobx-github": "^0.3.5", "mobx-i18n": "^0.6.0", - "mobx-lark": "^2.0.0", + "mobx-lark": "^2.1.0", "mobx-react": "^9.2.0", "mobx-restful": "^2.1.0", - "mobx-restful-table": "^2.0.1", - "next": "^15.2.1", + "mobx-restful-table": "^2.0.2", + "next": "^15.2.3", "next-pwa": "~5.6.0", - "next-ssr-middleware": "^0.8.9", + "next-ssr-middleware": "^0.8.10", "next-with-less": "^3.0.1", "react": "^19.0.0", "react-bootstrap": "^2.10.9", @@ -38,35 +38,39 @@ "remark-frontmatter": "^5.0.0", "remark-gfm": "^4.0.1", "remark-mdx-frontmatter": "^5.0.0", - "undici": "^7.4.0", + "undici": "^7.5.0", "web-utility": "^4.4.3", - "webpack": "^5.98.0" + "webpack": "^5.98.0", + "yaml": "^2.7.0" }, "devDependencies": { "@babel/plugin-proposal-decorators": "^7.25.9", "@babel/plugin-transform-typescript": "^7.26.8", "@babel/preset-react": "^7.26.3", + "@cspell/eslint-plugin": "^8.17.5", "@eslint/compat": "^1.2.7", "@eslint/eslintrc": "^3.3.0", - "@eslint/js": "^9.21.0", + "@eslint/js": "^9.22.0", + "@next/eslint-plugin-next": "^15.2.3", "@softonus/prettier-plugin-duplicate-remover": "^1.1.2", + "@stylistic/eslint-plugin": "^4.2.0", "@types/eslint-config-prettier": "^6.11.3", "@types/lodash": "^4.17.16", "@types/next-pwa": "^5.6.9", - "@types/node": "^22.13.9", - "@types/react": "^19.0.10", - "eslint": "^9.21.0", - "eslint-config-next": "^15.2.1", - "eslint-config-prettier": "^10.0.2", + "@types/node": "^22.13.10", + "@types/react": "^19.0.11", + "eslint": "^9.22.0", + "eslint-config-next": "^15.2.3", + "eslint-config-prettier": "^10.1.1", "eslint-plugin-react": "^7.37.4", "eslint-plugin-simple-import-sort": "^12.1.1", "globals": "^16.0.0", "husky": "^9.1.7", - "lint-staged": "^15.4.3", + "lint-staged": "^15.5.0", "prettier": "^3.5.3", "prettier-plugin-css-order": "^2.1.2", "typescript": "~5.8.2", - "typescript-eslint": "^8.26.0" + "typescript-eslint": "^8.26.1" }, "resolutions": { "next": "$next" @@ -89,7 +93,7 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint && tsc --noEmit", + "lint": "next lint --fix && tsc --noEmit", "test": "lint-staged && npm run lint", "pack-image": "docker build -t freecodecamp-chengdu/freecodecamp-chengdu.github.io:latest .", "container": "docker rm -f freecodecamp-chengdu.github.io && docker run --name freecodecamp-chengdu.github.io -p 3000:3000 -d freecodecamp-chengdu/freecodecamp-chengdu.github.io:latest" diff --git a/pages/_document.tsx b/pages/_document.tsx index 6c428b7cd..99033ec9f 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -7,7 +7,7 @@ export default function Document() { - +