From b2d89766476a5b8b047298d114e19232c8495516 Mon Sep 17 00:00:00 2001 From: Odin Thomas Rochmann Date: Fri, 7 Mar 2025 09:23:39 +0100 Subject: [PATCH] fix(biome): update noBannedTypes rule to error and adjust linting exceptions --- .changeset/crazy-ghosts-smile.md | 5 +++++ biome.json | 2 +- packages/utils/observable/src/create-reducer.ts | 15 ++++++++------- packages/utils/observable/src/types/actions.ts | 8 ++++---- packages/utils/observable/src/types/ts-helpers.ts | 12 +----------- 5 files changed, 19 insertions(+), 23 deletions(-) create mode 100644 .changeset/crazy-ghosts-smile.md diff --git a/.changeset/crazy-ghosts-smile.md b/.changeset/crazy-ghosts-smile.md new file mode 100644 index 000000000..49259aad1 --- /dev/null +++ b/.changeset/crazy-ghosts-smile.md @@ -0,0 +1,5 @@ +--- +"@equinor/fusion-observable": patch +--- + +fixed `noBannedTypes` Biome rules diff --git a/biome.json b/biome.json index 10a90d771..b00b48109 100644 --- a/biome.json +++ b/biome.json @@ -23,7 +23,7 @@ "rules": { "recommended": true, "complexity": { - "noBannedTypes": "warn", + "noBannedTypes": "error", "useLiteralKeys": "warn", "useOptionalChain": "warn" }, diff --git a/packages/utils/observable/src/create-reducer.ts b/packages/utils/observable/src/create-reducer.ts index 6b8b3300d..71a41c438 100644 --- a/packages/utils/observable/src/create-reducer.ts +++ b/packages/utils/observable/src/create-reducer.ts @@ -2,17 +2,16 @@ import { produce as createNextState, isDraft, isDraftable } from 'immer'; import type { Draft } from 'immer'; -import type { NoInfer, TypeGuard } from './types/ts-helpers'; -import type { Action, ActionType, ActionTypes, AnyAction, ExtractAction } from './types/actions'; +import type { TypeGuard } from './types/ts-helpers'; +import type { Action, ActionType, AnyAction, ExtractAction } from './types/actions'; import type { ReducerWithInitialState } from './types/reducers'; -import { ac } from 'vitest/dist/chunks/reporters.C_zwCd4j'; function freezeDraftable(val: T) { - // eslint-disable-next-line @typescript-eslint/no-empty-function + // biome-ignore lint/suspicious/noEmptyBlockStatements: This is a valid use case for an empty block statement return isDraftable(val) ? createNextState(val, () => {}) : val; } -// eslint-disable-next-line @typescript-eslint/ban-types +// biome-ignore lint/complexity/noBannedTypes: This is a valid use case for an empty object type type NotFunction = T extends Function ? never : T; function isStateFunction(x: unknown): x is () => S { @@ -24,11 +23,11 @@ export type ActionMatcherDescription = { reducer: CaseReducer>; }; -// eslint-disable-next-line @typescript-eslint/no-explicit-any +// biome-ignore lint/suspicious/noExplicitAny: This is a valid use case for any type ActionMatcherDescriptionCollection = Array>; interface TypedActionCreator { - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // biome-ignore lint/suspicious/noExplicitAny: This is a valid use case for any (...args: any[]): Action; type: Type; } @@ -36,9 +35,11 @@ interface TypedActionCreator { type CaseReducer = ( state: Draft, action: A, + // biome-ignore lint/suspicious/noConfusingVoidType: This is a valid use case for void ) => S | void | Draft; type CaseReducers> = { + // biome-ignore lint/suspicious/noConfusingVoidType: This is a valid use case for void [T in keyof AS]: AS[T] extends Action ? CaseReducer : void; }; diff --git a/packages/utils/observable/src/types/actions.ts b/packages/utils/observable/src/types/actions.ts index ac3539bc0..73026aaab 100644 --- a/packages/utils/observable/src/types/actions.ts +++ b/packages/utils/observable/src/types/actions.ts @@ -15,7 +15,7 @@ export type Action = { type: T }; */ export interface AnyAction extends Action { // Allows any extra properties to be defined in an action. - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // biome-ignore lint/suspicious/noExplicitAny: This is a valid use case for an explicit `any` type [extraProps: string]: any; } @@ -26,7 +26,7 @@ export interface AnyAction extends Action { * @param args - The arguments used to construct the action object. * @returns An action of type `T`. */ -// eslint-disable-next-line @typescript-eslint/no-explicit-any +// biome-ignore lint/suspicious/noExplicitAny: This is a valid use case for an explicit `any` type export type ActionCreator = (...args: any[]) => T; /** @@ -121,13 +121,13 @@ export type PayloadAction

= [void] extends [P] ? True : False; */ export type IsUnknownOrNonInferrable = IsUnknown; -/** - * Helper type. Passes T out again, but boxes it in a way that it cannot - * "widen" the type by accident if it is a generic that should be inferred - * from elsewhere. - * - * ref https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-322267089 - * - */ -export type NoInfer = [T][T extends any ? 0 : never]; - export type TypeGuard = (value: any) => value is T; -// eslint-disable-next-line @typescript-eslint/ban-types +// biome-ignore lint/complexity/noBannedTypes: This is a valid use case for an empty object type export type NotFunction = T extends Function ? never : T; export type NestedKeys = {