From 1874a4b3e1a49954d96114a978a64a95377df450 Mon Sep 17 00:00:00 2001 From: 1ncounter <1ncounter.100@gmail.com> Date: Fri, 29 Mar 2024 12:58:27 +0800 Subject: [PATCH] chore: lint tool --- .eslintrc.js | 59 ------------------- .husky/commit-msg | 1 + .husky/pre-commit | 1 + .prettierrc.js | 7 --- .stylelintignore | 9 --- .stylelintrc.js | 6 -- commitlint.config.js | 22 ++++++- eslint.config.js | 40 +++++++++++++ package.json | 38 ++++++------ .../package.json | 10 ++-- .../src/api/app.tsx | 0 .../src/api/component.tsx | 0 .../src/component.tsx | 0 .../src/components/app.tsx | 0 .../src/components/outlet.tsx | 0 .../src/components/route.tsx | 0 .../src/components/router-view.tsx | 0 .../src/context/app.ts | 0 .../src/context/router.ts | 0 .../src/index.ts | 0 .../src/renderer.ts | 0 .../src/runtime-api/intl/index.tsx | 0 .../src/runtime-api/intl/parser.ts | 0 .../src/runtime-api/utils.ts | 0 .../src/signals.ts | 0 .../src/utils/element.ts | 0 .../src/utils/reactive.tsx | 0 .../tsconfig.declaration.json | 0 .../tsconfig.json | 0 .../vite.config.ts | 0 .../vitest.config.ts | 0 packages/utils/src/app-helper.ts | 2 +- packages/utils/src/transaction-manager.ts | 2 +- 33 files changed, 89 insertions(+), 108 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 .husky/commit-msg create mode 100644 .husky/pre-commit delete mode 100644 .prettierrc.js delete mode 100644 .stylelintignore delete mode 100644 .stylelintrc.js create mode 100644 eslint.config.js rename packages/{renderer-react => react-renderer}/package.json (86%) rename packages/{renderer-react => react-renderer}/src/api/app.tsx (100%) rename packages/{renderer-react => react-renderer}/src/api/component.tsx (100%) rename packages/{renderer-react => react-renderer}/src/component.tsx (100%) rename packages/{renderer-react => react-renderer}/src/components/app.tsx (100%) rename packages/{renderer-react => react-renderer}/src/components/outlet.tsx (100%) rename packages/{renderer-react => react-renderer}/src/components/route.tsx (100%) rename packages/{renderer-react => react-renderer}/src/components/router-view.tsx (100%) rename packages/{renderer-react => react-renderer}/src/context/app.ts (100%) rename packages/{renderer-react => react-renderer}/src/context/router.ts (100%) rename packages/{renderer-react => react-renderer}/src/index.ts (100%) rename packages/{renderer-react => react-renderer}/src/renderer.ts (100%) rename packages/{renderer-react => react-renderer}/src/runtime-api/intl/index.tsx (100%) rename packages/{renderer-react => react-renderer}/src/runtime-api/intl/parser.ts (100%) rename packages/{renderer-react => react-renderer}/src/runtime-api/utils.ts (100%) rename packages/{renderer-react => react-renderer}/src/signals.ts (100%) rename packages/{renderer-react => react-renderer}/src/utils/element.ts (100%) rename packages/{renderer-react => react-renderer}/src/utils/reactive.tsx (100%) rename packages/{renderer-react => react-renderer}/tsconfig.declaration.json (100%) rename packages/{renderer-react => react-renderer}/tsconfig.json (100%) rename packages/{renderer-react => react-renderer}/vite.config.ts (100%) rename packages/{renderer-react => react-renderer}/vitest.config.ts (100%) diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 972882ce7..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,59 +0,0 @@ -module.exports = { - extends: 'eslint-config-ali/typescript/react', - parserOptions: { - project: [], // for lint performance - createDefaultProgram: false, // for lint performance - }, - rules: { - 'react/no-multi-comp': 0, - 'no-unused-expressions': 0, - 'implicit-arrow-linebreak': 1, - 'no-nested-ternary': 1, - 'no-mixed-operators': 1, - '@typescript-eslint/ban-types': 1, - 'no-shadow': 1, - 'no-prototype-builtins': 1, - 'no-useless-constructor': 1, - 'no-empty-function': 1, - 'lines-between-class-members': 0, - 'no-await-in-loop': 0, - 'no-plusplus': 0, - '@typescript-eslint/no-parameter-properties': 0, - 'no-restricted-exports': ['error'], - 'no-multi-assign': 1, - 'no-dupe-class-members': 1, - 'react/no-deprecated': 1, - 'no-useless-escape': 1, - 'brace-style': 1, - '@typescript-eslint/no-inferrable-types': 0, - 'no-proto': 0, - 'prefer-const': 0, - 'eol-last': 0, - 'react/no-find-dom-node': 0, - 'no-case-declarations': 0, - '@typescript-eslint/indent': 0, - 'import/no-cycle': 0, - '@typescript-eslint/no-shadow': 0, - '@typescript-eslint/method-signature-style': 0, - '@typescript-eslint/consistent-type-assertions': 0, - '@typescript-eslint/no-useless-constructor': 0, - '@typescript-eslint/dot-notation': 0, // for lint performance - '@typescript-eslint/restrict-plus-operands': 0, // for lint performance - 'no-unexpected-multiline': 1, - 'no-multiple-empty-lines': ['error', { max: 1 }], - 'lines-around-comment': ['error', { - beforeBlockComment: true, - afterBlockComment: false, - afterLineComment: false, - allowBlockStart: true, - }], - 'comma-dangle': ['error', 'always-multiline'], - '@typescript-eslint/member-ordering': [ - 'error', - { default: ['signature', 'field', 'constructor', 'method'] } - ], - '@typescript-eslint/no-unused-vars': ['error'], - 'no-redeclare': 0, - '@typescript-eslint/no-redeclare': 1, - }, -}; diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 000000000..66ae5b57c --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +pnpm commitlint --edit $1 \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 000000000..149e04b0f --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +# pnpm lint-staged diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 24c5859e6..000000000 --- a/.prettierrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - printWidth: 100, - tabWidth: 2, - semi: true, - singleQuote: true, - trailingComma: 'all', -}; diff --git a/.stylelintignore b/.stylelintignore deleted file mode 100644 index bec25cf29..000000000 --- a/.stylelintignore +++ /dev/null @@ -1,9 +0,0 @@ -# 忽略目录 -node_modules/ -build/ -dist/ - -# 忽略文件 -**/*.min.css -**/*-min.css -**/*.bundle.css diff --git a/.stylelintrc.js b/.stylelintrc.js deleted file mode 100644 index 2ba42f6d5..000000000 --- a/.stylelintrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - extends: 'stylelint-config-ali', - rules: { - "selector-max-id": 2 - } -}; diff --git a/commitlint.config.js b/commitlint.config.js index 52f3b754b..293105b2c 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,3 +1,21 @@ -module.exports = { - extends: ['ali'], +export default { + extends: ['@commitlint/config-conventional'], + rules: { + 'type-enum': [ + 2, + 'always', + [ + 'feat', + 'fix', + 'docs', + 'chore', + 'style', + 'refactor', + 'ci', + 'test', + 'revert', + 'perf', + ], + ], + } }; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000..e19c03400 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,40 @@ +import stylistic from '@stylistic/eslint-plugin'; +import tsParser from '@typescript-eslint/parser'; +import js from '@eslint/js'; +import reactHooks from 'eslint-plugin-react-hooks'; +import reactRefresh from 'eslint-plugin-react-refresh'; + +export default [ + js.configs.recommended, + { + files: ['**/src/**/*.{ts?(x),js?(x)}'], + plugins: { + '@stylistic': stylistic, + 'react-hooks': reactHooks, + }, + languageOptions: { + parser: tsParser, + }, + rules: { + '@stylistic/indent': ['error', 2], + "@stylistic/indent-binary-ops": ["error", 2], + '@stylistic/max-len': ["error", { "tabWidth": 2 }], + '@stylistic/no-tabs': "error", + '@stylistic/quotes': ["error", "single"], + "@stylistic/jsx-pascal-case": [2], + "@stylistic/jsx-indent": [2, 2, { checkAttributes: true, indentLogicalExpressions: true }], + + 'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks + 'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies + }, + }, + { + files: ['**/src/**/*.{tsx,jsx}'], + plugins: { + 'react-refresh': reactRefresh, + }, + rules: { + 'react-refresh/only-export-components': 'warn', + }, + }, +]; diff --git a/package.json b/package.json index 5b97bd6f6..b2a267782 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "lowcode-engine-repo", + "name": "@alilc/lowcode-monorepo", "private": true, + "type": "module", "scripts": { "playground": "pnpm --filter playground dev", "test": "pnpm -r test", "build": "pnpm -r build", "clean": "rimraf ./packages/*/dist", "clean:lib": "rimraf ./node_modules ./packages/*/node_modules", - "lint": "f2elint scan -q -i ./packages/*/src", - "lint:fix": "f2elint fix -i ./packages/*/src", + "lint": "eslint --cache --no-warn-ignored", "pub": "npm run watchdog:build && lerna publish patch --yes --force-publish --exact --no-changelog", "pub:minor": "npm run watchdog:build && lerna publish minor --yes --force-publish --exact --no-changelog", "pub:major": "npm run watchdog:build && lerna publish major --yes --force-publish --exact --no-changelog", @@ -16,37 +16,39 @@ "pub:preminor": "npm run watchdog:build && lerna publish preminor --force-publish --exact --dist-tag beta --preid beta --no-changelog", "pub:prepatch": "npm run watchdog:build && lerna publish prepatch --force-publish --exact --dist-tag beta --preid beta --no-changelog", "pub:prerelease": "npm run watchdog:build && lerna publish prerelease --yes --force-publish --exact --dist-tag beta --preid beta --no-changelog", - "syncOss": "node ./scripts/sync-oss.js" - }, - "husky": { - "hooks": { - "pre-commit": "f2elint commit-file-scan", - "commit-msg": "f2elint commit-msg-scan" - } + "syncOss": "node ./scripts/sync-oss.js", + "prepare": "husky" }, "devDependencies": { "@alilc/build-plugin-lce": "^0.0.5", "@alilc/lowcode-test-mate": "^1.0.1", "@changesets/cli": "^2.27.1", + "@commitlint/cli": "^19.2.1", + "@commitlint/config-conventional": "^19.1.0", + "@eslint/js": "^8.57.0", "@microsoft/api-extractor": "^7.43.0", + "@stylistic/eslint-plugin": "^1.7.0", "@types/node": "^20.11.30", "@types/react-router": "5.1.18", + "@typescript-eslint/parser": "^7.4.0", "@vitejs/plugin-react": "^4.2.1", - "babel-jest": "^26.5.2", - "del": "^6.1.1", - "execa": "^8.0.1", - "f2elint": "^4.2.1", - "gulp": "^4.0.2", + "eslint": "^8.57.0", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.4.6", "husky": "^9.0.11", - "typescript": "^5.4.2", - "prettier": "^3.2.5", + "lint-staged": "^15.2.2", "rimraf": "^5.0.2", "rollup": "^4.13.0", + "typescript": "^5.4.2", "vite": "^5.1.6", "vitest": "^1.3.1" }, "engines": { - "node": ">=18" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0", + "pnpm": ">= 8" + }, + "lint-staged": { + "*": "pnpm lint" }, "repository": "git@github.com:alibaba/lowcode-engine.git" } diff --git a/packages/renderer-react/package.json b/packages/react-renderer/package.json similarity index 86% rename from packages/renderer-react/package.json rename to packages/react-renderer/package.json index 75f6987a6..5013a3a1c 100644 --- a/packages/renderer-react/package.json +++ b/packages/react-renderer/package.json @@ -1,18 +1,18 @@ { - "name": "@alilc/lowcode-renderer-react", + "name": "@alilc/lowcode-react-renderer", "version": "2.0.0-beta.0", "description": "react renderer for ali lowcode engine", "type": "module", "bugs": "https://github.com/alibaba/lowcode-engine/issues", "homepage": "https://github.com/alibaba/lowcode-engine/#readme", "license": "MIT", - "main": "dist/rendererReact.cjs", - "module": "dist/rendererReact.js", + "main": "dist/reactRenderer.cjs", + "module": "dist/reactRenderer.js", "types": "dist/index.d.ts", "exports": { ".": { - "import": "./dist/rendererReact.js", - "require": "./dist/rendererReact.cjs", + "import": "./dist/reactRenderer.js", + "require": "./dist/reactRenderer.cjs", "types": "./dist/index.d.ts" } }, diff --git a/packages/renderer-react/src/api/app.tsx b/packages/react-renderer/src/api/app.tsx similarity index 100% rename from packages/renderer-react/src/api/app.tsx rename to packages/react-renderer/src/api/app.tsx diff --git a/packages/renderer-react/src/api/component.tsx b/packages/react-renderer/src/api/component.tsx similarity index 100% rename from packages/renderer-react/src/api/component.tsx rename to packages/react-renderer/src/api/component.tsx diff --git a/packages/renderer-react/src/component.tsx b/packages/react-renderer/src/component.tsx similarity index 100% rename from packages/renderer-react/src/component.tsx rename to packages/react-renderer/src/component.tsx diff --git a/packages/renderer-react/src/components/app.tsx b/packages/react-renderer/src/components/app.tsx similarity index 100% rename from packages/renderer-react/src/components/app.tsx rename to packages/react-renderer/src/components/app.tsx diff --git a/packages/renderer-react/src/components/outlet.tsx b/packages/react-renderer/src/components/outlet.tsx similarity index 100% rename from packages/renderer-react/src/components/outlet.tsx rename to packages/react-renderer/src/components/outlet.tsx diff --git a/packages/renderer-react/src/components/route.tsx b/packages/react-renderer/src/components/route.tsx similarity index 100% rename from packages/renderer-react/src/components/route.tsx rename to packages/react-renderer/src/components/route.tsx diff --git a/packages/renderer-react/src/components/router-view.tsx b/packages/react-renderer/src/components/router-view.tsx similarity index 100% rename from packages/renderer-react/src/components/router-view.tsx rename to packages/react-renderer/src/components/router-view.tsx diff --git a/packages/renderer-react/src/context/app.ts b/packages/react-renderer/src/context/app.ts similarity index 100% rename from packages/renderer-react/src/context/app.ts rename to packages/react-renderer/src/context/app.ts diff --git a/packages/renderer-react/src/context/router.ts b/packages/react-renderer/src/context/router.ts similarity index 100% rename from packages/renderer-react/src/context/router.ts rename to packages/react-renderer/src/context/router.ts diff --git a/packages/renderer-react/src/index.ts b/packages/react-renderer/src/index.ts similarity index 100% rename from packages/renderer-react/src/index.ts rename to packages/react-renderer/src/index.ts diff --git a/packages/renderer-react/src/renderer.ts b/packages/react-renderer/src/renderer.ts similarity index 100% rename from packages/renderer-react/src/renderer.ts rename to packages/react-renderer/src/renderer.ts diff --git a/packages/renderer-react/src/runtime-api/intl/index.tsx b/packages/react-renderer/src/runtime-api/intl/index.tsx similarity index 100% rename from packages/renderer-react/src/runtime-api/intl/index.tsx rename to packages/react-renderer/src/runtime-api/intl/index.tsx diff --git a/packages/renderer-react/src/runtime-api/intl/parser.ts b/packages/react-renderer/src/runtime-api/intl/parser.ts similarity index 100% rename from packages/renderer-react/src/runtime-api/intl/parser.ts rename to packages/react-renderer/src/runtime-api/intl/parser.ts diff --git a/packages/renderer-react/src/runtime-api/utils.ts b/packages/react-renderer/src/runtime-api/utils.ts similarity index 100% rename from packages/renderer-react/src/runtime-api/utils.ts rename to packages/react-renderer/src/runtime-api/utils.ts diff --git a/packages/renderer-react/src/signals.ts b/packages/react-renderer/src/signals.ts similarity index 100% rename from packages/renderer-react/src/signals.ts rename to packages/react-renderer/src/signals.ts diff --git a/packages/renderer-react/src/utils/element.ts b/packages/react-renderer/src/utils/element.ts similarity index 100% rename from packages/renderer-react/src/utils/element.ts rename to packages/react-renderer/src/utils/element.ts diff --git a/packages/renderer-react/src/utils/reactive.tsx b/packages/react-renderer/src/utils/reactive.tsx similarity index 100% rename from packages/renderer-react/src/utils/reactive.tsx rename to packages/react-renderer/src/utils/reactive.tsx diff --git a/packages/renderer-react/tsconfig.declaration.json b/packages/react-renderer/tsconfig.declaration.json similarity index 100% rename from packages/renderer-react/tsconfig.declaration.json rename to packages/react-renderer/tsconfig.declaration.json diff --git a/packages/renderer-react/tsconfig.json b/packages/react-renderer/tsconfig.json similarity index 100% rename from packages/renderer-react/tsconfig.json rename to packages/react-renderer/tsconfig.json diff --git a/packages/renderer-react/vite.config.ts b/packages/react-renderer/vite.config.ts similarity index 100% rename from packages/renderer-react/vite.config.ts rename to packages/react-renderer/vite.config.ts diff --git a/packages/renderer-react/vitest.config.ts b/packages/react-renderer/vitest.config.ts similarity index 100% rename from packages/renderer-react/vitest.config.ts rename to packages/react-renderer/vitest.config.ts diff --git a/packages/utils/src/app-helper.ts b/packages/utils/src/app-helper.ts index 86b535c59..97caaa890 100644 --- a/packages/utils/src/app-helper.ts +++ b/packages/utils/src/app-helper.ts @@ -1,4 +1,4 @@ -import EventEmitter from 'events'; +import { EventEmitter } from 'events'; let instance: AppHelper | null = null; diff --git a/packages/utils/src/transaction-manager.ts b/packages/utils/src/transaction-manager.ts index 1e1c951f6..feb9b7a11 100644 --- a/packages/utils/src/transaction-manager.ts +++ b/packages/utils/src/transaction-manager.ts @@ -1,6 +1,6 @@ import { IPublicEnumTransitionType } from '@alilc/lowcode-types'; import { runInAction } from 'mobx'; -import EventEmitter from 'events'; +import { EventEmitter } from 'events'; class TransactionManager { emitter = new EventEmitter();