From 8a1ab5c32078906c031216c386838ff04d80455d Mon Sep 17 00:00:00 2001 From: JC Franco Date: Wed, 26 Jun 2024 14:37:46 -0700 Subject: [PATCH] chore(linting): enable @typescript-eslint/methd-signature-style for safer types (#9690) **Related Issue:** N/A ## Summary Prevents method shorthand syntax to avoid potential pitfals described in https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful --- packages/calcite-components/.eslintrc.cjs | 1 + packages/calcite-components/src/utils/floating-ui.ts | 2 +- packages/calcite-components/src/utils/form.tsx | 4 ++-- packages/calcite-components/src/utils/observers.ts | 2 +- packages/calcite-components/src/utils/t9n.ts | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/calcite-components/.eslintrc.cjs b/packages/calcite-components/.eslintrc.cjs index b118bd3dccf..75c1fcfcd12 100644 --- a/packages/calcite-components/.eslintrc.cjs +++ b/packages/calcite-components/.eslintrc.cjs @@ -70,6 +70,7 @@ module.exports = { ], }, ], + "@typescript-eslint/method-signature-style": ["error", "property"], "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unused-vars": "error", curly: "error", diff --git a/packages/calcite-components/src/utils/floating-ui.ts b/packages/calcite-components/src/utils/floating-ui.ts index 1f9796cb69b..00275044003 100644 --- a/packages/calcite-components/src/utils/floating-ui.ts +++ b/packages/calcite-components/src/utils/floating-ui.ts @@ -298,7 +298,7 @@ export interface FloatingUIComponent { * * @param delayed – (internal) when true, it will reposition the component after a delay. the default is false. This is useful for components that have multiple watched properties that schedule repositioning. */ - reposition(delayed?: boolean): Promise; + reposition: (delayed?: boolean) => Promise; /** * Used to store the effective floating layout for components that use arrows. diff --git a/packages/calcite-components/src/utils/form.tsx b/packages/calcite-components/src/utils/form.tsx index 15484d7f41d..2d2f87e3b4a 100644 --- a/packages/calcite-components/src/utils/form.tsx +++ b/packages/calcite-components/src/utils/form.tsx @@ -125,14 +125,14 @@ export interface FormComponent extends FormOwner { /** * Hook for components to provide custom form reset behavior. */ - onFormReset?(): void; + onFormReset?: () => void; /** * Hook for components to sync _extra_ props on the hidden input form element used for form-submitting. * * Note: The following props are set by default: disabled, hidden, name, required, value. */ - syncHiddenFormInput?(input: HTMLInputElement): void; + syncHiddenFormInput?: (input: HTMLInputElement) => void; } /** diff --git a/packages/calcite-components/src/utils/observers.ts b/packages/calcite-components/src/utils/observers.ts index d12f60b3c41..5cd14d9ec81 100644 --- a/packages/calcite-components/src/utils/observers.ts +++ b/packages/calcite-components/src/utils/observers.ts @@ -2,7 +2,7 @@ import { Build } from "@stencil/core"; export interface ExtendedMutationObserver extends MutationObserver { new: () => ExtendedMutationObserver; - unobserve(target: Node): void; + unobserve: (target: Node) => void; } declare const ExtendedMutationObserver: { diff --git a/packages/calcite-components/src/utils/t9n.ts b/packages/calcite-components/src/utils/t9n.ts index 0c0b1ad4c29..b91f08cac86 100644 --- a/packages/calcite-components/src/utils/t9n.ts +++ b/packages/calcite-components/src/utils/t9n.ts @@ -142,7 +142,7 @@ export interface T9nComponent extends LocalizedComponent { * \/* wired up by t9n util *\/ * } */ - onMessagesChange(): void; + onMessagesChange: () => void; } function defaultOnMessagesChange(this: T9nComponent): void {