Skip to content

Commit

Permalink
refactor: remove redundant code (#758)
Browse files Browse the repository at this point in the history
* refactor: remove redundant code

* add `biome-ignore`

* add override

* clean up

* ups..
  • Loading branch information
mrazauskas authored Sep 10, 2024
1 parent 4f2842c commit 14a1517
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
10 changes: 10 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@
}
}
},
{
"include": ["src/modules/helpers/modifiers.ts"],
"linter": {
"rules": {
"suspicious": {
"useAwait": "off"
}
}
}
},
{
"include": ["src/bin/index.ts"],
"linter": {
Expand Down
40 changes: 7 additions & 33 deletions src/modules/helpers/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,32 @@ import { format } from '../../services/format.js';
export function todo(message: string): void;
export async function todo(
message: string,
_cb?: () => Promise<unknown>
cb?: () => Promise<unknown>
): Promise<void>;
export function todo(message: string, _cb?: () => unknown): void;
export function todo(message: string, cb?: () => unknown): void;
export async function todo(
message: string | (() => unknown) | (() => Promise<unknown>),
_cb?: (() => unknown) | (() => Promise<unknown>)
): Promise<void> {
Write.log(
`${indentation.hasDescribe ? ' ' : ''}${format(`● ${message}`).cyan().bold()}`
);

/* c8 ignore start */ // Type guard
if (typeof _cb === 'function') {
const isAsync = _cb.constructor.name === 'AsyncFunction';

if (isAsync) return await Promise.resolve();
return;
}
/* c8 ignore stop */
}

export async function skip(
message: string,
_cb: () => Promise<unknown>
cb: () => Promise<unknown>
): Promise<void>;
export function skip(message: string, _cb: () => unknown): void;
export async function skip(_cb: () => Promise<unknown>): Promise<void>;
export function skip(_cb: () => unknown): void;
export function skip(message: string, cb: () => unknown): void;
export async function skip(cb: () => Promise<unknown>): Promise<void>;
export function skip(cb: () => unknown): void;
export async function skip(
messageOrCb: string | (() => unknown) | (() => Promise<unknown>),
_cb?: (() => unknown) | (() => Promise<unknown>)
): Promise<void> {
const message =
(typeof messageOrCb === 'string' && messageOrCb) || 'Skipping';
const message = typeof messageOrCb === 'string' ? messageOrCb : 'Skipping';

Write.log(
`${indentation.hasDescribe ? ' ' : ''}${format(`◯ ${message}`).info().bold()}`
);

/* c8 ignore start */ // Type guard
if (typeof messageOrCb === 'function') {
const isAsync = messageOrCb.constructor.name === 'AsyncFunction';

if (isAsync) return await Promise.resolve();
return;
}

if (typeof _cb === 'function') {
const isAsync = _cb.constructor.name === 'AsyncFunction';

if (isAsync) return await Promise.resolve();
return;
}
/* c8 ignore stop */
}

0 comments on commit 14a1517

Please sign in to comment.