diff --git a/packages/snaps-utils/src/index.ts b/packages/snaps-utils/src/index.ts index 207972e5e2..aa87a494f1 100644 --- a/packages/snaps-utils/src/index.ts +++ b/packages/snaps-utils/src/index.ts @@ -29,3 +29,4 @@ export * from './ui'; export * from './validation'; export * from './versions'; export * from './virtual-file'; +export * from './promise'; diff --git a/packages/snaps-utils/src/manifest/validator-types.ts b/packages/snaps-utils/src/manifest/validator-types.ts index 6b97bfb721..91eb72b84f 100644 --- a/packages/snaps-utils/src/manifest/validator-types.ts +++ b/packages/snaps-utils/src/manifest/validator-types.ts @@ -1,3 +1,4 @@ +import type { Promisable } from '../promise'; import type { SnapFiles, UnvalidatedSnapFiles } from '../types'; import type { SnapManifest } from './validation'; @@ -5,7 +6,7 @@ import type { SnapManifest } from './validation'; // https://eslint.org/docs/latest/extend/custom-rules#applying-fixes export type ValidatorFix = (files: { manifest: SnapManifest; -}) => { manifest: SnapManifest } | Promise<{ manifest: SnapManifest }>; +}) => Promisable<{ manifest: SnapManifest }>; export type ValidatorSeverity = 'error' | 'warning'; diff --git a/packages/snaps-utils/src/manifest/validator.ts b/packages/snaps-utils/src/manifest/validator.ts index 319e61e5b8..25bc2e613a 100644 --- a/packages/snaps-utils/src/manifest/validator.ts +++ b/packages/snaps-utils/src/manifest/validator.ts @@ -18,6 +18,8 @@ export type ValidatorResults = { class Context implements ValidatorContext { reports: ValidatorReport[] = []; + #nextSeverity?: ValidatorSeverity = undefined; + report(message: string, fix?: ValidatorFix): void { assert(this.#nextSeverity !== undefined); this.reports.push({ @@ -34,8 +36,6 @@ class Context implements ValidatorContext { get hasErrors() { return this.reports.some((report) => report.severity === 'error'); } - - #nextSeverity?: ValidatorSeverity = undefined; } /** diff --git a/packages/snaps-utils/src/promise.ts b/packages/snaps-utils/src/promise.ts new file mode 100644 index 0000000000..eb97e2dd33 --- /dev/null +++ b/packages/snaps-utils/src/promise.ts @@ -0,0 +1 @@ +export type Promisable = Type | Promise;