chore(catalog-model): use unknown instead of any for validators
This commit is contained in:
@@ -113,7 +113,7 @@ describe('CommonValidatorFunctions', () => {
|
||||
[{}, true],
|
||||
[{ a: 1 }, true],
|
||||
[{ a: undefined }, false],
|
||||
] as [any, boolean][])(`isJsonSafe %p ? %p`, (value, result) => {
|
||||
] as [unknown, boolean][])(`isJsonSafe %p ? %p`, (value, result) => {
|
||||
expect(CommonValidatorFunctions.isJsonSafe(value)).toBe(result);
|
||||
});
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export class CommonValidatorFunctions {
|
||||
* @param isValidSuffix Checks that the part after the separator (or the entire value if there is no separator) is valid
|
||||
*/
|
||||
static isValidPrefixAndOrSuffix(
|
||||
value: any,
|
||||
value: unknown,
|
||||
separator: string,
|
||||
isValidPrefix: (value: string) => boolean,
|
||||
isValidSuffix: (value: string) => boolean,
|
||||
@@ -55,7 +55,7 @@ export class CommonValidatorFunctions {
|
||||
*
|
||||
* @param value The value to check
|
||||
*/
|
||||
static isJsonSafe(value: any): boolean {
|
||||
static isJsonSafe(value: unknown): boolean {
|
||||
try {
|
||||
return lodash.isEqual(value, JSON.parse(JSON.stringify(value)));
|
||||
} catch {
|
||||
@@ -69,7 +69,7 @@ export class CommonValidatorFunctions {
|
||||
* @param value The value to check
|
||||
* @see https://tools.ietf.org/html/rfc1123
|
||||
*/
|
||||
static isValidDnsSubdomain(value: any): boolean {
|
||||
static isValidDnsSubdomain(value: unknown): boolean {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
value.length >= 1 &&
|
||||
@@ -84,7 +84,7 @@ export class CommonValidatorFunctions {
|
||||
* @param value The value to check
|
||||
* @see https://tools.ietf.org/html/rfc1123
|
||||
*/
|
||||
static isValidDnsLabel(value: any): boolean {
|
||||
static isValidDnsLabel(value: unknown): boolean {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
value.length >= 1 &&
|
||||
|
||||
@@ -25,7 +25,7 @@ import { CommonValidatorFunctions } from './CommonValidatorFunctions';
|
||||
* @see https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set
|
||||
*/
|
||||
export class KubernetesValidatorFunctions {
|
||||
static isValidApiVersion(value: any): boolean {
|
||||
static isValidApiVersion(value: unknown): boolean {
|
||||
return CommonValidatorFunctions.isValidPrefixAndOrSuffix(
|
||||
value,
|
||||
'/',
|
||||
@@ -34,7 +34,7 @@ export class KubernetesValidatorFunctions {
|
||||
);
|
||||
}
|
||||
|
||||
static isValidKind(value: any): boolean {
|
||||
static isValidKind(value: unknown): boolean {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
value.length >= 1 &&
|
||||
@@ -43,7 +43,7 @@ export class KubernetesValidatorFunctions {
|
||||
);
|
||||
}
|
||||
|
||||
static isValidObjectName(value: any): boolean {
|
||||
static isValidObjectName(value: unknown): boolean {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
value.length >= 1 &&
|
||||
@@ -52,11 +52,11 @@ export class KubernetesValidatorFunctions {
|
||||
);
|
||||
}
|
||||
|
||||
static isValidNamespace(value: any): boolean {
|
||||
static isValidNamespace(value: unknown): boolean {
|
||||
return CommonValidatorFunctions.isValidDnsLabel(value);
|
||||
}
|
||||
|
||||
static isValidLabelKey(value: any): boolean {
|
||||
static isValidLabelKey(value: unknown): boolean {
|
||||
return CommonValidatorFunctions.isValidPrefixAndOrSuffix(
|
||||
value,
|
||||
'/',
|
||||
@@ -65,13 +65,13 @@ export class KubernetesValidatorFunctions {
|
||||
);
|
||||
}
|
||||
|
||||
static isValidLabelValue(value: any): boolean {
|
||||
static isValidLabelValue(value: unknown): boolean {
|
||||
return (
|
||||
value === '' || KubernetesValidatorFunctions.isValidObjectName(value)
|
||||
);
|
||||
}
|
||||
|
||||
static isValidAnnotationKey(value: any): boolean {
|
||||
static isValidAnnotationKey(value: unknown): boolean {
|
||||
return CommonValidatorFunctions.isValidPrefixAndOrSuffix(
|
||||
value,
|
||||
'/',
|
||||
@@ -80,7 +80,7 @@ export class KubernetesValidatorFunctions {
|
||||
);
|
||||
}
|
||||
|
||||
static isValidAnnotationValue(value: any): boolean {
|
||||
static isValidAnnotationValue(value: unknown): boolean {
|
||||
return typeof value === 'string';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
|
||||
export type Validators = {
|
||||
isValidApiVersion(value: any): boolean;
|
||||
isValidKind(value: any): boolean;
|
||||
isValidEntityName(value: any): boolean;
|
||||
isValidNamespace(value: any): boolean;
|
||||
isValidLabelKey(value: any): boolean;
|
||||
isValidLabelValue(value: any): boolean;
|
||||
isValidAnnotationKey(value: any): boolean;
|
||||
isValidAnnotationValue(value: any): boolean;
|
||||
isValidTag(value: any): boolean;
|
||||
isValidApiVersion(value: unknown): boolean;
|
||||
isValidKind(value: unknown): boolean;
|
||||
isValidEntityName(value: unknown): boolean;
|
||||
isValidNamespace(value: unknown): boolean;
|
||||
isValidLabelKey(value: unknown): boolean;
|
||||
isValidLabelValue(value: unknown): boolean;
|
||||
isValidAnnotationKey(value: unknown): boolean;
|
||||
isValidAnnotationValue(value: unknown): boolean;
|
||||
isValidTag(value: unknown): boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user