浏览代码

fix: add some lint config

代强 2 年之前
父节点
当前提交
5c36a97b25

+ 3 - 0
.eslintrc.js

@@ -41,6 +41,7 @@ module.exports = {
                 'jsx-a11y/html-has-lang': ['warn'],
                 'jsx-a11y/mouse-events-have-key-events': ['warn'],
                 'object-curly-spacing': ['error', 'always'],
+                'space-before-blocks': ['error', 'always'],
             },
             globals: {
                 "sinon": "readonly",
@@ -91,6 +92,8 @@ module.exports = {
                 'jsx-a11y/html-has-lang': ['warn'],
                 'object-curly-spacing': ['error', 'always'],
                 'semi-design/no-import': 'error',
+                'space-before-blocks': ['error', 'always'],
+                "@typescript-eslint/type-annotation-spacing": ['error', {"after": true}],
                 "@typescript-eslint/member-delimiter-style": [
                     "error",
                     {

+ 1 - 1
content/show/popover/index-en-US.md

@@ -541,6 +541,7 @@ Please refer to [Use with Tooltip/Popconfirm](/en-US/show/tooltip#%E6%90%AD%E9%8
 | disableFocusListener | When trigger is `hover`, does not respond to the keyboard focus popup event, see details at [issue#977](https://github.com/DouyinFE/semi-design/issues/977)                                                                                   | boolean | true | **2.17.0** |
 | getPopupContainer | Specifies the parent DOM, and the bullet layer will be rendered to the DOM, you need to set 'position: relative`                                                                                                                              | () => HTMLElement | () => document.body |
 | guardFocus | When the focus is in the popup layer, toggle whether the Tab makes the focus loop in the popup layer                                                                                                                                          | boolean | true | **2.8.0** |
+| keepDOM | Whether to keep internal components from being destroyed when closing                                          | boolean | false | **2.31.0** |
 | margin | Popup layer calculates the size of the safe area when the current direction overflows, used in scenes covered by fixed elements, more detail refer to [issue#549](https://github.com/DouyinFE/semi-design/issues/549), same as Tooltip margin | object\|number |  | 2.25.0 |
 | mouseEnterDelay | After the mouse is moved in, the display delay time, in milliseconds (only effective when the trigger is hover/focus)                                                                                                                         | number | 50 |  |
 | mouseLeaveDelay | The time for the delay to disappear after the mouse is moved out, in milliseconds (only effective when the trigger is hover/focus)                                                                                                            | number | 50 |  |
@@ -556,7 +557,6 @@ Please refer to [Use with Tooltip/Popconfirm](/en-US/show/tooltip#%E6%90%AD%E9%8
 | onClickOutSide  | Callback when the pop-up layer is in the display state and the non-Children, non-floating layer inner area is clicked (only valid when trigger is custom, click)                                                                              | (e:event) => void | | **2.1.0** |
 | onEscKeyDown | Called when Esc key is pressed in trigger or popup layer                                                                                                                                                                                      | function(e:event) | | **2.8.0** |
 | onVisibleChange | A callback triggered when the pop-up layer is displayed / hidden                                                                                                                                                                              | (isVisible: boolean) => void |  |
-| keepDOM | Whether to keep internal components from being destroyed when closing                                          | boolean | false | **2.31.0** |
 
 ## Accessibility
 

+ 1 - 1
content/show/popover/index.md

@@ -538,6 +538,7 @@ import { Button, Input, Popover, Space } from '@douyinfe/semi-ui';
 | disableFocusListener | trigger为`hover`时,不响应键盘聚焦弹出浮层事件,详见[issue#977](https://github.com/DouyinFE/semi-design/issues/977) | boolean | true | **2.17.0** |
 | getPopupContainer  | 指定父级 DOM,弹层将会渲染至该 DOM 中,自定义需要设置 `position: relative`                                                                  | function():HTMLElement     | () => document.body                         |            |
 | guardFocus         | 当焦点处于弹出层内时,切换 Tab 是否让焦点在弹出层内循环 | boolean | true | **2.8.0**  |
+| keepDOM | 关闭时是否保留内部组件不销毁 | boolean | false | **2.31.0** |
 | margin     |  弹出层计算溢出时的增加的冗余值,详见[issue#549](https://github.com/DouyinFE/semi-design/issues/549),作用同 Tooltip margin                        | number\|object                     |            |  **2.25.0**   |
 | mouseEnterDelay    | 鼠标移入后,延迟显示的时间,单位毫秒(仅当 trigger 为 hover/focus 时生效)                                                                  | number                     | 50                                          |            |
 | mouseLeaveDelay    | 鼠标移出后,延迟消失的时间,单位毫秒(仅当 trigger 为 hover/focus 时生效)                                                                  | number                     | 50                                          |            |
@@ -553,7 +554,6 @@ import { Button, Input, Popover, Space } from '@douyinfe/semi-ui';
 | onClickOutSide     | 当弹出层处于展示状态,点击非Children、非浮层内部区域时的回调(仅trigger为custom、click时有效)| function(e:event) |  | **2.1.0**  |
 | onEscKeyDown       | 在 trigger 或 弹出层按 Esc 键时调用        | function(e:event) | | **2.8.0**  |
 | onVisibleChange    | 弹出层展示/隐藏时触发的回调                                                                                                                 | function(isVisble:boolean) |                                             |            |
-| keepDOM | 关闭时是否保留内部组件不销毁 | boolean | false | **2.31.0** |
 
 ## Accessibility
 

+ 1 - 1
content/show/tooltip/index-en-US.md

@@ -339,6 +339,7 @@ import { Popconfirm, Tooltip, Button } from '@douyinfe/semi-ui';
 | clickToHide | Whether to automatically close the elastic layer when clicking on the floating layer and any element inside | boolean | false | **0.24.0** |
 | disableFocusListener | When trigger is `hover`, does not respond to the keyboard focus popup event, see details at [issue#977](https://github.com/DouyinFE/semi-design/issues/977) | boolean | false | **2.17.0** |
 | getPopupContainer | Specifies the parent DOM, and the bullet layer will be rendered to the DOM | () => HTMLElement | () => document.body |
+| keepDOM | Whether to keep internal components from being destroyed when closing                                          | boolean | false | **2.31.0** |
 | margin | Calculate the added redundancy value when overflowing, see [issue#549](https://github.com/DouyinFE/semi-design/issues/549) | number | { marginLeft: number; marginTop: number; marginRight: number; marginBottom: number } | 0 |  **2.23.0**|
 | mouseEnterDelay | After the mouse is moved in, the display delay time, in milliseconds (only effective when the trigger is hover/focus) | number | 50 |  |
 | mouseLeaveDelay | The time for the delay to disappear after the mouse is moved out, in milliseconds (only effective when the trigger is hover/focus), and is not less than mouseEnterDelay | number | 50 |  |
@@ -359,7 +360,6 @@ import { Popconfirm, Tooltip, Button } from '@douyinfe/semi-ui';
 | zIndex              | Bullet levels.           | number                      | 1060                |            |
 | onVisibleChange     | A callback triggered when the pop-up layer is displayed/hidden                                                                                                                                                                               | (isVisible: boolean) => void |                     |            |
 | onClickOutSide      | Callback when the pop-up layer is in the display state and the non-Children, non-floating layer inner area is clicked (only valid when trigger is custom, click)                                                                             | (e:event) => void           |                     | **2.1.0** |
-| keepDOM | Whether to keep internal components from being destroyed when closing                                          | boolean | false | **2.31.0** |
 
 
 ## Accessibility

+ 1 - 1
content/show/tooltip/index.md

@@ -370,6 +370,7 @@ function Demo() {
 | clickToHide | 点击弹出层及内部任一元素时是否自动关闭弹层 | boolean | false | **0.24.0** |
 | disableFocusListener | trigger为`hover`时,不响应键盘聚焦弹出浮层事件,详见[issue#977](https://github.com/DouyinFE/semi-design/issues/977) | boolean | false | **2.17.0** |
 | getPopupContainer | 指定父级 DOM,弹层将会渲染至该 DOM 中,自定义需要设置 `position: relative` | function():HTMLElement | () => document.body |  |
+| keepDOM | 关闭时是否保留内部组件不销毁 | boolean | false | **2.31.0** |
 | margin | 计算溢出时的增加的冗余值,详见[issue#549](https://github.com/DouyinFE/semi-design/issues/549) | number | <ApiType detail='{ marginLeft: number; marginTop: number; marginRight: number; marginBottom: number }'>MarginObject</ApiType> | 0 |  **2.23.0**|
 | mouseEnterDelay | 鼠标移入后,延迟显示的时间,单位毫秒(仅当 trigger 为 hover/focus 时生效) | number | 50 |  |
 | mouseLeaveDelay | 鼠标移出后,延迟消失的时间,单位毫秒(仅当 trigger 为 hove/focus 时生效),不小于 mouseEnterDelay | number | 50 |  |
@@ -390,7 +391,6 @@ function Demo() {
 | zIndex | 弹层层级 | number | 1060 |  |
 | onVisibleChange | 弹出层展示/隐藏时触发的回调 | function(isVisible:boolean) |  |  |
 | onClickOutSide | 当弹出层处于展示状态,点击非Children、非浮层内部区域时的回调(仅trigger为custom、click时有效)| function(e:event) |  | **2.1.0** |
-| keepDOM | 关闭时是否保留内部组件不销毁 | boolean | false | **2.31.0** |
 
 ## Accessibility
 

+ 10 - 10
packages/semi-foundation/tooltip/foundation.ts

@@ -38,7 +38,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
     unregisterScrollHandler(): void;
     insertPortal(...args: any[]): void;
     removePortal(...args: any[]): void;
-    setDisplayNone:(displayNone:boolean, cb?:()=>void)=>void;
+    setDisplayNone: (displayNone: boolean, cb?: () => void) => void;
     getEventName(): {
         mouseEnter: string;
         mouseLeave: string;
@@ -139,7 +139,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
         this._adapter.removePortal();
     }
 
-    setDisplayNone:(displayNone:boolean, cb?:()=>void)=>void = (displayNone, cb) => {
+    setDisplayNone: (displayNone: boolean, cb?: () => void) => void = (displayNone, cb) => {
         this._adapter.setDisplayNone(displayNone, cb);
     }
 
@@ -271,7 +271,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
         this.calcPosition();
     };
 
-    _shouldShow() {
+    _shouldShow() { 
         const visible = this.getProp('visible');
         if (visible) {
             this.show();
@@ -300,9 +300,9 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
         const trigger = this.getProp('trigger');
         const clickTriggerToHide = this.getProp('clickTriggerToHide');
         const { visible, displayNone } = this.getStates();
-        if (displayNone){
+        if (displayNone) {
             this.setDisplayNone(false);
-        }
+        } 
         if (visible) {
             return ;
         }
@@ -687,19 +687,19 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
         return rowSpace < size && reverseSpace > size;
     }
 
-    isOverFlow(rowSpace: number, reverseSpace: number, size: number){
+    isOverFlow(rowSpace: number, reverseSpace: number, size: number) {
         // 原空间且反向空间都不足
         // The original space and the reverse space are not enough
         return rowSpace < size && reverseSpace < size;
     }
 
-    isHalfOverFlow(posSpace: number, negSpace: number, size: number){
+    isHalfOverFlow(posSpace: number, negSpace: number, size: number) {
         // 正半空间或者负半空间不足,即表示有遮挡,需要偏移
         // Insufficient positive half space or negative half space means that there is occlusion and needs to be offset
         return posSpace < size || negSpace < size;
     }
 
-    isHalfAllEnough(posSpace: number, negSpace: number, size: number){
+    isHalfAllEnough(posSpace: number, negSpace: number, size: number) {
         // 正半空间和负半空间都足够,即表示可以从 topLeft/topRight 变成 top
         // Both positive and negative half-spaces are sufficient, which means you can change from topLeft/topRight to top
         return posSpace >= size || negSpace >= size;
@@ -1011,7 +1011,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
 
             // 判断溢出 Judgment overflow
             // 上下方向 top and bottom
-            if (this.isTB(position)){
+            if (this.isTB(position)) {
                 isHeightOverFlow = isViewYOverFlow && isContainerYOverFlow;
                 // Related PR: https://github.com/DouyinFE/semi-design/pull/1297
                 // If clientRight or restClientRight less than 0, means that the left and right parts of the trigger are blocked
@@ -1023,7 +1023,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
                 }
             }
             // 左右方向 left and right
-            if (this.isLR(position)){
+            if (this.isLR(position)) {
                 isWidthOverFlow = isViewXOverFlow && isContainerXOverFlow;
                 // If clientTop or restClientTop less than 0, means that the top and bottom parts of the trigger are blocked
                 // Then the display of the wrapper will also be affected, make height overflow to offset the wrapper

+ 3 - 4
packages/semi-ui/popover/index.tsx

@@ -45,11 +45,10 @@ export interface PopoverProps extends BaseProps {
     guardFocus?: TooltipProps['guardFocus'];
     returnFocusOnClose?: TooltipProps['returnFocusOnClose'];
     onEscKeyDown?: TooltipProps['onEscKeyDown'];
-    clickToHide?:TooltipProps['clickToHide'];
+    clickToHide?: TooltipProps['clickToHide'];
     disableFocusListener?: boolean;
-    afterClose?:()=>void;
-
-    keepDOM?:boolean
+    afterClose?: () => void;
+    keepDOM?: boolean
 }
 
 export interface PopoverState {