From 0a05642b7804b3aea9c99908807094c7483bbd20 Mon Sep 17 00:00:00 2001 From: Fernanda Toledo Date: Thu, 5 Sep 2024 18:00:59 -0300 Subject: [PATCH 1/2] chore(sonar): unexpected any specify a different type --- .eslintrc.js | 1 + scripts/i18next-syntax-validation.js | 2 +- src/api/common/axios.d.ts | 2 +- src/api/common/utils.tsx | 4 ++-- src/core/i18n/types.ts | 2 +- src/core/utils.ts | 12 ++++++++---- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 515c70bed..effc29342 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,6 +9,7 @@ module.exports = { ], plugins: ['unicorn', 'sonarjs'], rules: { + '@typescript-eslint/no-explicit-any': 'error', 'prettier/prettier': [ 'error', { diff --git a/scripts/i18next-syntax-validation.js b/scripts/i18next-syntax-validation.js index 6be5484ac..9edebf96e 100644 --- a/scripts/i18next-syntax-validation.js +++ b/scripts/i18next-syntax-validation.js @@ -13,7 +13,7 @@ const validate = (message = '') => { 'Interpolation error. See: https://www.i18next.com/misc/json-format' ); } - if (message.includes('$t(') && !/\$t\([\w]+:\w+(?:\.\w+)*\)/g.test(message)) { + if (message.includes('$t(') && !/\$t\(\w+:\w+(?:\.\w+)*\)/g.test(message)) { throw new SyntaxError( 'Nesting error. See: https://www.i18next.com/misc/json-format' ); diff --git a/src/api/common/axios.d.ts b/src/api/common/axios.d.ts index 8705ad542..57294a3c9 100644 --- a/src/api/common/axios.d.ts +++ b/src/api/common/axios.d.ts @@ -6,7 +6,7 @@ declare module 'axios' { interface AxiosInterceptorManager { handlers: Array<{ fulfilled: ((value: V) => V | Promise) | null; - rejected: ((error: any) => any) | null; + rejected: ((error: unknown) => unknown) | null; synchronous: boolean; runWhen: (config: InternalAxiosRequestConfig) => boolean | null; }>; diff --git a/src/api/common/utils.tsx b/src/api/common/utils.tsx index 812d00a2b..a02f0cfc2 100644 --- a/src/api/common/utils.tsx +++ b/src/api/common/utils.tsx @@ -6,7 +6,7 @@ import type { import type { PaginateQuery } from '../types'; type KeyParams = { - [key: string]: any; + [key: string]: unknown; }; export const DEFAULT_LIMIT = 10; @@ -46,7 +46,7 @@ export const getNextPageParam: GetPreviousPageParamFunction< PaginateQuery > = (page) => getUrlParameters(page.next)?.offset ?? null; -type GenericObject = { [key: string]: any }; +type GenericObject = { [key: string]: unknown }; export const toCamelCase = (obj: GenericObject): GenericObject => { const newObj: GenericObject = {}; diff --git a/src/core/i18n/types.ts b/src/core/i18n/types.ts index 015523db3..45aeb0362 100644 --- a/src/core/i18n/types.ts +++ b/src/core/i18n/types.ts @@ -16,7 +16,7 @@ type RecursiveKeyOfInner = { type RecursiveKeyOfHandleValue< TValue, Text extends string -> = TValue extends any[] +> = TValue extends unknown[] ? Text : TValue extends object ? Text | `${Text}${RecursiveKeyOfInner}` diff --git a/src/core/utils.ts b/src/core/utils.ts index bf5849371..4644da0c6 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -9,13 +9,17 @@ type WithSelectors = S extends { getState: () => infer T } ? S & { use: { [K in keyof T]: () => T[K] } } : never; -export const createSelectors = >>( +export const createSelectors = < + T extends object, + S extends UseBoundStore> +>( _store: S ) => { const store = _store as WithSelectors; - store.use = {}; - for (const k of Object.keys(store.getState())) { - (store.use as any)[k] = () => store((s) => s[k as keyof typeof s]); + store.use = {} as { [K in keyof T]: () => T[K] }; + + for (const k of Object.keys(store.getState()) as Array) { + store.use[k] = () => store((s) => s[k]); } return store; From b37f3f83fd0b50c397d845c90aa1b2c3cb026718 Mon Sep 17 00:00:00 2001 From: Fernanda Toledo Date: Fri, 6 Sep 2024 09:22:43 -0300 Subject: [PATCH 2/2] chore(sonar): redundant casts and non-null assertions should be avoided --- .github/workflows/sonar.yml | 2 +- src/core/i18n/utils.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index bfd1ea9ff..51f9a7224 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -41,4 +41,4 @@ jobs: -Dsonar.sonar.sourceEncoding=UTF-8 -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info -Dsonar.coverage.exclusions=**/node_modules/**,**/storage/**,**/**.config.js,**/*.test.ts,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx,**/icons/**,**/docs/**,**/cli/**,**/android/**,**/ios/**,env.js - -Dsonar.exclusions=,**/__mocks__/** + -Dsonar.exclusions=**/docs/**,**/__mocks__/** diff --git a/src/core/i18n/utils.tsx b/src/core/i18n/utils.tsx index 62c356dba..b6cca0171 100644 --- a/src/core/i18n/utils.tsx +++ b/src/core/i18n/utils.tsx @@ -51,11 +51,11 @@ export const useSelectedLanguage = () => { (lang: Language) => { setLang(lang); if (lang !== undefined) { - changeLanguage(lang as Language); + changeLanguage(lang); } }, [setLang] ); - return { language: language as Language, setLanguage }; + return { language: language, setLanguage }; };