Skip to content
Merged
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
18 changes: 9 additions & 9 deletions packages/object-schema/src/validation-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
export class ValidationStrategy {
/**
* Validates that a value is an array.
* @param {*} value The value to validate.
* @param {unknown} value The value to validate.
* @returns {void}
* @throws {TypeError} If the value is invalid.
*/
Expand All @@ -24,7 +24,7 @@ export class ValidationStrategy {

/**
* Validates that a value is a boolean.
* @param {*} value The value to validate.
* @param {unknown} value The value to validate.
* @returns {void}
* @throws {TypeError} If the value is invalid.
*/
Expand All @@ -36,7 +36,7 @@ export class ValidationStrategy {

/**
* Validates that a value is a number.
* @param {*} value The value to validate.
* @param {unknown} value The value to validate.
* @returns {void}
* @throws {TypeError} If the value is invalid.
*/
Expand All @@ -47,8 +47,8 @@ export class ValidationStrategy {
}

/**
* Validates that a value is a object.
* @param {*} value The value to validate.
* Validates that a value is an object.
* @param {unknown} value The value to validate.
* @returns {void}
* @throws {TypeError} If the value is invalid.
*/
Expand All @@ -59,8 +59,8 @@ export class ValidationStrategy {
}

/**
* Validates that a value is a object or null.
* @param {*} value The value to validate.
* Validates that a value is an object or null.
* @param {unknown} value The value to validate.
* @returns {void}
* @throws {TypeError} If the value is invalid.
*/
Expand All @@ -72,7 +72,7 @@ export class ValidationStrategy {

/**
* Validates that a value is a string.
* @param {*} value The value to validate.
* @param {unknown} value The value to validate.
* @returns {void}
* @throws {TypeError} If the value is invalid.
*/
Expand All @@ -84,7 +84,7 @@ export class ValidationStrategy {

/**
* Validates that a value is a non-empty string.
* @param {*} value The value to validate.
* @param {unknown} value The value to validate.
* @returns {void}
* @throws {TypeError} If the value is invalid.
*/
Expand Down
35 changes: 35 additions & 0 deletions packages/object-schema/tests/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
type PropertyDefinition,
type PropertyDefinitionWithSchema,
type PropertyDefinitionWithStrategies,
ValidationStrategy,
} from "@eslint/object-schema";

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -134,6 +135,40 @@ MergeStrategy.assign({ a: 1 }, { a: "a" }) satisfies {

// #endregion MergeStrategy

//-----------------------------------------------------------------------------
// Tests for ValidationStrategy
//-----------------------------------------------------------------------------

// #region ValidationStrategy

const validateArray: CustomValidationStrategy = ValidationStrategy.array;
const validateBoolean: CustomValidationStrategy = ValidationStrategy.boolean;
const validateNumber: CustomValidationStrategy = ValidationStrategy.number;
const validateObject: CustomValidationStrategy = ValidationStrategy.object;
const validateObjectOptional: CustomValidationStrategy =
ValidationStrategy["object?"];
const validateString: CustomValidationStrategy = ValidationStrategy.string;
const validateNonEmptyString: CustomValidationStrategy =
ValidationStrategy["string!"];

ValidationStrategy.array([]);
ValidationStrategy.boolean(true);
ValidationStrategy.number(123);
ValidationStrategy.object({ foo: 1 });
ValidationStrategy["object?"](null);
ValidationStrategy.string("foo");
ValidationStrategy["string!"]("foo");

validateArray([]);
validateBoolean(true);
validateNumber(123);
validateObject({ foo: 1 });
validateObjectOptional(null);
validateString("foo");
validateNonEmptyString("foo");

// #endregion ValidationStrategy

//-----------------------------------------------------------------------------
// Tests for PropertyDefinition
//-----------------------------------------------------------------------------
Expand Down
Loading