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:
committed by
GitHub
parent
40bea0d95e
commit
17511be0cf
@ -1,6 +1,8 @@
|
||||
import { ReactNode, useLayoutEffect, useRef, useState } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
type ComputeNodeDimensionsProps = {
|
||||
children: (
|
||||
dimensions: { height: number; width: number } | undefined,
|
||||
@ -32,7 +34,7 @@ export const ComputeNodeDimensions = ({
|
||||
return;
|
||||
}
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
if (nodeWrapperRef.current) {
|
||||
if (isNonNullable(nodeWrapperRef.current)) {
|
||||
setNodeDimensions({
|
||||
width: nodeWrapperRef.current.offsetWidth,
|
||||
height: nodeWrapperRef.current.offsetHeight,
|
||||
|
||||
@ -28,6 +28,7 @@ export const useScopedHotkeyCallback = () =>
|
||||
.getValue();
|
||||
|
||||
if (!currentHotkeyScopes.includes(scope)) {
|
||||
// eslint-disable-next-line @nx/workspace-explicit-boolean-predicates-in-if
|
||||
if (DEBUG_HOTKEY_SCOPE) {
|
||||
logDebug(
|
||||
`%cI can't call hotkey (${
|
||||
@ -42,6 +43,7 @@ export const useScopedHotkeyCallback = () =>
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @nx/workspace-explicit-boolean-predicates-in-if
|
||||
if (DEBUG_HOTKEY_SCOPE) {
|
||||
logDebug(
|
||||
`%cI can call hotkey (${
|
||||
|
||||
@ -2,6 +2,8 @@ import { Options, useHotkeys } from 'react-hotkeys-hook';
|
||||
import { Keys } from 'react-hotkeys-hook/dist/types';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import { pendingHotkeyState } from '../states/internal/pendingHotkeysState';
|
||||
|
||||
import { useScopedHotkeyCallback } from './useScopedHotkeyCallback';
|
||||
@ -55,7 +57,7 @@ export const useSequenceHotkeys = (
|
||||
|
||||
setPendingHotkey(null);
|
||||
|
||||
if (options.preventDefault) {
|
||||
if (isNonNullable(options.preventDefault)) {
|
||||
keyboardEvent.stopImmediatePropagation();
|
||||
keyboardEvent.stopPropagation();
|
||||
keyboardEvent.preventDefault();
|
||||
|
||||
@ -63,15 +63,15 @@ export const useSetHotkeyScope = () =>
|
||||
|
||||
const scopesToSet: string[] = [];
|
||||
|
||||
if (newHotkeyScope.customScopes?.commandMenu) {
|
||||
if (newHotkeyScope.customScopes?.commandMenu === true) {
|
||||
scopesToSet.push(AppHotkeyScope.CommandMenu);
|
||||
}
|
||||
|
||||
if (newHotkeyScope?.customScopes?.goto) {
|
||||
if (newHotkeyScope?.customScopes?.goto === true) {
|
||||
scopesToSet.push(AppHotkeyScope.Goto);
|
||||
}
|
||||
|
||||
if (newHotkeyScope?.customScopes?.keyboardShortcutMenu) {
|
||||
if (newHotkeyScope?.customScopes?.keyboardShortcutMenu === true) {
|
||||
scopesToSet.push(AppHotkeyScope.KeyboardShortcutMenu);
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@ import React from 'react';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { fireEvent, render, renderHook } from '@testing-library/react';
|
||||
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import {
|
||||
ClickOutsideMode,
|
||||
useListenClickOutside,
|
||||
@ -46,7 +48,7 @@ describe('useListenClickOutside', () => {
|
||||
);
|
||||
|
||||
act(() => {
|
||||
if (containerRef.current) {
|
||||
if (isNonNullable(containerRef.current)) {
|
||||
fireEvent.mouseDown(containerRef.current);
|
||||
fireEvent.click(containerRef.current);
|
||||
}
|
||||
@ -95,7 +97,7 @@ describe('useListenClickOutsideByClassName', () => {
|
||||
|
||||
act(() => {
|
||||
const notClickableElement = container.querySelector('.will-trigger');
|
||||
if (notClickableElement) {
|
||||
if (isNonNullable(notClickableElement)) {
|
||||
fireEvent.mouseDown(notClickableElement);
|
||||
fireEvent.click(notClickableElement);
|
||||
}
|
||||
@ -122,7 +124,7 @@ describe('useListenClickOutsideByClassName', () => {
|
||||
|
||||
act(() => {
|
||||
const notClickableElement = container.querySelector('.wont-trigger');
|
||||
if (notClickableElement) {
|
||||
if (isNonNullable(notClickableElement)) {
|
||||
fireEvent.mouseDown(notClickableElement);
|
||||
fireEvent.click(notClickableElement);
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
ClickOutsideMode,
|
||||
useListenClickOutsideV2,
|
||||
} from '@/ui/utilities/pointer-event/hooks/useListenClickOutsideV2';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const containerRef = React.createRef<HTMLDivElement>();
|
||||
const nullRef = React.createRef<HTMLDivElement>();
|
||||
@ -76,7 +77,7 @@ describe('useListenClickOutsideV2', () => {
|
||||
);
|
||||
|
||||
act(() => {
|
||||
if (containerRef.current) {
|
||||
if (isNonNullable(containerRef.current)) {
|
||||
fireEvent.mouseDown(containerRef.current);
|
||||
fireEvent.click(containerRef.current);
|
||||
}
|
||||
@ -100,7 +101,7 @@ describe('useListenClickOutsideV2', () => {
|
||||
);
|
||||
|
||||
act(() => {
|
||||
if (containerRef.current) {
|
||||
if (isNonNullable(containerRef.current)) {
|
||||
fireEvent.mouseDown(containerRef.current);
|
||||
fireEvent.click(containerRef.current);
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import { ScopeInternalContext } from '../types/ScopeInternalContext';
|
||||
|
||||
import { useScopeInternalContext } from './useScopeInternalContext';
|
||||
@ -10,9 +12,9 @@ export const useAvailableScopeIdOrThrow = <T extends { scopeId: string }>(
|
||||
|
||||
const scopeIdFromContext = scopeInternalContext?.scopeId;
|
||||
|
||||
if (scopeIdFromProps) {
|
||||
if (isNonEmptyString(scopeIdFromProps)) {
|
||||
return scopeIdFromProps;
|
||||
} else if (scopeIdFromContext) {
|
||||
} else if (isNonEmptyString(scopeIdFromContext)) {
|
||||
return scopeIdFromContext;
|
||||
} else {
|
||||
throw new Error('Scope id is not provided and cannot be found in context.');
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import React from 'react';
|
||||
import { expect } from '@storybook/test';
|
||||
import { act, fireEvent, renderHook } from '@testing-library/react';
|
||||
import { RecoilRoot, useRecoilValue } from 'recoil';
|
||||
|
||||
import { useListenScroll } from '@/ui/utilities/scroll/hooks/useListenScroll';
|
||||
import { isScrollingState } from '@/ui/utilities/scroll/states/isScrollingState';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const containerRef = React.createRef<HTMLDivElement>();
|
||||
|
||||
@ -38,7 +40,7 @@ describe('useListenScroll', () => {
|
||||
const container = document.querySelector('#container');
|
||||
|
||||
act(() => {
|
||||
if (container) fireEvent.scroll(container);
|
||||
if (isNonNullable(container)) fireEvent.scroll(container);
|
||||
});
|
||||
|
||||
expect(result.current.isScrolling).toBe(true);
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
|
||||
import { ScrollWrapperContext } from '../components/ScrollWrapper';
|
||||
|
||||
export const useScrollWrapperScopedRef = () => {
|
||||
const scrollWrapperRef = useContext(ScrollWrapperContext);
|
||||
|
||||
if (!scrollWrapperRef)
|
||||
if (isNullable(scrollWrapperRef))
|
||||
throw new Error(
|
||||
`Using a scroll ref without a ScrollWrapper : verify that you are using a ScrollWrapper if you intended to do so.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user