Skip to content

No Ianitor In Function Body

ErrorRoblox
small-rules/no-ianitor-in-function-body

Disallow Ianitor validator creation inside function bodies. Hoist to module scope to avoid recreating validators on every call.

Diagnostic Messages

hoistIanitorValidator
Ianitor validator created inside function body is slow — hoist to module scope. Example: const validator = Ianitor.keyOf(ids);

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-ianitor-in-function-body": "error"
}
}

Examples

Ianitor validator inside function
import { Ianitor } from "@packages/ianitor";
const placementVfxIds = { a: "a", b: "b" } as const;
export function isPlacementVfxId(value: unknown) {
return Ianitor.keyOf(placementVfxIds)(value).success;
}
hoisted Ianitor validator
import { Ianitor } from "@packages/ianitor";
const placementVfxIds = { a: "a", b: "b" } as const;
const isPlacementVfxIdIanitor = Ianitor.keyOf(placementVfxIds);
export function isPlacementVfxId(value: unknown) {
return isPlacementVfxIdIanitor(value).success;
}