From d7b3d649d6c21787baa752a4aa106b5b500c477b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 15 Dec 2022 16:27:17 +0100 Subject: [PATCH] refactor: Enforce `no-explicit-any` in `design-system` (no-changelog) (#4937) :shirt: Enforce `no-explicit-any` in design-system --- packages/design-system/.eslintrc.js | 1 - .../src/components/N8nFormInput/FormInput.vue | 8 ++++---- .../src/components/N8nFormInputs/FormInputs.vue | 4 ++-- packages/design-system/src/types/form.ts | 13 +++++++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/design-system/.eslintrc.js b/packages/design-system/.eslintrc.js index 99933f5d65..e94195422c 100644 --- a/packages/design-system/.eslintrc.js +++ b/packages/design-system/.eslintrc.js @@ -14,7 +14,6 @@ module.exports = { // TODO: Remove these 'import/no-default-export': 'off', 'import/order': 'off', - '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-unsafe-argument': 'warn', '@typescript-eslint/no-unsafe-return': 'warn', '@typescript-eslint/no-unsafe-member-access': 'warn', diff --git a/packages/design-system/src/components/N8nFormInput/FormInput.vue b/packages/design-system/src/components/N8nFormInput/FormInput.vue index 777a2e154a..76466abb11 100644 --- a/packages/design-system/src/components/N8nFormInput/FormInput.vue +++ b/packages/design-system/src/components/N8nFormInput/FormInput.vue @@ -75,12 +75,12 @@ import N8nInputLabel from '../N8nInputLabel'; import N8nCheckbox from '../N8nCheckbox'; import { getValidationError, VALIDATORS } from './validators'; -import { Rule, RuleGroup, IValidator } from '../../types'; +import { Rule, RuleGroup, IValidator, Validatable, FormState } from '../../types'; import { t } from '../../locale'; export interface Props { - value: any; + value: Validatable; label: string; infoText?: string; required?: boolean; @@ -112,7 +112,7 @@ const props = withDefaults(defineProps(), { const emit = defineEmits<{ (event: 'validate', shouldValidate: boolean): void; - (event: 'input', value: any): void; + (event: 'input', value: unknown): void; (event: 'focus'): void; (event: 'blur'): void; (event: 'enter'): void; @@ -169,7 +169,7 @@ function onBlur() { emit('blur'); } -function onInput(value: any) { +function onInput(value: FormState) { state.isTyping = true; emit('input', value); } diff --git a/packages/design-system/src/components/N8nFormInputs/FormInputs.vue b/packages/design-system/src/components/N8nFormInputs/FormInputs.vue index a5a0efebb7..c638a6f591 100644 --- a/packages/design-system/src/components/N8nFormInputs/FormInputs.vue +++ b/packages/design-system/src/components/N8nFormInputs/FormInputs.vue @@ -57,7 +57,7 @@ export default Vue.extend({ data() { return { showValidationWarnings: false, - values: {} as { [key: string]: any }, + values: {} as { [key: string]: unknown }, validity: {} as { [key: string]: boolean }, }; }, @@ -89,7 +89,7 @@ export default Vue.extend({ }, }, methods: { - onInput(name: string, value: any) { + onInput(name: string, value: unknown) { this.values = { ...this.values, [name]: value, // eslint-disable-line @typescript-eslint/no-unsafe-assignment diff --git a/packages/design-system/src/types/form.ts b/packages/design-system/src/types/form.ts index 87c38a5c10..c072c19959 100644 --- a/packages/design-system/src/types/form.ts +++ b/packages/design-system/src/types/form.ts @@ -1,8 +1,8 @@ -export type Rule = { name: string; config?: any }; +export type Rule = { name: string; config?: unknown }; export type RuleGroup = { rules: Array; - defaultError?: { messageKey: string; options?: any }; + defaultError?: { messageKey: string; options?: unknown }; }; export type Validatable = string | number | boolean | null | undefined; @@ -10,8 +10,13 @@ export type Validatable = string | number | boolean | null | undefined; export type IValidator = { validate: ( value: Validatable, - config: any, - ) => false | { messageKey: string; options?: any } | null; + config: unknown, + ) => false | { messageKey: string; options?: unknown } | null; +}; + +export type FormState = { + isTyping: boolean; + hasBlutted: boolean; }; export type IFormInput = {