diff --git a/packages/designer/.eslintrc.js b/packages/designer/.eslintrc.js new file mode 100644 index 000000000..3209648ec --- /dev/null +++ b/packages/designer/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + extends: 'eslint-config-ali/typescript/react', + rules: { + 'react/no-multi-comp': 1, + 'no-unused-expressions': 1, + 'implicit-arrow-linebreak': 1, + 'no-nested-ternary': 1, + 'no-mixed-operators': 1, + '@typescript-eslint/no-parameter-properties': 1, + '@typescript-eslint/ban-types': 1, + 'no-shadow': 1, + 'no-prototype-builtins': 1, + 'no-useless-constructor': 1, + 'no-empty-function': 1, + } +} \ No newline at end of file diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx index d757e7eb8..0ab451772 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx @@ -38,6 +38,7 @@ export class BorderDetectingInstance extends PureComponent<{ } @observer +// eslint-disable-next-line react/no-multi-comp export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> { shouldComponentUpdate() { return false; diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx index 118f0de63..2a590e096 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx @@ -57,6 +57,7 @@ export default class BoxResizing extends Component<{ host: BuiltinSimulatorHost } @observer +// eslint-disable-next-line react/no-multi-comp export class BoxResizingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> { static contextType = SimulatorContext; @@ -104,6 +105,7 @@ export class BoxResizingForNode extends Component<{ host: BuiltinSimulatorHost; } @observer +// eslint-disable-next-line react/no-multi-comp export class BoxResizingInstance extends Component<{ observed: OffsetObserver; highlight?: boolean; diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx index ae82e67b1..2129d7dc0 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx @@ -55,6 +55,7 @@ export class BorderSelectingInstance extends Component<{ } @observer +// eslint-disable-next-line react/no-multi-comp class Toolbar extends Component<{ observed: OffsetObserver }> { shouldComponentUpdate() { return false; @@ -150,6 +151,7 @@ function createAction(content: ReactNode | ComponentType | ActionContentObj } @observer +// eslint-disable-next-line react/no-multi-comp export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> { get host(): BuiltinSimulatorHost { return this.props.host; @@ -193,6 +195,7 @@ export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHo } @observer +// eslint-disable-next-line react/no-multi-comp export class BorderSelecting extends Component<{ host: BuiltinSimulatorHost }> { get host(): BuiltinSimulatorHost { return this.props.host; diff --git a/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts b/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts index 8b4a3bfd3..7586bd17f 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts +++ b/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts @@ -1,7 +1,7 @@ import { EventEmitter } from 'events'; -import { ISimulatorHost, isSimulatorHost } from '../../simulator'; +import { ISimulatorHost } from '../../simulator'; import { Designer, Point } from '../../designer'; -import { setNativeSelection, cursor } from '@ali/lowcode-utils'; +import { cursor } from '@ali/lowcode-utils'; // import Cursor from './cursor'; // import Pages from './pages'; @@ -19,7 +19,7 @@ function makeEventsHandler( // } docs.add(sourceDoc); // if (sourceDoc !== topDoc || isDragEvent(boostEvent)) { - sensors.forEach((sim) => { + sensors.forEach(sim => { const sdoc = sim.contentDocument; if (sdoc) { docs.add(sdoc); @@ -28,7 +28,7 @@ function makeEventsHandler( // } return (handle: (sdoc: Document) => void) => { - docs.forEach((doc) => handle(doc)); + docs.forEach(doc => handle(doc)); }; } @@ -38,23 +38,11 @@ export default class DragResizeEngine { private dragResizing = false; - constructor(readonly designer: Designer) { + constructor(designer: Designer) { this.designer = designer; this.emitter = new EventEmitter(); } - private getMasterSensors(): ISimulatorHost[] { - return this.designer.project.documents - .map((doc) => { - // TODO: not use actived, - if (doc.actived && doc.simulator?.sensorAvailable) { - return doc.simulator; - } - return null; - }) - .filter(Boolean) as any; - } - isDragResizing() { return this.dragResizing; } @@ -84,14 +72,12 @@ export default class DragResizeEngine { const masterSensors = this.getMasterSensors(); const createResizeEvent = (e: MouseEvent | DragEvent): Point => { - const evt: any = {}; - const sourceDocument = e.view?.document; if (!sourceDocument || sourceDocument === document) { return e; } - const srcSim = masterSensors.find((sim) => sim.contentDocument === sourceDocument); + const srcSim = masterSensors.find(sim => sim.contentDocument === sourceDocument); if (srcSim) { return srcSim.viewport.toGlobalPoint(e); } @@ -100,7 +86,7 @@ export default class DragResizeEngine { const over = (e: MouseEvent) => { const handleEvents = makeEventsHandler(e, masterSensors); - handleEvents((doc) => { + handleEvents(doc => { doc.removeEventListener('mousemove', move, true); doc.removeEventListener('mouseup', over, true); }); @@ -115,7 +101,7 @@ export default class DragResizeEngine { node = boost(e); startEvent = createResizeEvent(e); const handleEvents = makeEventsHandler(e, masterSensors); - handleEvents((doc) => { + handleEvents(doc => { doc.addEventListener('mousemove', move, true); doc.addEventListener('mouseup', over, true); }); @@ -137,7 +123,9 @@ export default class DragResizeEngine { }; } - onResize(func: (e: MouseEvent, direction: string, node: any, moveX: number, moveY: number) => any) { + onResize( + func: (e: MouseEvent, direction: string, node: any, moveX: number, moveY: number) => any, + ) { this.emitter.on('resize', func); return () => { this.emitter.removeListener('resize', func); @@ -150,6 +138,18 @@ export default class DragResizeEngine { this.emitter.removeListener('resizeEnd', func); }; } + + private getMasterSensors(): ISimulatorHost[] { + return this.designer.project.documents + .map(doc => { + // TODO: not use actived, + if (doc.actived && doc.simulator?.sensorAvailable) { + return doc.simulator; + } + return null; + }) + .filter(Boolean) as any; + } } // new DragResizeEngine(); diff --git a/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx b/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx index ee1a4c007..6ed6ef93d 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx @@ -1,6 +1,5 @@ import { Component } from 'react'; -import { computed, observer } from '@ali/lowcode-editor-core'; -import { SimulatorContext } from '../context'; +import { observer } from '@ali/lowcode-editor-core'; import { BuiltinSimulatorHost } from '../host'; import { DropLocation, diff --git a/packages/designer/src/builtin-simulator/host-view.tsx b/packages/designer/src/builtin-simulator/host-view.tsx index 9024f8d60..0d1ab37c0 100644 --- a/packages/designer/src/builtin-simulator/host-view.tsx +++ b/packages/designer/src/builtin-simulator/host-view.tsx @@ -2,7 +2,6 @@ import { Component } from 'react'; import { observer } from '@ali/lowcode-editor-core'; import { BuiltinSimulatorHost, BuiltinSimulatorProps } from './host'; import { DocumentModel } from '../document'; -import { SimulatorContext } from './context'; import { BemTools } from './bem-tools'; import './host.less'; @@ -51,6 +50,7 @@ export class BuiltinSimulatorHostView extends Component { } } +// eslint-disable-next-line react/no-multi-comp @observer class Canvas extends Component<{ host: BuiltinSimulatorHost }> { render() { @@ -73,6 +73,7 @@ class Canvas extends Component<{ host: BuiltinSimulatorHost }> { } } +// eslint-disable-next-line react/no-multi-comp @observer class Content extends Component<{ host: BuiltinSimulatorHost }> { render() { diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 47878ac2d..4679b3338 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -60,6 +60,7 @@ export interface BuiltinSimulatorProps { const defaultSimulatorUrl = (() => { const publicPath = getPublicPath(); let urls; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [_, prefix = '', dev] = /^(.+?)(\/js)?\/?$/.exec(publicPath) || []; if (dev) { urls = [`${prefix}/css/react-simulator-renderer.css`, `${prefix}/js/react-simulator-renderer.js`]; @@ -74,6 +75,7 @@ const defaultSimulatorUrl = (() => { const defaultRaxSimulatorUrl = (() => { const publicPath = getPublicPath(); let urls; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [_, prefix = '', dev] = /^(.+?)(\/js)?\/?$/.exec(publicPath) || []; if (dev) { urls = [`${prefix}/css/rax-simulator-renderer.css`, `${prefix}/js/rax-simulator-renderer.js`]; @@ -503,11 +505,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost last.r) { last.r = rect.right; - computed = true; + _computed = true; } if (rect.bottom > last.b) { last.b = rect.bottom; - computed = true; + _computed = true; } } if (last) { const r: any = new DOMRect(last.x, last.y, last.r - last.x, last.b - last.y); r.elements = elements; - r.computed = computed; + r.computed = _computed; return r; } @@ -734,7 +734,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost 1 - ? instances.find((inst) => this.getClosestNodeInstance(inst, container.id)?.instance === containerInstance) + ? instances.find((_inst) => this.getClosestNodeInstance(_inst, container.id)?.instance === containerInstance) : instances[0] : null; const rect = inst ? this.computeComponentInstanceRect(inst, node.componentMeta.rootSelector) : null; @@ -1164,7 +1164,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost { - return item.isLeaf() && item.getProp('children')?.type === 'literal'; - }); - // TODO: - } + // if (!propTarget) { + // // 自动纯文本编辑满足一下情况: + // // 1. children 内容都是 Leaf 且都是文本(一期) + // // 2. DOM 节点是单层容器,子集都是文本节点 (已满足) + // const isAllText = node.children?.every(item => { + // return item.isLeaf() && item.getProp('children')?.type === 'literal'; + // }); + // // TODO: + // } if (propTarget && setterPropElement) { const prop = node.getProp(propTarget, true)!; @@ -121,8 +121,10 @@ export class LiveEditing { console.info(e.code); switch (e.code) { case 'Enter': + break; // TODO: check is richtext? case 'Escape': + break; case 'Tab': setterPropElement?.blur(); } @@ -130,7 +132,7 @@ export class LiveEditing { // enter // tab }; - const focusout = (e: FocusEvent) => { + const focusout = (/* e: FocusEvent */) => { this.saveAndDispose(); }; setterPropElement.addEventListener('focusout', focusout); diff --git a/packages/designer/src/builtin-simulator/node-selector/index.tsx b/packages/designer/src/builtin-simulator/node-selector/index.tsx index 3062e8b5e..af1f6cb14 100644 --- a/packages/designer/src/builtin-simulator/node-selector/index.tsx +++ b/packages/designer/src/builtin-simulator/node-selector/index.tsx @@ -71,7 +71,7 @@ export default class InstanceNodeSelector extends React.Component { + renderNodes = (/* node: Node */) => { const nodes = this.state.parentNodes || []; const children = nodes.map((node, key) => { return ( diff --git a/packages/designer/src/builtin-simulator/resource-consumer.ts b/packages/designer/src/builtin-simulator/resource-consumer.ts index 9e5ad25bd..38a1aa181 100644 --- a/packages/designer/src/builtin-simulator/resource-consumer.ts +++ b/packages/designer/src/builtin-simulator/resource-consumer.ts @@ -26,14 +26,14 @@ export default class ResourceConsumer { private _providing?: () => void; + private _consuming?: () => void; + constructor(provider: () => T, private consumer?: RendererConsumer) { this._providing = autorun(() => { this._data = provider(); }); } - private _consuming?: () => void; - consume(consumerOrRenderer: BuiltinSimulatorRenderer | ((data: T) => any)) { if (this._consuming) { return; diff --git a/packages/designer/src/builtin-simulator/utils/parse-metadata.ts b/packages/designer/src/builtin-simulator/utils/parse-metadata.ts index d90b249d2..3bcf9d6d4 100644 --- a/packages/designer/src/builtin-simulator/utils/parse-metadata.ts +++ b/packages/designer/src/builtin-simulator/utils/parse-metadata.ts @@ -16,6 +16,7 @@ export const primitiveTypes = [ 'any', ]; +// eslint-disable-next-line @typescript-eslint/ban-types function makeRequired(propType: any, lowcodeType: string | object) { function lowcodeCheckTypeIsRequired(...rest: any[]) { return propType.isRequired(...rest); @@ -32,6 +33,7 @@ function makeRequired(propType: any, lowcodeType: string | object) { return lowcodeCheckTypeIsRequired; } +// eslint-disable-next-line @typescript-eslint/ban-types function define(propType: any = PropTypes.any, lowcodeType: string | object = {}) { if (!propType._inner && propType.name !== 'lowcodeCheckType') { propType.lowcodeType = lowcodeType; diff --git a/packages/designer/src/builtin-simulator/utils/throttle.ts b/packages/designer/src/builtin-simulator/utils/throttle.ts index c426837d6..9dcf78c01 100644 --- a/packages/designer/src/builtin-simulator/utils/throttle.ts +++ b/packages/designer/src/builtin-simulator/utils/throttle.ts @@ -1,5 +1,6 @@ const useRAF = typeof requestAnimationFrame === 'function'; +// eslint-disable-next-line @typescript-eslint/ban-types export function throttle(func: Function, delay: number) { let lastArgs: any; let lastThis: any; diff --git a/packages/designer/src/component-meta.ts b/packages/designer/src/component-meta.ts index d57f12d27..c14133262 100644 --- a/packages/designer/src/component-meta.ts +++ b/packages/designer/src/component-meta.ts @@ -13,7 +13,7 @@ import { FieldConfig, } from '@ali/lowcode-types'; import { computed } from '@ali/lowcode-editor-core'; -import { Node, ParentalNode, TransformStage } from './document'; +import { Node, ParentalNode } from './document'; import { Designer } from './designer'; import { intlNode } from './locale'; import { IconContainer } from './icons/container'; @@ -231,6 +231,7 @@ export class ComponentMeta { } @computed get availableActions() { + // eslint-disable-next-line prefer-const let { disableBehaviors, actions } = this._transformedMetadata?.configure.component || {}; const disabled = ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null); actions = builtinComponentActions.concat(this.designer.getGlobalComponentActions() || [], actions || []); @@ -331,6 +332,7 @@ registerMetadataTransducer((metadata) => { if (!component.nestingRule) { let m; // uri match xx.Group set subcontrolling: true, childWhiteList + // eslint-disable-next-line no-cond-assign if ((m = /^(.+)\.Group$/.exec(componentName))) { // component.subControlling = true; if (!component.nestingRule) { @@ -338,16 +340,16 @@ registerMetadataTransducer((metadata) => { childWhitelist: [`${m[1]}`], }; } - } - // uri match xx.Node set selfControlled: false, parentWhiteList - else if ((m = /^(.+)\.Node$/.exec(componentName))) { + // eslint-disable-next-line no-cond-assign + } else if ((m = /^(.+)\.Node$/.exec(componentName))) { + // uri match xx.Node set selfControlled: false, parentWhiteList // component.selfControlled = false; component.nestingRule = { parentWhitelist: [`${m[1]}`, componentName], }; - } - // uri match .Item .Node .Option set parentWhiteList - else if ((m = /^(.+)\.(Item|Node|Option)$/.exec(componentName))) { + // eslint-disable-next-line no-cond-assign + } else if ((m = /^(.+)\.(Item|Node|Option)$/.exec(componentName))) { + // uri match .Item .Node .Option set parentWhiteList component.nestingRule = { parentWhitelist: [`${m[1]}`], }; diff --git a/packages/designer/src/designer/builtin-hotkey.ts b/packages/designer/src/designer/builtin-hotkey.ts index 451b6b308..bc8a698df 100644 --- a/packages/designer/src/designer/builtin-hotkey.ts +++ b/packages/designer/src/designer/builtin-hotkey.ts @@ -245,7 +245,7 @@ hotkey.bind(['option+left', 'option+right'], (e, action) => { } }); -hotkey.bind(['option+up'], (e, action) => { +hotkey.bind(['option+up'], (e) => { const designer = focusing.focusDesigner; const doc = designer?.currentDocument; if (isFormEvent(e) || !doc) { @@ -283,7 +283,7 @@ hotkey.bind(['option+up'], (e, action) => { } }); -hotkey.bind(['option+down'], (e, action) => { +hotkey.bind(['option+down'], (e) => { const designer = focusing.focusDesigner; const doc = designer?.currentDocument; if (isFormEvent(e) || !doc) { diff --git a/packages/designer/src/designer/designer-view.tsx b/packages/designer/src/designer/designer-view.tsx index 43fb3e3a6..6ce25f606 100644 --- a/packages/designer/src/designer/designer-view.tsx +++ b/packages/designer/src/designer/designer-view.tsx @@ -44,7 +44,7 @@ export class DesignerView extends Component !!item).join('-') || parent?.componentMeta?.componentName || ''; + // eslint-disable-next-line no-unused-expressions this.editor?.emit('designer.drag', { time: (endTime - startTime).toFixed(2), selected: nodes @@ -143,6 +144,7 @@ export class Designer { if (!n) { return; } + // eslint-disable-next-line no-shadow const npm = n?.componentMeta?.npm; return ( [npm?.package, npm?.componentName].filter((item) => !!item).join('-') || diff --git a/packages/designer/src/designer/dragon.ts b/packages/designer/src/designer/dragon.ts index 9f40d50e0..e8a696138 100644 --- a/packages/designer/src/designer/dragon.ts +++ b/packages/designer/src/designer/dragon.ts @@ -77,6 +77,7 @@ export interface ISensor { export type DragObject = DragNodeObject | DragNodeDataObject | DragAnyObject; export enum DragObjectType { + // eslint-disable-next-line no-shadow Node = 'node', NodeData = 'nodedata', } @@ -204,8 +205,7 @@ export class Dragon { private emitter = new EventEmitter(); - constructor(readonly designer: Designer) { - } + constructor(readonly designer: Designer) {} /** * Quick listen a shell(container element) drag behavior diff --git a/packages/designer/src/designer/offset-observer.ts b/packages/designer/src/designer/offset-observer.ts index 23012c283..7b4b8bebf 100644 --- a/packages/designer/src/designer/offset-observer.ts +++ b/packages/designer/src/designer/offset-observer.ts @@ -134,7 +134,8 @@ export class OffsetObserver { this._bottom = rect.bottom; this.hasOffset = true; } - this.pid = pid = (window as any).requestIdleCallback(compute); + this.pid = (window as any).requestIdleCallback(compute); + pid = this.pid; }; this.compute = compute; @@ -142,7 +143,8 @@ export class OffsetObserver { // try first compute(); // try second, ensure the dom mounted - this.pid = pid = (window as any).requestIdleCallback(compute); + this.pid = (window as any).requestIdleCallback(compute); + pid = this.pid; } purge() { diff --git a/packages/designer/src/designer/scroller.ts b/packages/designer/src/designer/scroller.ts index 761db0f1d..24070b306 100644 --- a/packages/designer/src/designer/scroller.ts +++ b/packages/designer/src/designer/scroller.ts @@ -53,6 +53,8 @@ export interface IScrollable { export class Scroller { private pid: number | undefined; + constructor(private scrollable: IScrollable) {} + get scrollTarget(): ScrollTarget | null { let target = this.scrollable.scrollTarget; if (!target) { @@ -65,8 +67,6 @@ export class Scroller { return target; } - constructor(private scrollable: IScrollable) {} - scrollTo(options: { left?: number; top?: number }) { this.cancel(); @@ -109,13 +109,15 @@ export class Scroller { scrollTarget.scrollTo(opt); if (time < 1) { - this.pid = pid = requestAnimationFrame(animate); + this.pid = requestAnimationFrame(animate); + pid = this.pid; } else { end(); } }; - this.pid = pid = requestAnimationFrame(animate); + this.pid = requestAnimationFrame(animate); + pid = this.pid; } scrolling(point: { globalX: number; globalY: number }) { diff --git a/packages/designer/src/designer/setting/setting-prop-entry.ts b/packages/designer/src/designer/setting/setting-prop-entry.ts index 577997a68..c219a3091 100644 --- a/packages/designer/src/designer/setting/setting-prop-entry.ts +++ b/packages/designer/src/designer/setting/setting-prop-entry.ts @@ -1,4 +1,4 @@ -import { obx, computed, autorun } from '@ali/lowcode-editor-core'; +import { obx, computed } from '@ali/lowcode-editor-core'; import { IEditor, isJSExpression } from '@ali/lowcode-types'; import { uniqueId } from '@ali/lowcode-utils'; import { SettingEntry } from './setting-entry'; diff --git a/packages/designer/src/designer/setting/setting-top-entry.ts b/packages/designer/src/designer/setting/setting-top-entry.ts index 6434938ab..507fc053c 100644 --- a/packages/designer/src/designer/setting/setting-top-entry.ts +++ b/packages/designer/src/designer/setting/setting-top-entry.ts @@ -2,7 +2,7 @@ import { EventEmitter } from 'events'; import { CustomView, isCustomView, IEditor } from '@ali/lowcode-types'; import { computed } from '@ali/lowcode-editor-core'; import { SettingEntry } from './setting-entry'; -import { SettingField, isSettingField } from './setting-field'; +import { SettingField } from './setting-field'; import { SettingPropEntry } from './setting-prop-entry'; import { Node } from '../../document'; import { ComponentMeta } from '../../component-meta'; diff --git a/packages/designer/src/document/document-model.ts b/packages/designer/src/document/document-model.ts index cd6628a13..fab7bb49e 100644 --- a/packages/designer/src/document/document-model.ts +++ b/packages/designer/src/document/document-model.ts @@ -672,7 +672,7 @@ export class DocumentModel { /** * @deprecated */ - onRefresh(func: () => void) { + onRefresh(/* func: () => void */) { console.warn('onRefresh method is deprecated'); } } diff --git a/packages/designer/src/document/node/modal-nodes-manager.ts b/packages/designer/src/document/node/modal-nodes-manager.ts index 8a33e47ee..b5cb96963 100644 --- a/packages/designer/src/document/node/modal-nodes-manager.ts +++ b/packages/designer/src/document/node/modal-nodes-manager.ts @@ -112,7 +112,7 @@ export class ModalNodesManager { private addNodeEvent(node: Node) { this.nodeRemoveEvents[node.getId()] = - node.onVisibleChange((flag) => { + node.onVisibleChange(() => { this.emitter.emit('visibleChange'); }); } diff --git a/packages/designer/src/document/node/node-children.ts b/packages/designer/src/document/node/node-children.ts index c326a2021..d21b0c288 100644 --- a/packages/designer/src/document/node/node-children.ts +++ b/packages/designer/src/document/node/node-children.ts @@ -129,7 +129,7 @@ export class NodeChildren { node.internalSetParent(null, useMutator); try { node.purge(useMutator); - } catch(err) { + } catch (err) { console.error(err); } } diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index 5d46c906b..b2d2f4906 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -431,7 +431,7 @@ export class Node { return false; } - wrapWith(schema: Schema) { + wrapWith(/* schema: Schema */) { // todo } @@ -725,7 +725,7 @@ export class Node { /** * 销毁 */ - purge(useMutator = true) { + purge() { if (this.purged) { return; } @@ -1066,7 +1066,7 @@ export function insertChildren( let index = at; let node: any; const results: Node[] = []; - // tslint:disable-next-line + // eslint-disable-next-line no-cond-assign while ((node = nodes.pop())) { node = insertChild(container, node, index, copy); results.push(node); diff --git a/packages/designer/src/document/node/props/props.ts b/packages/designer/src/document/node/props/props.ts index 951e4adb2..fa73e0190 100644 --- a/packages/designer/src/document/node/props/props.ts +++ b/packages/designer/src/document/node/props/props.ts @@ -153,41 +153,41 @@ export class Props implements IPropParent { query(path: string, stash = true): Prop | null { return this.get(path, stash); // todo: future support list search - let matchedLength = 0; - let firstMatched = null; - if (this.items) { - // target: a.b.c - // trys: a.b.c, a.b, a - let i = this.items.length; - while (i-- > 0) { - const expr = this.items[i]; - if (!expr.key) { - continue; - } - const name = String(expr.key); - if (name === path) { - // completely match - return expr; - } + // let matchedLength = 0; + // let firstMatched = null; + // if (this.items) { + // // target: a.b.c + // // trys: a.b.c, a.b, a + // let i = this.items.length; + // while (i-- > 0) { + // const expr = this.items[i]; + // if (!expr.key) { + // continue; + // } + // const name = String(expr.key); + // if (name === path) { + // // completely match + // return expr; + // } - // fisrt match - const l = name.length; - if (path.slice(0, l + 1) === `${name}.`) { - matchedLength = l; - firstMatched = expr; - } - } - } + // // fisrt match + // const l = name.length; + // if (path.slice(0, l + 1) === `${name}.`) { + // matchedLength = l; + // firstMatched = expr; + // } + // } + // } - let ret = null; - if (firstMatched) { - ret = firstMatched.get(path.slice(matchedLength + 1), true); - } - if (!ret && stash) { - return this.stash.get(path); - } + // let ret = null; + // if (firstMatched) { + // ret = firstMatched.get(path.slice(matchedLength + 1), true); + // } + // if (!ret && stash) { + // return this.stash.get(path); + // } - return ret; + // return ret; } /** diff --git a/packages/designer/src/document/node/props/value-to-source.ts b/packages/designer/src/document/node/props/value-to-source.ts index 7cf33da2a..77f5db856 100644 --- a/packages/designer/src/document/node/props/value-to-source.ts +++ b/packages/designer/src/document/node/props/value-to-source.ts @@ -4,6 +4,7 @@ function propertyNameRequiresQuotes(propertyName: string) { worksWithoutQuotes: false, }; + // eslint-disable-next-line no-new-func new Function('ctx', `ctx.worksWithoutQuotes = {${propertyName}: true}['${propertyName}']`)(); return !context.worksWithoutQuotes; @@ -225,7 +226,9 @@ export function getSource(value: any): string { if (value) { try { value.__source = source; - } catch (ex) {} + } catch (ex) { + console.error(ex); + } } return source; } diff --git a/packages/designer/src/document/selection.ts b/packages/designer/src/document/selection.ts index 705a4b95c..c62f4be08 100644 --- a/packages/designer/src/document/selection.ts +++ b/packages/designer/src/document/selection.ts @@ -8,6 +8,8 @@ export class Selection { @obx.val private _selected: string[] = []; + constructor(readonly doc: DocumentModel) {} + /** * 选中的节点 id */ @@ -15,8 +17,6 @@ export class Selection { return this._selected; } - constructor(readonly doc: DocumentModel) {} - /** * 选中 */ diff --git a/packages/designer/src/project/project.ts b/packages/designer/src/project/project.ts index e35920d70..fa2024525 100644 --- a/packages/designer/src/project/project.ts +++ b/packages/designer/src/project/project.ts @@ -36,10 +36,10 @@ export class Project { /** * 替换当前document的schema,并触发渲染器的render - * @param schema + * @param schema */ - setSchema(schema?: ProjectSchema){ - let doc = this.documents.find((doc) => doc.actived); + setSchema(schema?: ProjectSchema) { + const doc = this.documents.find((doc) => doc.actived); doc && doc.import(schema?.componentsTree[0]); } @@ -91,6 +91,7 @@ export class Project { * 分字段设置储存数据,不记录操作记录 */ set( + // eslint-disable-next-line @typescript-eslint/no-unused-vars key: | 'version' | 'componentsTree' @@ -101,6 +102,7 @@ export class Project { | 'css' | 'dataSource' | string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars value: any, ): void {} @@ -108,6 +110,7 @@ export class Project { * 分字段设置储存数据 */ get( + // eslint-disable-next-line @typescript-eslint/no-unused-vars key: | 'version' | 'componentsTree' diff --git a/packages/editor-core/.eslintrc.js b/packages/editor-core/.eslintrc.js new file mode 100644 index 000000000..f8bcac9a2 --- /dev/null +++ b/packages/editor-core/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + extends: 'eslint-config-ali/typescript/react', + rules: { + 'react/no-multi-comp': 1, + 'no-unused-expressions': 1, + 'implicit-arrow-linebreak': 1, + 'no-nested-ternary': 1, + 'no-mixed-operators': 1, + '@typescript-eslint/no-parameter-properties': 1, + '@typescript-eslint/ban-types': 1, + 'no-shadow': 1, + 'no-prototype-builtins': 1, + } +} \ No newline at end of file diff --git a/packages/editor-core/build.plugin.js b/packages/editor-core/build.plugin.js index 4a772200b..d24fe23ae 100644 --- a/packages/editor-core/build.plugin.js +++ b/packages/editor-core/build.plugin.js @@ -1,5 +1,4 @@ const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); -const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); module.exports = ({ onGetWebpackConfig }) => { onGetWebpackConfig((config) => { diff --git a/packages/editor-core/src/editor.ts b/packages/editor-core/src/editor.ts index d616712d4..117b5c14d 100644 --- a/packages/editor-core/src/editor.ts +++ b/packages/editor-core/src/editor.ts @@ -11,7 +11,7 @@ import { import { IocContext, RegisterOptions } from './di'; import { globalLocale } from './intl'; import * as utils from './utils'; -import { tipHandler } from './widgets/tip/tip-handler'; +// import { tipHandler } from './widgets/tip/tip-handler'; EventEmitter.defaultMaxListeners = 100; @@ -22,7 +22,7 @@ export class Editor extends EventEmitter implements IEditor { * Ioc Container */ private context = new IocContext({ - notFoundHandler: (type: KeyType) => NOT_FOUND, + notFoundHandler: (/* type: KeyType */) => NOT_FOUND, }); get locale() { @@ -92,7 +92,7 @@ export class Editor extends EventEmitter implements IEditor { async init(config?: EditorConfig, components?: PluginClassSet): Promise { this.config = config || {}; this.components = components || {}; - const { shortCuts = [], hooks = [], lifeCycles } = this.config; + const { hooks = [], lifeCycles } = this.config; this.emit('editor.beforeInit'); const init = (lifeCycles && lifeCycles.init) || ((): void => {}); @@ -116,7 +116,7 @@ export class Editor extends EventEmitter implements IEditor { return; } try { - const { shortCuts = [], lifeCycles = {} } = this.config; + const { lifeCycles = {} } = this.config; // unRegistShortCuts(shortCuts); this.unregisterHooks(); diff --git a/packages/editor-core/src/hotkey.ts b/packages/editor-core/src/hotkey.ts index dd2ff308c..c4a25ff05 100644 --- a/packages/editor-core/src/hotkey.ts +++ b/packages/editor-core/src/hotkey.ts @@ -588,7 +588,6 @@ export class Hotkey { combination = combination.replace(/\s+/g, ' '); const sequence: string[] = combination.split(' '); - let info: KeyInfo; // if this pattern is a sequence of keys then run through this method // to reprocess each pattern one key at a time @@ -597,7 +596,7 @@ export class Hotkey { return; } - info = getKeyInfo(combination, action); + const info: KeyInfo = getKeyInfo(combination, action); // make sure to initialize array if this is the first time // a callback is added for this key diff --git a/packages/editor-core/src/widgets/tip/tip-container.tsx b/packages/editor-core/src/widgets/tip/tip-container.tsx index 35ff58f14..81750bd6a 100644 --- a/packages/editor-core/src/widgets/tip/tip-container.tsx +++ b/packages/editor-core/src/widgets/tip/tip-container.tsx @@ -20,7 +20,7 @@ export class TipContainer extends Component { }; } - componentWillMount() { + UNSAFE_componentWillMount() { if (this.dispose) { this.dispose(); } diff --git a/packages/editor-core/src/widgets/title/index.tsx b/packages/editor-core/src/widgets/title/index.tsx index 05bf10773..5a8ac589b 100644 --- a/packages/editor-core/src/widgets/title/index.tsx +++ b/packages/editor-core/src/widgets/title/index.tsx @@ -25,6 +25,7 @@ export class Title extends Component<{ title: TitleContent; className?: string; } render() { + // eslint-disable-next-line prefer-const let { title, className } = this.props; if (title == null) { return null; diff --git a/packages/editor-preset-vision/.eslintrc.js b/packages/editor-preset-vision/.eslintrc.js new file mode 100644 index 000000000..f8bcac9a2 --- /dev/null +++ b/packages/editor-preset-vision/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + extends: 'eslint-config-ali/typescript/react', + rules: { + 'react/no-multi-comp': 1, + 'no-unused-expressions': 1, + 'implicit-arrow-linebreak': 1, + 'no-nested-ternary': 1, + 'no-mixed-operators': 1, + '@typescript-eslint/no-parameter-properties': 1, + '@typescript-eslint/ban-types': 1, + 'no-shadow': 1, + 'no-prototype-builtins': 1, + } +} \ No newline at end of file diff --git a/packages/editor-skeleton/.eslintrc.js b/packages/editor-skeleton/.eslintrc.js new file mode 100644 index 000000000..c3ee4f29b --- /dev/null +++ b/packages/editor-skeleton/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + extends: 'eslint-config-ali/typescript/react', + rules: { + 'react/no-multi-comp': 1, + 'no-unused-expressions': 1, + 'implicit-arrow-linebreak': 1, + 'no-nested-ternary': 1, + 'no-mixed-operators': 1, + '@typescript-eslint/no-parameter-properties': 1, + '@typescript-eslint/ban-types': 1, + 'no-shadow': 1, + 'no-prototype-builtins': 1, + 'no-confusing-arrow': 1, + 'no-case-declarations': 1, + } +} \ No newline at end of file diff --git a/packages/editor-skeleton/src/components/array-setter/index.tsx b/packages/editor-skeleton/src/components/array-setter/index.tsx index f9583ff29..0ec51b815 100644 --- a/packages/editor-skeleton/src/components/array-setter/index.tsx +++ b/packages/editor-skeleton/src/components/array-setter/index.tsx @@ -74,7 +74,7 @@ export class ListSetter extends Component { onSort(sortedIds: Array) { const { itemsMap } = this.state; const { onChange, itemSetter, field } = this.props; - const items = sortedIds.map((id, index) => { + const items = sortedIds.map((id) => { const item = itemsMap.get(id)!; // item.setKey(index); return item; @@ -85,7 +85,8 @@ export class ListSetter extends Component { }); // 对itemsMap重新生成并刷新当前setter数据 - const newItems = []; const newItemsMap = {}; + const newItems = []; + // const newItemsMap = {}; itemsMap.clear(); for (let i = 0; i < items.length; i++) { const newItem = field.createField({ @@ -128,7 +129,7 @@ export class ListSetter extends Component { } onRemove(field: SettingField) { - const { onChange, itemSetter } = this.props; + const { onChange } = this.props; const { items, itemsMap } = this.state; let i = items.indexOf(field); const values = items.map((item) => { @@ -235,7 +236,7 @@ class ArrayItem extends Component<{ render() { const { onRemove, field } = this.props; return ( -
(this.shell = ref)}> +
{ this.shell = ref; }}>
diff --git a/packages/editor-skeleton/src/components/field/fields.tsx b/packages/editor-skeleton/src/components/field/fields.tsx index 3e3cc4c91..153dd593b 100644 --- a/packages/editor-skeleton/src/components/field/fields.tsx +++ b/packages/editor-skeleton/src/components/field/fields.tsx @@ -35,6 +35,7 @@ export class Field extends Component { private toggleExpand = () => { const { onExpandChange } = this.props; + // eslint-disable-next-line react/no-access-state-in-setstate const collapsed = !this.state.collapsed; this.setState({ collapsed, @@ -130,7 +131,7 @@ export class Field extends Component { return null; } - const { className, children, meta, title, valueState, onClear, name: propName, tip } = this.props; + const { className, children, meta, title, valueState, name: propName, tip } = this.props; const { display, collapsed } = this.state; const isAccordion = display === 'accordion'; let hostName = ''; @@ -160,7 +161,7 @@ export class Field extends Component {
) } -
(this.body = shell)} className="lc-field-body"> +
{ this.body = shell; }} className="lc-field-body"> {children}
@@ -179,7 +180,7 @@ export class Field extends Component { * * TODO: turn number to enum */ -function createValueState(valueState?: number, onClear?: (e: React.MouseEvent) => void) { +function createValueState(/* valueState?: number, onClear?: (e: React.MouseEvent) => void */) { return null; /* let tip: any = null; diff --git a/packages/editor-skeleton/src/components/mixed-setter/index.tsx b/packages/editor-skeleton/src/components/mixed-setter/index.tsx index 5347f164f..c182873ee 100644 --- a/packages/editor-skeleton/src/components/mixed-setter/index.tsx +++ b/packages/editor-skeleton/src/components/mixed-setter/index.tsx @@ -146,7 +146,7 @@ export default class MixedSetter extends Component<{ private hasVariableSetter = this.setters.some((item) => item.name === 'VariableSetter'); private useSetter = (name: string) => { - const { field, onChange } = this.props; + const { field } = this.props; if (name === 'VariableSetter') { const setterComponent = getSetter('VariableSetter')?.component as any; if (setterComponent && setterComponent.isPopup) { @@ -350,7 +350,7 @@ export default class MixedSetter extends Component<{ } return ( -
(this.shell = shell)} className={classNames('lc-setter-mixed', className)}> +
{ this.shell = shell; }} className={classNames('lc-setter-mixed', className)}> {contents.setterContent}
{contents.actions}
diff --git a/packages/editor-skeleton/src/components/settings/settings-pane.tsx b/packages/editor-skeleton/src/components/settings/settings-pane.tsx index 6e2876c83..65772a87e 100644 --- a/packages/editor-skeleton/src/components/settings/settings-pane.tsx +++ b/packages/editor-skeleton/src/components/settings/settings-pane.tsx @@ -1,5 +1,5 @@ import { Component, MouseEvent, Fragment } from 'react'; -import { shallowIntl, createSetterContent, observer, obx, Title } from '@ali/lowcode-editor-core'; +import { shallowIntl, createSetterContent, observer, obx } from '@ali/lowcode-editor-core'; import { createContent } from '@ali/lowcode-utils'; import { createField } from '../field'; import PopupService, { PopupPipe } from '../popup'; @@ -12,6 +12,7 @@ import { Skeleton } from 'editor-skeleton/src/skeleton'; function transformStringToFunction(str) { if (typeof str !== 'string') return str; + // eslint-disable-next-line no-new-func return new Function(`"use strict"; return ${str}`)(); } @@ -128,6 +129,7 @@ class SettingFieldView extends Component<{ field: SettingField }> { value, // reaction point onChange: (value: any) => { this.setState({ + // eslint-disable-next-line react/no-unused-state value, }); field.setValue(value); @@ -139,6 +141,7 @@ class SettingFieldView extends Component<{ field: SettingField }> { } const value = typeof initialValue === 'function' ? initialValue(field) : initialValue; this.setState({ + // eslint-disable-next-line react/no-unused-state value, }); field.setValue(value); diff --git a/packages/editor-skeleton/src/components/slot-setter/index.tsx b/packages/editor-skeleton/src/components/slot-setter/index.tsx index 887b24f1a..584cac2f0 100644 --- a/packages/editor-skeleton/src/components/slot-setter/index.tsx +++ b/packages/editor-skeleton/src/components/slot-setter/index.tsx @@ -11,7 +11,7 @@ export default class SlotSetter extends Component<{ supportParams?: boolean; }> { private handleInitial = () => { - const { value, onChange, onInitial } = this.props; + const { onChange, onInitial } = this.props; if (onInitial) { onInitial(); return; diff --git a/packages/editor-skeleton/src/register-defaults.ts b/packages/editor-skeleton/src/register-defaults.ts index 00cb49f6a..50e73b508 100644 --- a/packages/editor-skeleton/src/register-defaults.ts +++ b/packages/editor-skeleton/src/register-defaults.ts @@ -7,7 +7,7 @@ import { isPlainObject } from '@ali/lowcode-utils'; import parseProps from './transducers/parse-props'; import addonCombine from './transducers/addon-combine'; import SlotSetter from './components/slot-setter'; -import { isJSSlot, isJSExpression } from '@ali/lowcode-types'; +import { isJSSlot } from '@ali/lowcode-types'; export const registerDefaults = () => { registerSetter('ArraySetter', { diff --git a/packages/editor-skeleton/src/transducers/parse-props.ts b/packages/editor-skeleton/src/transducers/parse-props.ts index cecf25bc6..d0804347a 100644 --- a/packages/editor-skeleton/src/transducers/parse-props.ts +++ b/packages/editor-skeleton/src/transducers/parse-props.ts @@ -4,7 +4,6 @@ import { PropType, SetterType, OneOf, - Shape, ObjectOf, ArrayOf, TransformedComponentMetadata, diff --git a/packages/editor-skeleton/src/widget/panel-dock.ts b/packages/editor-skeleton/src/widget/panel-dock.ts index d8e411c3b..9c52f483c 100644 --- a/packages/editor-skeleton/src/widget/panel-dock.ts +++ b/packages/editor-skeleton/src/widget/panel-dock.ts @@ -52,6 +52,7 @@ export default class PanelDock implements IWidget { } getDOMNode() { + // eslint-disable-next-line react/no-find-dom-node return this._shell ? findDOMNode(this._shell) : null; } diff --git a/packages/editor-skeleton/src/widget/panel.ts b/packages/editor-skeleton/src/widget/panel.ts index 3e2192eeb..25eecb78d 100644 --- a/packages/editor-skeleton/src/widget/panel.ts +++ b/packages/editor-skeleton/src/widget/panel.ts @@ -82,7 +82,7 @@ export default class Panel implements IWidget { constructor(readonly skeleton: Skeleton, readonly config: PanelConfig) { const { name, content, props = {} } = config; - const { hideTitleBar, title, icon, description, help, shortcut } = props; + const { hideTitleBar, title, icon, description, help } = props; this.name = name; this.id = uniqueId(`pane:${name}$`); this.title = composeTitle(title || name, icon, description); @@ -207,7 +207,7 @@ export default class Panel implements IWidget { /** * @deprecated */ - setPosition(position: string) { + setPosition(/* position: string */) { // noop } diff --git a/packages/editor-skeleton/src/widget/stage.ts b/packages/editor-skeleton/src/widget/stage.ts index 0fdf9195a..2af49af82 100644 --- a/packages/editor-skeleton/src/widget/stage.ts +++ b/packages/editor-skeleton/src/widget/stage.ts @@ -1,4 +1,4 @@ -import { uniqueId } from '@ali/lowcode-utils'; +// import { uniqueId } from '@ali/lowcode-utils'; import Widget from './widget'; import { Skeleton } from '../skeleton'; import { WidgetConfig } from '../types'; diff --git a/packages/editor-skeleton/src/widget/widget-container.ts b/packages/editor-skeleton/src/widget/widget-container.ts index 0d2ac72f2..013268db8 100644 --- a/packages/editor-skeleton/src/widget/widget-container.ts +++ b/packages/editor-skeleton/src/widget/widget-container.ts @@ -25,12 +25,14 @@ export default class WidgetContainer T, private exclusive: boolean = false, private checkVisible: () => boolean = () => true, private defaultSetCurrent: boolean = false, + // eslint-disable-next-line no-empty-function ) {} @computed get visible() { diff --git a/packages/plugin-designer/.eslintrc.js b/packages/plugin-designer/.eslintrc.js new file mode 100644 index 000000000..f8bcac9a2 --- /dev/null +++ b/packages/plugin-designer/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + extends: 'eslint-config-ali/typescript/react', + rules: { + 'react/no-multi-comp': 1, + 'no-unused-expressions': 1, + 'implicit-arrow-linebreak': 1, + 'no-nested-ternary': 1, + 'no-mixed-operators': 1, + '@typescript-eslint/no-parameter-properties': 1, + '@typescript-eslint/ban-types': 1, + 'no-shadow': 1, + 'no-prototype-builtins': 1, + } +} \ No newline at end of file diff --git a/packages/rax-simulator-renderer/.eslintrc.js b/packages/rax-simulator-renderer/.eslintrc.js new file mode 100644 index 000000000..f8bcac9a2 --- /dev/null +++ b/packages/rax-simulator-renderer/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + extends: 'eslint-config-ali/typescript/react', + rules: { + 'react/no-multi-comp': 1, + 'no-unused-expressions': 1, + 'implicit-arrow-linebreak': 1, + 'no-nested-ternary': 1, + 'no-mixed-operators': 1, + '@typescript-eslint/no-parameter-properties': 1, + '@typescript-eslint/ban-types': 1, + 'no-shadow': 1, + 'no-prototype-builtins': 1, + } +} \ No newline at end of file diff --git a/packages/rax-simulator-renderer/src/renderer-view.tsx b/packages/rax-simulator-renderer/src/renderer-view.tsx index 229b58a9c..413697411 100644 --- a/packages/rax-simulator-renderer/src/renderer-view.tsx +++ b/packages/rax-simulator-renderer/src/renderer-view.tsx @@ -20,7 +20,9 @@ const originCloneElement = (window as any).Rax.cloneElement; } else { try { cRef.current = x; - } catch (e) {} + } catch (e) { + console.error(e); + } } } if (dRef) { @@ -29,7 +31,9 @@ const originCloneElement = (window as any).Rax.cloneElement; } else { try { dRef.current = x; - } catch (e) {} + } catch (e) { + console.error(e); + } } } }; diff --git a/packages/rax-simulator-renderer/src/renderer.ts b/packages/rax-simulator-renderer/src/renderer.ts index ed98d3980..b7f7ef82d 100644 --- a/packages/rax-simulator-renderer/src/renderer.ts +++ b/packages/rax-simulator-renderer/src/renderer.ts @@ -2,7 +2,7 @@ import { BuiltinSimulatorRenderer, NodeInstance, Component } from '@ali/lowcode- import { shared, render as raxRender, createElement } from 'rax'; import DriverUniversal from 'driver-universal'; import { computed, obx } from '@recore/obx'; -import { RootSchema, NpmInfo, ComponentSchema } from '@ali/lowcode-types'; +import { RootSchema, NpmInfo } from '@ali/lowcode-types'; import { Asset, isReactComponent, isESModule, setNativeSelection, cursor, isElement } from '@ali/lowcode-utils'; import SimulatorRendererView from './renderer-view'; @@ -135,7 +135,7 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer { this.buildComponents(); } }); - host.injectionConsumer.consume((data) => { + host.injectionConsumer.consume(() => { // sync utils, i18n, contants,... config this._appContext = { utils: {}, @@ -183,7 +183,7 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer { // return null; } - createComponent(schema: ComponentSchema): Component | null { + createComponent(/* schema: ComponentSchema */): Component | null { return null; } @@ -404,7 +404,7 @@ function buildComponents(libraryMap: LibraryMap, componentsMap: { [componentName return components; } -function getClosestNodeInstance(from: any, specId?: string): NodeInstance | null { +function getClosestNodeInstance(from: any): NodeInstance | null { const el: any = from; if (el) { // if (isElement(el)) { diff --git a/packages/rax-simulator-renderer/src/utils/find-dom-nodes.ts b/packages/rax-simulator-renderer/src/utils/find-dom-nodes.ts index e93102654..516798f44 100644 --- a/packages/rax-simulator-renderer/src/utils/find-dom-nodes.ts +++ b/packages/rax-simulator-renderer/src/utils/find-dom-nodes.ts @@ -9,6 +9,7 @@ export function raxFindDOMNodes(instance: any): Array | null { if (isElement(instance)) { return [instance]; } + // eslint-disable-next-line react/no-find-dom-node const result = findDOMNode(instance); if (Array.isArray(result)) { return result; diff --git a/packages/react-renderer/package.json b/packages/react-renderer/package.json index aad269a1c..c59a124ea 100644 --- a/packages/react-renderer/package.json +++ b/packages/react-renderer/package.json @@ -53,5 +53,5 @@ "publishConfig": { "registry": "http://registry.npm.alibaba-inc.com" }, - "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.7-0/build/index.html" + "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.8-0/build/index.html" } diff --git a/packages/react-simulator-renderer/.eslintrc.js b/packages/react-simulator-renderer/.eslintrc.js new file mode 100644 index 000000000..c6815abf7 --- /dev/null +++ b/packages/react-simulator-renderer/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + extends: 'eslint-config-ali/typescript/react', + rules: { + 'react/no-multi-comp': 1, + 'no-unused-expressions': 1, + 'implicit-arrow-linebreak': 1, + 'no-nested-ternary': 1, + 'no-mixed-operators': 1, + '@typescript-eslint/no-parameter-properties': 1, + '@typescript-eslint/ban-types': 1, + 'no-shadow': 1, + 'no-prototype-builtins': 1, + 'array-callback-return': 1, + } +} \ No newline at end of file diff --git a/packages/react-simulator-renderer/src/builtin-components/builtin-components.ts b/packages/react-simulator-renderer/src/builtin-components/builtin-components.ts index bf09bf75c..01cdb57db 100644 --- a/packages/react-simulator-renderer/src/builtin-components/builtin-components.ts +++ b/packages/react-simulator-renderer/src/builtin-components/builtin-components.ts @@ -152,6 +152,7 @@ const supportedEvents = [ }, ]; +// eslint-disable-next-line func-call-spacing const builtinComponents = new Map ReactElement>(); function getBlockElement(tag: string): (props: any) => ReactElement { if (builtinComponents.has(tag)) { diff --git a/packages/react-simulator-renderer/src/renderer-view.tsx b/packages/react-simulator-renderer/src/renderer-view.tsx index 693dcc310..8d7599ef7 100644 --- a/packages/react-simulator-renderer/src/renderer-view.tsx +++ b/packages/react-simulator-renderer/src/renderer-view.tsx @@ -19,7 +19,9 @@ const originCloneElement = window.React.cloneElement; } else { try { cRef.current = x; - } catch (e) {} + } catch (e) { + console.error(e); + } } } if (dRef) { @@ -28,7 +30,9 @@ const originCloneElement = window.React.cloneElement; } else { try { dRef.current = x; - } catch (e) {} + } catch (e) { + console.error(e); + } } } }; diff --git a/packages/react-simulator-renderer/src/renderer.ts b/packages/react-simulator-renderer/src/renderer.ts index 1a5136254..fface745a 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -1,4 +1,4 @@ -import React, { createElement, ReactInstance, ComponentType, ReactElement, FunctionComponent } from 'react'; +import React, { createElement, ReactInstance } from 'react'; import { render as reactRender } from 'react-dom'; import { host } from './host'; import SimulatorRendererView from './renderer-view'; @@ -63,7 +63,7 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer { this.buildComponents(); } }); - host.injectionConsumer.consume((data) => { + host.injectionConsumer.consume(() => { // sync utils, i18n, contants,... config this._appContext = { utils: {}, @@ -237,8 +237,6 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer { subs.unshift(sub); componentName = paths.join('.'); } - - return null; } getComponentInstances(id: string): ReactInstance[] | null {