Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update noBannedTypes rule to error and adjust linting exceptions #2899

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/crazy-ghosts-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@equinor/fusion-observable": patch
---

fixed `noBannedTypes` Biome rules
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"rules": {
"recommended": true,
"complexity": {
"noBannedTypes": "warn",
"noBannedTypes": "error",
"useLiteralKeys": "warn",
"useOptionalChain": "warn"
},
Expand Down
15 changes: 8 additions & 7 deletions packages/utils/observable/src/create-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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 = unknown> = T extends Function ? never : T;

function isStateFunction<S>(x: unknown): x is () => S {
Expand All @@ -24,21 +23,23 @@ export type ActionMatcherDescription<S, A extends AnyAction> = {
reducer: CaseReducer<S, NoInfer<A>>;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is a valid use case for any
type ActionMatcherDescriptionCollection<S> = Array<ActionMatcherDescription<S, any>>;

interface TypedActionCreator<Type extends string> {
// 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: Type;
}

type CaseReducer<S = unknown, A extends Action = AnyAction> = (
state: Draft<S>,
action: A,
// biome-ignore lint/suspicious/noConfusingVoidType: This is a valid use case for void
) => S | void | Draft<S>;

type CaseReducers<S, AS extends Record<string, Action>> = {
// biome-ignore lint/suspicious/noConfusingVoidType: This is a valid use case for void
[T in keyof AS]: AS[T] extends Action ? CaseReducer<S, AS[T]> : void;
};

Expand Down
8 changes: 4 additions & 4 deletions packages/utils/observable/src/types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Action<T extends TypeConstant = TypeConstant> = { 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;
}

Expand All @@ -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<T extends Action = AnyAction> = (...args: any[]) => T;

/**
Expand Down Expand Up @@ -121,13 +121,13 @@ export type PayloadAction<P = void, T extends string = string, M = never, E = ne
payload: P;
type: T;
} & ([M] extends [never]
? // eslint-disable-next-line @typescript-eslint/ban-types
? // biome-ignore lint/complexity/noBannedTypes: This is a valid use case for an empty object type
{}
: {
meta: M;
}) &
([E] extends [never]
? // eslint-disable-next-line @typescript-eslint/ban-types
? // biome-ignore lint/complexity/noBannedTypes: This is a valid use case for an empty object type
{}
: {
error: E;
Expand Down
12 changes: 1 addition & 11 deletions packages/utils/observable/src/types/ts-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,9 @@ export type IfVoid<P, True, False> = [void] extends [P] ? True : False;
*/
export type IsUnknownOrNonInferrable<T, True, False> = IsUnknown<T, True, False>;

/**
* 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][T extends any ? 0 : never];

export type TypeGuard<T> = (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 = unknown> = T extends Function ? never : T;

export type NestedKeys<TObject extends object> = {
Expand Down
Loading