From cbf57e367e08557c88188384de6e7cc5c7ca4077 Mon Sep 17 00:00:00 2001 From: 1ncounter <1ncounter.100@gmail.com> Date: Tue, 9 Apr 2024 16:50:43 +0800 Subject: [PATCH] ci: add lint --- eslint.config.js | 24 ++++++++++++++++++- package.json | 5 ++-- packages/designer/src/icons/hidden.tsx | 1 + .../designer/src/plugin/plugin-manager.ts | 1 - packages/editor-core/src/di/setter.ts | 2 +- packages/engine/src/shell/api/common.tsx | 24 +++++++++---------- pnpm-workspace.yaml | 1 + scripts/build.js | 20 ++++++++-------- scripts/package.json | 10 ++++++++ scripts/rollup-dts.js | 2 +- scripts/sync-oss.js | 2 +- tsconfig.json | 1 + 12 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 scripts/package.json diff --git a/eslint.config.js b/eslint.config.js index 3bda22ccb..851559db2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,8 +1,10 @@ import stylistic from '@stylistic/eslint-plugin'; import tseslint from 'typescript-eslint' import js from '@eslint/js'; +import react from 'eslint-plugin-react' import reactHooks from 'eslint-plugin-react-hooks'; import reactRefresh from 'eslint-plugin-react-refresh'; +import globals from 'globals' export default tseslint.config({ files: ['packages/*/src/**/*.{ts?(x),js?(x)}'], @@ -13,19 +15,39 @@ export default tseslint.config({ ], plugins: { '@stylistic': stylistic, + react, 'react-hooks': reactHooks, 'react-refresh': reactRefresh }, + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + globals: { + ...globals.browser, + ...globals.nodeBuiltin, + ...globals.jest + }, + }, rules: { '@stylistic/indent': ['error', 2], '@stylistic/indent-binary-ops': ['error', 2], - '@stylistic/max-len': ['error', { tabWidth: 2 }], + '@stylistic/max-len': ['error', { tabWidth: 2, "ignoreStrings": true }], '@stylistic/no-tabs': 'error', '@stylistic/quotes': ['error', 'single'], '@stylistic/jsx-pascal-case': [2], '@stylistic/jsx-indent': [2, 2, { checkAttributes: true, indentLogicalExpressions: true }], '@stylistic/semi': ['error', 'always'], + 'react/jsx-no-undef': 'error', + 'react/jsx-uses-vars': 'error', + 'react/jsx-no-duplicate-props': ['error', { ignoreCase: true }], + 'react/no-this-in-sfc': 'error', + 'react/require-render-return': 'warn', + 'react/no-children-prop': 'warn', + 'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks 'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies diff --git a/package.json b/package.json index bf70c54c0..a8d695306 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "clean": "rimraf ./packages/*/dist", "clean:lib": "rimraf ./node_modules ./packages/*/node_modules", "lint": "eslint . --cache", + "docs": "pnpm --filter @alilc/lowcode-engine-docs run start", "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", @@ -32,13 +33,13 @@ "@types/react-router": "5.1.18", "@vitejs/plugin-react": "^4.2.1", "eslint": "^8.57.0", + "eslint-plugin-react": "^7.34.1", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.6", - "execa": "^8.0.1", + "globals": "^15.0.0", "husky": "^9.0.11", "less": "^4.2.0", "lint-staged": "^15.2.2", - "minimist": "^1.2.8", "rimraf": "^5.0.2", "rollup": "^4.13.0", "typescript": "^5.4.2", diff --git a/packages/designer/src/icons/hidden.tsx b/packages/designer/src/icons/hidden.tsx index ac316d180..cbf2896de 100644 --- a/packages/designer/src/icons/hidden.tsx +++ b/packages/designer/src/icons/hidden.tsx @@ -7,4 +7,5 @@ export function IconHidden(props: IconProps) { ); } + IconHidden.displayName = 'Hidden'; diff --git a/packages/designer/src/plugin/plugin-manager.ts b/packages/designer/src/plugin/plugin-manager.ts index 9d66dd197..cd43cf28f 100644 --- a/packages/designer/src/plugin/plugin-manager.ts +++ b/packages/designer/src/plugin/plugin-manager.ts @@ -9,7 +9,6 @@ import { } from './plugin-types'; import { filterValidOptions, isLowCodeRegisterOptions } from './plugin-utils'; import { LowCodePluginRuntime } from './plugin'; -// eslint-disable-next-line import/no-named-as-default import LowCodePluginContext from './plugin-context'; import { invariant } from '../utils'; import sequencify from './sequencify'; diff --git a/packages/editor-core/src/di/setter.ts b/packages/editor-core/src/di/setter.ts index 5af2c0230..37447bbd9 100644 --- a/packages/editor-core/src/di/setter.ts +++ b/packages/editor-core/src/di/setter.ts @@ -39,7 +39,7 @@ export function registerSetter( function getInitialFromSetter(setter: any) { return setter && ( setter.initial || setter.Initial - || (setter.type && (setter.type.initial || setter.type.Initial)) + || (setter.type && (setter.type.initial || setter.type.Initial)) ) || null; // eslint-disable-line } diff --git a/packages/engine/src/shell/api/common.tsx b/packages/engine/src/shell/api/common.tsx index 8ce07153a..6534968f2 100644 --- a/packages/engine/src/shell/api/common.tsx +++ b/packages/engine/src/shell/api/common.tsx @@ -211,7 +211,7 @@ class SkeletonCabin implements IPublicApiCommonSkeletonCabin { /** * @deprecated */ - get PopupPipe(): any { + get PopupPipe(): any { return InnerPopupPipe; } } @@ -233,9 +233,9 @@ class Utils implements IPublicApiCommonUtils { } getNodeSchemaById( - schema: IPublicTypeNodeSchema, - nodeId: string, - ): IPublicTypeNodeSchema | undefined { + schema: IPublicTypeNodeSchema, + nodeId: string, + ): IPublicTypeNodeSchema | undefined { return innerGetNodeSchemaById(schema, nodeId); } @@ -248,18 +248,18 @@ class Utils implements IPublicApiCommonUtils { } executeTransaction( - fn: () => void, - type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT, - ): void { + fn: () => void, + type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT, + ): void { transactionManager.executeTransaction(fn, type); } createIntl(instance: string | object): { - intlNode(id: string, params?: object): ReactNode; - intl(id: string, params?: object): string; - getLocale(): string; - setLocale(locale: string): void; - } { + intlNode(id: string, params?: object): ReactNode; + intl(id: string, params?: object): string; + getLocale(): string; + setLocale(locale: string): void; + } { return innerCreateIntl(instance); } diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 79d051d7c..3162b4d65 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -2,3 +2,4 @@ packages: - 'packages/*' - 'playground' - 'docs' + - 'scripts' diff --git a/scripts/build.js b/scripts/build.js index 8e3aad054..85e6b3243 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,25 +1,25 @@ import { resolve } from 'node:path'; import { existsSync } from 'node:fs'; import { readdir } from 'node:fs/promises'; -import { argv } from 'node:process'; -import { URL } from 'node:url' +import { argv, cwd } from 'node:process'; import minimist from 'minimist'; import { execa } from 'execa'; +import { findWorkspacePackages } from '@pnpm/workspace.find-packages' const args = minimist(argv.slice(2)); -const targets = args['_'][0].split(','); -const formatArgs = args['format']; +const targets = args['_'][0]; +const formatArgs = args['formats']; const prod = args['prod'] || args['p']; -const packagesUrl = new URL('../packages', import.meta.url); - async function run() { - const packageDirs = await readdir(packagesUrl.pathname); - const targetPackages = packageDirs - .filter((dir) => targets.includes(dir)) + const packages = await findWorkspacePackages(cwd()); + const targetPackageName = `@alilc/lowcode-${targets[0]}` + + const finalName = packages + .filter((item) => item.manifest.name.includes(targetPackageName)) .filter((dir) => existsSync(resolve(packagesUrl.pathname, dir))); - await execa('pnpm', ['--filter', `@alilc/lowcode-${targetPackages[0]}`, 'build:target'], { + await execa('pnpm', ['--filter', finalName, 'build:target'], { stdio: 'inherit', env: { FORMATS: !prod ? formatArgs : undefined, diff --git a/scripts/package.json b/scripts/package.json new file mode 100644 index 000000000..e6f95b6e5 --- /dev/null +++ b/scripts/package.json @@ -0,0 +1,10 @@ +{ + "name": "scripts", + "private": true, + "type": "module", + "devDependencies": { + "@pnpm/workspace.find-packages": "^1.1.12", + "execa": "^8.0.1", + "minimist": "^1.2.8" + } +} \ No newline at end of file diff --git a/scripts/rollup-dts.js b/scripts/rollup-dts.js index 24a5477b1..526937f8f 100644 --- a/scripts/rollup-dts.js +++ b/scripts/rollup-dts.js @@ -1,7 +1,7 @@ import { join } from 'node:path'; import { existsSync, readdirSync } from 'node:fs'; import { env, exit } from 'node:process' -import * as console from 'node:console' +import console from 'node:console' import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'; import { rimraf } from 'rimraf'; diff --git a/scripts/sync-oss.js b/scripts/sync-oss.js index 24749334f..2c5cef73e 100644 --- a/scripts/sync-oss.js +++ b/scripts/sync-oss.js @@ -1,7 +1,7 @@ #!/usr/bin/env node import { request } from 'node:http'; import packageJson from '../packages/engine/package.json'; -import * as console from 'node:console'; +import console from 'node:console'; import { Buffer } from 'node:buffer' const { version, name } = packageJson; diff --git a/tsconfig.json b/tsconfig.json index 12cf1f01c..3aefccdb6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,6 +33,7 @@ "removeComments": false, "baseUrl": ".", "rootDir": ".", + // provide type friendly tips "paths": { "@alilc/lowcode-*": ["packages/*/src"] }