浏览代码

[ui] Vue 3 - Fixed lint errors in Web Component Wrapper

sreenaths 4 年之前
父节点
当前提交
24fde64280

+ 2 - 0
desktop/core/src/desktop/js/catalog/api.ts

@@ -435,6 +435,8 @@ export const fetchSample = ({
         // eslint-disable-next-line @typescript-eslint/ban-ts-comment
         // @ts-ignore
         const transformResponse = (response: unknown) => {
+          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+          // @ts-ignore
           return JSON.bigdataParse(response);
         };
         const resultPromise = post<SampleResponse>(

+ 1 - 0
desktop/core/src/desktop/js/types/types.ts

@@ -50,4 +50,5 @@ export interface hueWindow {
   WEB_SOCKETS_ENABLED?: boolean;
   WS_CHANNEL?: string;
   hueDebug?: HueDebug;
+  DISABLE_LOCAL_STORAGE?: boolean;
 }

+ 2 - 2
desktop/core/src/desktop/js/utils/storageUtils.ts

@@ -22,7 +22,7 @@ type LocalStorageGet = {
 };
 export const getFromLocalStorage: LocalStorageGet = <T>(key: string, defaultValue?: T) => {
   const defaultOrNull = typeof defaultValue !== 'undefined' ? defaultValue : null;
-  if (!window.localStorage || window.DISABLE_LOCAL_STORAGE) {
+  if (!window.localStorage || (<hueWindow>window).DISABLE_LOCAL_STORAGE) {
     return defaultOrNull;
   }
 
@@ -47,7 +47,7 @@ export const setInLocalStorage = (key: string, value: unknown): void => {
   if (!window.localStorage) {
     return;
   }
-  if (window.DISABLE_LOCAL_STORAGE) {
+  if ((<hueWindow>window).DISABLE_LOCAL_STORAGE) {
     window.localStorage.clear();
     return;
   }

+ 32 - 30
desktop/core/src/desktop/js/vue/wrapper/utils.ts

@@ -1,54 +1,54 @@
-import { ComponentPublicInstance, h, VNode } from "vue";
+import { ComponentPublicInstance, h, VNode } from 'vue';
 
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
 export type KeyHash = { [key: string]: any };
 
-const camelizeRE = /-(\w)/g
+const camelizeRE = /-(\w)/g;
 export const camelize = (str: string): string => {
-  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
-}
+  return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
+};
 
-const hyphenateRE = /\B([A-Z])/g
+const hyphenateRE = /\B([A-Z])/g;
 export const hyphenate = (str: string): string => {
-  return str.replace(hyphenateRE, '-$1').toLowerCase()
-}
+  return str.replace(hyphenateRE, '-$1').toLowerCase();
+};
 
 export function setInitialProps(propsList: string[]): KeyHash {
-  const res: KeyHash = {}
+  const res: KeyHash = {};
   propsList.forEach(key => {
-    res[key] = undefined
-  })
-  return res
-}
-
-export function injectHook (options: KeyHash, key: string, hook: Function) {
-  options[key] = [].concat(options[key] || [])
-  options[key].unshift(hook)
+    res[key] = undefined;
+  });
+  return res;
 }
 
-export function callHooks (vm: ComponentPublicInstance | undefined, hook: string) {
+export function callHooks(vm: ComponentPublicInstance | undefined, hook: string): void {
   if (vm) {
     let hooks = vm.$options[hook] || [];
-    if(!Array.isArray(hooks)) {
+    if (!Array.isArray(hooks)) {
       hooks = [hooks];
     }
-    hooks.forEach((hook: Function) => {
+    hooks.forEach((hook: () => void): void => {
       hook.call(vm);
     });
   }
 }
 
-export function createCustomEvent (name: string, args: any) {
+export function createCustomEvent(name: string, args: unknown): CustomEvent {
   return new CustomEvent(name, {
     bubbles: false,
     cancelable: false,
     detail: args
-  })
+  });
 }
 
-const isBoolean = (val: any) => /function Boolean/.test(String(val));
-const isNumber = (val: any) => /function Number/.test(String(val));
+const isBoolean = (val: unknown) => /function Boolean/.test(String(val));
+const isNumber = (val: unknown) => /function Number/.test(String(val));
 
-export function convertAttributeValue (value: any, name: string, { type }: { type?: any } = {}) {
+export function convertAttributeValue(
+  value: unknown,
+  name: string,
+  { type }: { type?: unknown } = {}
+): unknown {
   if (isBoolean(type)) {
     if (value === 'true' || value === 'false') {
       return value === 'true';
@@ -58,14 +58,14 @@ export function convertAttributeValue (value: any, name: string, { type }: { typ
     }
     return value != null;
   } else if (isNumber(type)) {
-    const parsed = parseFloat(value);
+    const parsed = parseFloat(<string>value);
     return isNaN(parsed) ? value : parsed;
   } else {
     return value;
   }
 }
 
-export function toVNodes (children: NodeListOf<ChildNode>): (VNode | null)[] {
+export function toVNodes(children: NodeListOf<ChildNode>): (VNode | null)[] {
   const res: (VNode | null)[] = [];
 
   for (let i = 0, l = children.length; i < l; i++) {
@@ -75,11 +75,13 @@ export function toVNodes (children: NodeListOf<ChildNode>): (VNode | null)[] {
   return res;
 }
 
-function toVNode (node: any): VNode | null {
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+function toVNode(node: any): VNode | null {
   if (node.nodeType === 3) {
     return node.data.trim() ? node.data : null;
   } else if (node.nodeType === 1) {
-    const data = {
+    // eslint-disable-next-line @typescript-eslint/no-explicit-any
+    const data: { attrs: any; domProps: any; slot?: any } = {
       attrs: getAttributes(node),
       domProps: {
         innerHTML: node.innerHTML
@@ -93,11 +95,11 @@ function toVNode (node: any): VNode | null {
 
     return h(node.tagName, data);
   } else {
-    return null
+    return null;
   }
 }
 
-function getAttributes (node: any): KeyHash {
+function getAttributes(node: { attributes: { nodeName: string; nodeValue: unknown }[] }): KeyHash {
   const res: KeyHash = {};
   for (let i = 0, l = node.attributes.length; i < l; i++) {
     const attr = node.attributes[i];