Function localStorageToggleValue
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function localStorageToggleValue(key: string, value: any, useDispatch: boolean = true, onlyDelete: boolean = false): void {
const existingArray = JSON.parse(localStorage.getItem(key) ?? '') || [];
// check if the value matches, either as a string or as a number
let indexOfId = existingArray.indexOf(value);
if (indexOfId <= -1) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getCustomLocation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export function getCustomLocation(loc: any, org: string): string {
if (!loc) return NO_POST;
// DC Post - org ex. GTM/EX/SDD
if (get(loc, 'state') === 'DC') return org || NO_POST;
// Domestic outside of DC - City, State
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function scrollToId
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
export const scrollToId = ({ el, config = {} }: any): void => {
// Get an element's distance from the top of the page
const getElemDistance = (elem: HTMLElement) => {
let location = 0;
if (elem.offsetParent) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return x;
Function getAvatarColor
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
export const getAvatarColor = (str: string, hashAdjuster: number = 0): { backgroundColor: string, color: 'black' | 'white' } | null => {
if (str) {
let hash: number = Math.floor(Math.random() * hashAdjuster);
//replaced this loop with the for loop below
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function mapDuplicates
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
export const mapDuplicates = (
data: any[] = [],
propToCheck: string = 'custom_description',
transformFunc?: (item: any) => any
): any[] => {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"