TWNTY-3794 - ESLint rule: only take explicit boolean predicates in if statements (#4354)

* ESLint rule: only take explicit boolean predicates in if statements

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>

* Merge main

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>

* Fix frontend linter errors

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>

* Fix jest

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>

* Refactor according to review

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>

* Refactor according to review

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>

* Fix lint on new code

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>

---------

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>
This commit is contained in:
gitstart-app[bot]
2024-03-09 10:48:19 +01:00
committed by GitHub
parent 40bea0d95e
commit 17511be0cf
164 changed files with 655 additions and 367 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable @nx/workspace-explicit-boolean-predicates-in-if */
import { isNull, isNumber, isString } from '@sniptt/guards';
import { logError } from './logError';

View File

@ -1,5 +1,7 @@
import { LinkType } from '@/ui/navigation/link/components/SocialLink';
import { isNonNullable } from './isNonNullable';
export const checkUrlType = (url: string) => {
if (
/^(http|https):\/\/(?:www\.)?linkedin.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(
@ -8,7 +10,11 @@ export const checkUrlType = (url: string) => {
) {
return LinkType.LinkedIn;
}
if (url.match(/^((http|https):\/\/)?(?:www\.)?twitter\.com\/(\w+)?/i)) {
if (
isNonNullable(
/^((http|https):\/\/)?(?:www\.)?twitter\.com\/(\w+)?/i.exec(url),
)
) {
return LinkType.Twitter;
}

View File

@ -1,3 +1,4 @@
/* eslint-disable @nx/workspace-explicit-boolean-predicates-in-if */
import { isDate, isNumber, isString } from '@sniptt/guards';
import { differenceInCalendarDays, formatDistanceToNow } from 'date-fns';
import { DateTime } from 'luxon';

View File

@ -1,5 +1,7 @@
import { LinkType } from '@/ui/navigation/link/components/SocialLink';
import { isNonNullable } from './isNonNullable';
type getUrlDisplayValueByUrlTypeProps = {
type: LinkType;
href: string;
@ -13,8 +15,8 @@ export const getDisplayValueByUrlType = ({
const matches = href.match(
/(?:https?:\/\/)?(?:www.)?linkedin.com\/(?:in|company|school)\/(.*)/,
);
if (matches && matches[1]) {
return matches[1];
if (isNonNullable(matches?.[1])) {
return matches?.[1];
} else {
return 'LinkedIn';
}
@ -24,8 +26,8 @@ export const getDisplayValueByUrlType = ({
const matches = href.match(
/(?:https?:\/\/)?(?:www.)?twitter.com\/([-a-zA-Z0-9@:%_+.~#?&//=]*)/,
);
if (matches && matches[1]) {
return `@${matches[1]}`;
if (isNonNullable(matches?.[1])) {
return `@${matches?.[1]}`;
} else {
return '@twitter';
}

View File

@ -1,9 +1,11 @@
import { isNumber } from '@sniptt/guards';
export const isNonEmptyArray = <T>(
probableArray: T[] | readonly T[] | undefined | null,
): probableArray is NonNullable<T[]> => {
if (
Array.isArray(probableArray) &&
probableArray.length &&
isNumber(probableArray.length) &&
probableArray.length > 0
) {
return true;

View File

@ -0,0 +1,4 @@
import { isNull, isUndefined } from '@sniptt/guards';
export const isNullable = (value: any): value is null | undefined =>
isUndefined(value) || isNull(value);

View File

@ -2,6 +2,8 @@ import { AtomEffect } from 'recoil';
import { cookieStorage } from '~/utils/cookie-storage';
import { isNonNullable } from './isNonNullable';
export const localStorageEffect =
<T>(key: string): AtomEffect<T> =>
({ setSelf, onSet }) => {
@ -21,7 +23,10 @@ export const cookieStorageEffect =
<T>(key: string): AtomEffect<T | null> =>
({ setSelf, onSet }) => {
const savedValue = cookieStorage.getItem(key);
if (savedValue != null && JSON.parse(savedValue)['accessToken']) {
if (
isNonNullable(savedValue) &&
isNonNullable(JSON.parse(savedValue)['accessToken'])
) {
setSelf(JSON.parse(savedValue));
}