From 6fb79722e15b5b44ba928e246054fae716100474 Mon Sep 17 00:00:00 2001 From: jaluik Date: Mon, 19 Feb 2024 16:33:34 +0800 Subject: [PATCH 1/2] feat: add custom filter --- packages/core/src/interfaces/options.interface.ts | 3 +++ packages/core/src/rabin-karp.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/src/interfaces/options.interface.ts b/packages/core/src/interfaces/options.interface.ts index 91cf9ed2..5025b6b6 100644 --- a/packages/core/src/interfaces/options.interface.ts +++ b/packages/core/src/interfaces/options.interface.ts @@ -1,3 +1,5 @@ +import { IClone } from ".."; + export interface IOptions { executionId?: string; minLines?: number; @@ -33,6 +35,7 @@ export interface IOptions { reportersOptions?: Record; tokensToSkip?: string[]; hashFunction?: (value: string) => string; + customFilter?: (clone: IClone) => boolean; exitCode?: number; } diff --git a/packages/core/src/rabin-karp.ts b/packages/core/src/rabin-karp.ts index 809ca84d..cc9ff53d 100644 --- a/packages/core/src/rabin-karp.ts +++ b/packages/core/src/rabin-karp.ts @@ -60,12 +60,18 @@ export class RabinKarp { const validation: IValidationResult = runCloneValidators(clone, this.options, this.cloneValidators); - if (validation.status) { + let status = validation.status + + if (this.options.customFilter) { + status = status && this.options.customFilter(clone) + } + + if (status) { this.eventEmitter.emit('CLONE_FOUND', {clone}) } else { this.eventEmitter.emit('CLONE_SKIPPED', {clone, validation}) } - return validation.status; + return status; } private static createClone(format: string, mapFrameA: IMapFrame, mapFrameB: IMapFrame): IClone { From a82ecf3827fde956d4481038755ef869351b6aca Mon Sep 17 00:00:00 2001 From: jaluik Date: Tue, 20 Feb 2024 09:05:17 +0800 Subject: [PATCH 2/2] refactor: rename the prop name --- packages/core/src/interfaces/options.interface.ts | 2 +- packages/core/src/rabin-karp.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/interfaces/options.interface.ts b/packages/core/src/interfaces/options.interface.ts index 5025b6b6..812c3e88 100644 --- a/packages/core/src/interfaces/options.interface.ts +++ b/packages/core/src/interfaces/options.interface.ts @@ -35,7 +35,7 @@ export interface IOptions { reportersOptions?: Record; tokensToSkip?: string[]; hashFunction?: (value: string) => string; - customFilter?: (clone: IClone) => boolean; + customValidate?: (clone: IClone) => boolean; exitCode?: number; } diff --git a/packages/core/src/rabin-karp.ts b/packages/core/src/rabin-karp.ts index cc9ff53d..d41e7d25 100644 --- a/packages/core/src/rabin-karp.ts +++ b/packages/core/src/rabin-karp.ts @@ -62,8 +62,8 @@ export class RabinKarp { let status = validation.status - if (this.options.customFilter) { - status = status && this.options.customFilter(clone) + if (this.options.customValidate) { + status = status && this.options.customValidate(clone) } if (status) {