From a13037310dc7015eb3f33720f3ab9fca2d9572c1 Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Thu, 17 Aug 2023 20:10:26 +0300 Subject: [PATCH] use SpecificKey in validateForSpecificSyntax() Squashed commit of the following: commit f4fc93eac189215a2760e24400535ac3a9fc6631 Merge: b0ffee47 7ff682c9 Author: Slava Leleka Date: Thu Aug 17 19:55:09 2023 +0300 Merge branch 'master' into fix/AG-24028-use-SpecificKey-enum commit b0ffee472ea142cbe5b14347e83760145fb076f7 Author: Slava Leleka Date: Thu Aug 17 19:06:36 2023 +0300 use SpecificKey in validateForSpecificSyntax() --- .../agtree/src/compatibility-tables/index.ts | 9 +++++---- packages/agtree/src/validator/index.ts | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/agtree/src/compatibility-tables/index.ts b/packages/agtree/src/compatibility-tables/index.ts index 5a19d22e5..0e533ba30 100644 --- a/packages/agtree/src/compatibility-tables/index.ts +++ b/packages/agtree/src/compatibility-tables/index.ts @@ -4,8 +4,9 @@ export { getModifiersData } from './modifiers-data'; -export type { - ModifierData, - ModifierDataMap, - SpecificPlatformModifierData, +export { + type ModifierData, + type ModifierDataMap, + type SpecificPlatformModifierData, + SpecificKey, } from './types'; diff --git a/packages/agtree/src/validator/index.ts b/packages/agtree/src/validator/index.ts index 25b794aab..7f5e4dbaa 100644 --- a/packages/agtree/src/validator/index.ts +++ b/packages/agtree/src/validator/index.ts @@ -9,6 +9,7 @@ import { type ModifierDataMap, type SpecificPlatformModifierData, getModifiersData, + SpecificKey, } from '../compatibility-tables'; import { type Modifier } from '../parser/common'; import { AdblockSyntax } from '../utils/adblockers'; @@ -145,42 +146,42 @@ const validateForSpecificSyntax = ( } // e.g. 'object-subrequest' - if (specificBlockerData.removed) { + if (specificBlockerData[SpecificKey.Removed]) { return getInvalidValidationResult(`${INVALID_ERROR_PREFIX.REMOVED}: '${modifierName}'`); } - if (specificBlockerData.deprecated) { - if (!specificBlockerData.deprecation_message) { + if (specificBlockerData[SpecificKey.Deprecated]) { + if (!specificBlockerData[SpecificKey.DeprecationMessage]) { throw new Error('Deprecation notice is required for deprecated modifier'); } return { ok: true, - warn: specificBlockerData.deprecation_message, + warn: specificBlockerData[SpecificKey.DeprecationMessage], }; } - if (specificBlockerData.block_only && isException) { + if (specificBlockerData[SpecificKey.BlockOnly] && isException) { return getInvalidValidationResult(`${INVALID_ERROR_PREFIX.BLOCK_ONLY}: '${modifierName}'`); } - if (specificBlockerData.exception_only && !isException) { + if (specificBlockerData[SpecificKey.ExceptionOnly] && !isException) { return getInvalidValidationResult(`${INVALID_ERROR_PREFIX.EXCEPTION_ONLY}: '${modifierName}'`); } // e.g. '~domain=example.com' - if (!specificBlockerData.negatable && modifier.exception) { + if (!specificBlockerData[SpecificKey.Negatable] && modifier.exception) { return getInvalidValidationResult(`${INVALID_ERROR_PREFIX.NOT_NEGATABLE}: '${modifierName}'`); } // e.g. 'domain' - if (specificBlockerData.assignable) { + if (specificBlockerData[SpecificKey.Assignable]) { /** * Some assignable modifiers can be used without a value, * e.g. '@@||example.com^$cookie'. */ if (!modifier.value // value should be specified if it is not optional - && !specificBlockerData.value_optional) { + && !specificBlockerData[SpecificKey.ValueOptional]) { return getInvalidValidationResult(`${INVALID_ERROR_PREFIX.VALUE_REQUIRED}: '${modifierName}'`); } /**