Skip to content

Commit

Permalink
browser/src/jsonify_notice: simplify truncateObject
Browse files Browse the repository at this point in the history
Fixes the following warning:

```
@codescene-delta-analysis codescene-delta-analysis
/ CodeScene Cloud Delta Analysis (master)

❌ New issue: Complex Method
Truncator.truncateObject has a cyclomatic complexity of 10, threshold = 9
```
  • Loading branch information
kyrylo committed Dec 8, 2022
1 parent d40a5ee commit 1d689f9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/browser/src/jsonify_notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,8 @@ class Truncator {
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
continue;
}
if (
(this.keysAllowlist.length > 0 && !isInList(key, this.keysAllowlist)) ||
(this.keysAllowlist.length === 0 && isInList(key, this.keysBlocklist))
) {
dst[key] = FILTERED;
continue;
}

if (this.filterKey(key, dst)) continue;

let value = getAttr(obj, key);

Expand All @@ -217,6 +212,18 @@ class Truncator {
}
return dst;
}

private filterKey(key: string, obj: any): boolean {
if (
(this.keysAllowlist.length > 0 && !isInList(key, this.keysAllowlist)) ||
(this.keysAllowlist.length === 0 && isInList(key, this.keysBlocklist))
) {
obj[key] = FILTERED;
return true;
}

return false;
}
}

export function truncate(value: any, opts: ITruncatorOptions = {}): any {
Expand Down

0 comments on commit 1d689f9

Please sign in to comment.