Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-dldc committed Jul 23, 2024
1 parent e93c99b commit ba80cb2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"deno.enable": true,
"editor.defaultFormatter": "denoland.vscode-deno",
"npm.autoDetect": "off"
"npm.autoDetect": "off",
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
38 changes: 20 additions & 18 deletions src/FormiField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function create<Value, Issue, Children extends TFormiFieldTree>({
}

function validate<NextValue = Value, NextIssue = never>(
validateFn: TValidateFn<Value, NextValue, Issue | NextIssue>
validateFn: TValidateFn<Value, NextValue, Issue | NextIssue>,
): TFormiField<NextValue, Issue | NextIssue, Children> {
const nextValidate = (input: any) => {
const prev = currentValidateFn(input);
Expand All @@ -120,10 +120,11 @@ function create<Value, Issue, Children extends TFormiFieldTree>({
}

function withChildren(
update: Children | TChildrenUpdateFn<Children>
update: Children | TChildrenUpdateFn<Children>,
): TFormiField<Value, Issue, Children> {
const nextChildren =
typeof update === "function" ? update(children) : update;
const nextChildren = typeof update === "function"
? update(children)
: update;
return create({
key: self.key,
children: nextChildren,
Expand Down Expand Up @@ -197,7 +198,7 @@ function nonEmptyfile(): TFormiField<File, TNonEmptyFileIssues, null> {
}

function group<Children extends TFormiFieldTree>(
children: Children
children: Children,
): TFormiField<TFormiFieldTreeValue<Children>, TFormiIssueBase, Children> {
return create<TFormiFieldTreeValue<Children>, TFormiIssueBase, Children>({
key: createFormiKey(),
Expand All @@ -209,14 +210,15 @@ function group<Children extends TFormiFieldTree>(

function repeat<Child extends TFormiFieldTree>(
child: Child,
initialCount: number = 1
initialCount: number = 1,
): TFormiField<
Array<TFormiFieldTreeValue<Child>>,
TFormiIssueBase,
Array<Child>
> {
const initialChildren = Array.from({ length: initialCount }, () =>
cloneFormiFieldTree(child)
const initialChildren = Array.from(
{ length: initialCount },
() => cloneFormiFieldTree(child),
);
return create<
Array<TFormiFieldTreeValue<Child>>,
Expand All @@ -234,7 +236,7 @@ function repeat<Child extends TFormiFieldTree>(

function restoreRepeat<Child extends TFormiFieldTree>(
child: Child,
paths: ReadonlyArray<TPath>
paths: ReadonlyArray<TPath>,
): Array<Child> {
let size = 0;
const pathsByIndex = new Map<number, Array<TPath>>();
Expand All @@ -256,7 +258,7 @@ function restoreRepeat<Child extends TFormiFieldTree>(
(child, index) => {
const paths = pathsByIndex.get(index) ?? [];
return restoreFormiFieldTreeFromPaths(child, paths);
}
},
);
}

Expand All @@ -269,13 +271,13 @@ function getValidateFn(field: TFormiFieldAny): TValidateFn<any, any, any> {
}

function getRestoreFromPaths(
field: TFormiFieldAny
field: TFormiFieldAny,
): TRestoreFromPaths<any> | null {
return field[FIELD_RESTORE_FROM_PATHS];
}

function isSingleValue(
input: TInputBase<null>
input: TInputBase<null>,
): TValidateResult<FormDataEntryValue | null, TFormiIssueSingle> {
if (input.values === null) {
return success(null);
Expand All @@ -290,7 +292,7 @@ function isSingleValue(
}

function isNotNull<Value>(
input: Value | null
input: Value | null,
): TValidateResult<Value, TFormiIssueBase> {
if (input === null) {
return failure<TFormiIssueBase>({ kind: "MissingField" });
Expand All @@ -299,7 +301,7 @@ function isNotNull<Value>(
}

function isNotFile<Value>(
input: Value | File
input: Value | File,
): TValidateResult<Value, TFormiIssueNotFile> {
if (input instanceof FileOrBlob) {
return failure<TFormiIssueNotFile>({ kind: "UnexpectedFile" });
Expand All @@ -308,7 +310,7 @@ function isNotFile<Value>(
}

function isNumber(
input: string | null
input: string | null,
): TValidateResult<number | null, TFormiIssueNumber> {
if (input === "" || input === null) {
return success<number | null>(null);
Expand All @@ -331,7 +333,7 @@ function isDefined(input: any): TValidateResult<boolean, TFormiIssueBase> {
}

function isFile(
entry: FormDataEntryValue | null
entry: FormDataEntryValue | null,
): TValidateResult<File, TFormiIssueNotString> {
if (entry === null) {
return { success: false, issue: { kind: "MissingField" } };
Expand All @@ -343,7 +345,7 @@ function isFile(
}

function isNonEmptyFile(
input: File
input: File,
): TValidateResult<File, TFormiIssueNonEmptyFile> {
if (input.size === 0) {
return failure<TFormiIssueNonEmptyFile>({ kind: "EmptyFile" });
Expand All @@ -356,7 +358,7 @@ export function success<Value>(value: Value): TValidateSuccess<Value> {
}

export function failure<Issue>(
issue?: Issue | Array<Issue>
issue?: Issue | Array<Issue>,
): TValidateFailure<Issue> {
if (issue === undefined) {
return { success: false };
Expand Down
14 changes: 7 additions & 7 deletions src/FormiField.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type TValidateResult<Value, Issue> =
| TValidateFailure<Issue>;

export type TValidateFn<Input, Value, Issue> = (
value: Input
value: Input,
) => TValidateResult<Value, Issue>;

export type TChildrenUpdateFn<Children> = (prev: Children) => Children;
Expand All @@ -40,20 +40,20 @@ export type TFormiFieldIssue<F extends TFormiFieldAny> =
export type TFormiFieldChildren<F extends TFormiFieldAny> = F["children"];

export type TRestoreFromPaths<Children extends TFormiFieldTree> = (
paths: ReadonlyArray<TPath>
paths: ReadonlyArray<TPath>,
) => Children;

export type TValidate<Value, Issue, Children extends TFormiFieldTree = null> = <
NextValue = Value,
NextIssue = never
NextIssue = never,
>(
validateFn: TValidateFn<Value, NextValue, Issue | NextIssue>
validateFn: TValidateFn<Value, NextValue, Issue | NextIssue>,
) => TFormiField<NextValue, Issue | NextIssue, Children>;

export interface TFormiField<
Value,
Issue,
Children extends TFormiFieldTree = null
Children extends TFormiFieldTree = null,
> {
readonly [FIELD_RESTORE_FROM_PATHS]: TRestoreFromPaths<Children> | null;
readonly [FIELD_VALIDATE_FN]: TValidateFn<any, Value, Issue>;
Expand All @@ -69,14 +69,14 @@ export interface TFormiField<
Children
>;
readonly withChildren: (
children: Children | TChildrenUpdateFn<Children>
children: Children | TChildrenUpdateFn<Children>,
) => TFormiField<Value, Issue, Children>;
}

export interface ICreateFieldOptions<
Value,
Issue,
Children extends TFormiFieldTree
Children extends TFormiFieldTree,
> {
key: TFormiKey;
children: Children;
Expand Down
10 changes: 5 additions & 5 deletions src/FormiIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export type TFormiIssueNotFile = TFormiIssueBase | { kind: "UnexpectedFile" };
export type TFormiIssueNotString =
| TFormiIssueBase
| {
kind: "UnexpectedString";
};
kind: "UnexpectedString";
};
export type TFormiIssueNumber =
| TFormiIssueBase
| {
kind: "InvalidNumber";
value: string;
};
kind: "InvalidNumber";
value: string;
};
export type TFormiIssueNonEmptyFile = TFormiIssueBase | { kind: "EmptyFile" };

export type TFormiIssue =
Expand Down

0 comments on commit ba80cb2

Please sign in to comment.