weareinreach / InReach

Found complex boolean return JS-W1041
Anti-pattern
Major
16 days agoa year old
Boolean return can be simplified
135}
136
137export const isValidBreadcrumbProps = (props: PossibleBreadcrumbProps): props is BreadcrumbProps => {
138	if (props.option === 'close') {139		return true140	} else if (props.option === 'back') {141		if (props.backTo === 'dynamicText') {142			if (typeof props.onClick === 'function' && typeof props.backToText === 'string') {143				return true144			}145		} else if (props.backTo === 'none' || props.backTo === 'search') {146			return true147		}148	}149	return false
150}
151type PossibleBreadcrumbProps = {
 8
 9const ajv = new Ajv()
10const validateJsonSchema = (schema: unknown): schema is JSONSchemaType<unknown> => {
11	if (schema && typeof schema === 'object' && ajv.validateSchema(schema)) {12		return true13	}14	return false
15}
16
Boolean return can be simplified
 7	if (!item || typeof item !== 'object') {
 8		return false
 9	}
10	if ('tsKey' in item) {11		return true12	}13	return false
14}
15
10	})
11	.refine(
12		(keys) => {
13			if (keys.organizationId || keys.serviceId) return true14			else return false15		},
16		{ message: 'Requires one of the following: organizationId, serviceId' }
17	)
12		includeUnsupported: z.boolean().optional().default(false),
13	})
14	.refine(({ id, slug }) => {
15		if (!id && !slug) {16			return false17		}18		return true
19	}, 'Missing required params: `id` or `slug`')
20export type TGetAttributesSchema = z.infer<typeof ZGetAttributesSchema>