Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up all lint warnings #1199

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fcdb525
Clean up a few lint warnings
snowystinger Oct 28, 2020
17d4031
Merge branch 'main' into clean-up-lint-warnings
snowystinger Oct 28, 2020
629adfe
Merge branch 'main' into clean-up-lint-warnings
snowystinger Nov 11, 2020
fb1c9e4
Merge branch 'main' of https://github.com/adobe/react-spectrum into c…
LFDanLu Dec 4, 2020
cb01f26
fixing some lint warnings
LFDanLu Dec 4, 2020
7656b73
more lint fixes
LFDanLu Dec 5, 2020
0fa07a6
fixing new story lint
LFDanLu Dec 5, 2020
4829591
Updating useOverlayPositon to not use dep array
LFDanLu Dec 7, 2020
e224f60
fixing rest of linter warnings
LFDanLu Dec 7, 2020
31d731b
fixing table test
LFDanLu Dec 8, 2020
2430934
Merge branch 'main' of https://github.com/adobe/react-spectrum into c…
LFDanLu Dec 8, 2020
afa543f
removing a whiteline
LFDanLu Dec 8, 2020
4696ec4
Merge branch 'main' into clean-up-lint-warnings
LFDanLu Dec 8, 2020
93e2f89
reverting lint max-level change
LFDanLu Dec 8, 2020
d6f3d79
Merge branch 'clean-up-lint-warnings' of https://github.com/adobe/rea…
LFDanLu Dec 8, 2020
9ba8140
fix breadcrumb layouteffect dep array
LFDanLu Dec 8, 2020
1d981ed
Merge branch 'main' of github.com:adobe/react-spectrum into clean-up-…
LFDanLu Feb 22, 2021
5e501f8
Merge branch 'main' of github.com:adobe/react-spectrum into clean-up-…
LFDanLu Apr 6, 2021
c8440b1
Merge branch 'main' into clean-up-lint-warnings
snowystinger Apr 9, 2021
874011a
Merge commit 'd04e70b27e40d0a04312d8c5e40127eceeefcd22' into clean-up…
snowystinger Jun 18, 2021
2166816
Merge branch 'main' into clean-up-lint-warnings
snowystinger Sep 1, 2021
2d273d0
Merge branch 'main' into clean-up-lint-warnings
snowystinger Sep 21, 2021
b4fa626
cleaning up more lint warnings
LFDanLu Sep 21, 2021
0081d9f
Merge branch 'main' into clean-up-lint-warnings
LFDanLu Sep 21, 2021
0d595fa
fix lint warnings
snowystinger Sep 23, 2021
ac9f2b4
Merge branch 'main' into clean-up-lint-warnings
snowystinger Sep 23, 2021
f21b763
Merge branch 'main' into clean-up-lint-warnings
LFDanLu Sep 23, 2021
ed616c4
Merge branch 'main' into clean-up-lint-warnings
snowystinger Jan 4, 2022
57c3437
Merge branch 'main' into clean-up-lint-warnings
majornista Feb 1, 2022
98ef135
Merge branch 'main' into clean-up-lint-warnings
majornista Feb 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@react-aria/color/src/useColorField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function useColorField(
} else if (e.deltaY < 0) {
decrement();
}
}, [isReadOnly, isDisabled, decrement, increment]);
}, [decrement, increment]);
// If the input isn't supposed to receive input, disable scrolling.
let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, ref);
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-aria/dnd/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export function readFromDataTransfer(dataTransfer: DataTransfer) {
// only implemented in Chrome.
if (typeof item.webkitGetAsEntry === 'function') {
let entry: FileSystemEntry = item.webkitGetAsEntry();
// eslint-disable-next-line max-depth
if (!entry) {
// For some reason, Firefox includes an item with type image/png when copy
// and pasting any file or directory (no matter the type), but returns `null` for both
Expand All @@ -215,7 +216,7 @@ export function readFromDataTransfer(dataTransfer: DataTransfer) {
// This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.
continue;
}

// eslint-disable-next-line max-depth
if (entry.isFile) {
items.push(createFileItem(item.getAsFile()));
} else if (entry.isDirectory) {
Expand Down
10 changes: 4 additions & 6 deletions packages/@react-aria/dnd/stories/VirtualizedListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export function VirtualizedListBoxExample(props) {
for (let item of e.items) {
if (item.kind === 'text') {
let type: string;
if (props.accept) {
if (item.types.has(props.accept)) {
type = props.accept;
}
} else if (item.types.has('folder')) {
if (props.accept && item.types.has(props.accept)) {
type = props.accept;
} else if (!props.accept && item.types.has('folder')) {
type = 'folder';
} else if (item.types.has('item')) {
} else if (!props.accept && item.types.has('item')) {
type = 'item';
}

Expand Down
5 changes: 3 additions & 2 deletions packages/@react-aria/focus/src/useFocusable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import {FocusableDOMProps, FocusableProps} from '@react-types/shared';
import {mergeProps, useSyncRef} from '@react-aria/utils';
import React, {HTMLAttributes, MutableRefObject, ReactNode, RefObject, useContext, useEffect} from 'react';
import React, {HTMLAttributes, MutableRefObject, ReactNode, RefObject, useContext, useEffect, useMemo} from 'react';
import {useFocus, useKeyboard} from '@react-aria/interactions';

interface FocusableOptions extends FocusableProps, FocusableDOMProps {
Expand All @@ -32,7 +32,8 @@ interface FocusableContextValue extends FocusableProviderProps {
let FocusableContext = React.createContext<FocusableContextValue>(null);

function useFocusableContext(ref: RefObject<HTMLElement>): FocusableContextValue {
let context = useContext(FocusableContext) || {};
let context = useContext(FocusableContext);
context = useMemo(() => context || {}, [context]);
useSyncRef(context, ref);

return context;
Expand Down
1 change: 1 addition & 0 deletions packages/@react-aria/interactions/src/useFocusVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,6 @@ export function useFocusVisibleListener(fn: FocusVisibleHandler, deps: ReadonlyA
};
changeHandlers.add(handler);
return () => changeHandlers.delete(handler);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}
2 changes: 1 addition & 1 deletion packages/@react-aria/interactions/src/useHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function useHover(props: HoverProps): HoverResult {
if (isDisabled) {
triggerHoverEnd({target: state.target}, state.pointerType);
}
}, [isDisabled]);
}, [triggerHoverEnd, isDisabled, state.target, state.pointerType]);

return {
hoverProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function useInteractOutside(props: InteractOutsideProps) {
document.removeEventListener('touchend', onTouchEnd, true);
};
}
}, [onInteractOutside, ref, state.ignoreEmulatedMouseEvents, state.isPointerDown, isDisabled]);
}, [onInteractOutside, ref, state, isDisabled, onInteractOutsideStart]);
}

function isValidEvent(event, ref) {
Expand Down
19 changes: 2 additions & 17 deletions packages/@react-aria/overlays/src/useOverlayPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,6 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
placement: undefined
});

let deps = [
shouldUpdatePosition,
placement,
overlayRef.current,
targetRef.current,
scrollRef.current,
containerPadding,
shouldFlip,
boundaryElement,
offset,
crossOffset,
isOpen,
direction
];

let updatePosition = useCallback(() => {
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) {
return;
Expand All @@ -120,10 +105,10 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
crossOffset
})
);
}, deps);
}, [shouldUpdatePosition, placement, overlayRef, targetRef, scrollRef, containerPadding, shouldFlip, boundaryElement, offset, crossOffset, isOpen, direction]);

// Update position when anything changes
useLayoutEffect(updatePosition, deps);
useLayoutEffect(updatePosition, [updatePosition]);

// Update position on window resize
useResize(updatePosition);
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/selection/src/useSelectableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
focusSafely(ref.current);
}
}
}, [ref, isFocused, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);
}, [ref, isFocused, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus, focus]);

// Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
// item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/ssr/src/SSRProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function useSSRSafeId(defaultId?: string): string {
console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');
}

return useMemo(() => defaultId || `react-aria-${ctx.prefix}-${++ctx.current}`, [defaultId]);
return useMemo(() => defaultId || `react-aria-${ctx.prefix}-${++ctx.current}`, [defaultId, ctx]);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/@react-aria/utils/src/useId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function useId(defaultId?: string): string {
let [value, setValue] = useState(defaultId);
let nextId = useRef(null);
// don't memo this, we want it new each render so that the Effects always run
// eslint-disable-next-line react-hooks/exhaustive-deps
let updateValue = (val) => {
if (!isRendering.current) {
setValue(val);
Expand Down
2 changes: 2 additions & 0 deletions packages/@react-aria/virtualizer/src/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ function ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {
return () => {
clearTimeout(state.scrollTimeout);
};
// We only need to cleanup state.scrollTimeout on unmount here, don't want to constantly clearTimeout by including state.scrollTimeout in dep array
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
ktabors marked this conversation as resolved.
Show resolved Hide resolved

let updateSize = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function useVisuallyHidden(props: VisuallyHiddenProps = {}): VisuallyHidd
} else {
return styles;
}
}, [isFocused]);
}, [isFocused, style]);

return {
visuallyHiddenProps: {
Expand Down
4 changes: 3 additions & 1 deletion packages/@react-spectrum/breadcrumbs/src/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ function Breadcrumbs<T>(props: SpectrumBreadcrumbsProps<T>, ref: DOMRef) {
yield computeVisibleItems(newVisibleItems);
}
});
// Don't need to include childArray.length in dep array cuz children is already in array
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [listRef, children, setVisibleItems, showRoot, isMultiline]);

useResizeObserver({ref: domRef, onResize: updateOverflow});

useLayoutEffect(updateOverflow, [children]);
useLayoutEffect(updateOverflow, [updateOverflow]);

let contents = childArray;
if (childArray.length > visibleItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import {action} from '@storybook/addon-actions';
import {Breadcrumbs} from '../';
import {Button} from '@react-spectrum/button';
import {ButtonGroup} from '@react-spectrum/buttongroup';
// import {Heading} from '@react-spectrum/text';
import {Item} from '@react-stately/collections';
import React from 'react';
Expand Down Expand Up @@ -136,6 +138,10 @@ storiesOf('Breadcrumbs', module)
<Item>Root</Item>
</Breadcrumbs>
)
)
.add(
ktabors marked this conversation as resolved.
Show resolved Hide resolved
'adding breadcrumbs',
() => <DynamicBreadcrumbs />
);

function render(props = {}) {
Expand Down Expand Up @@ -179,3 +185,44 @@ function renderMany(props = {}) {
</Breadcrumbs>
);
}

let folders = [
{id: 1, label: 'Home'},
{id: 2, label: 'Trendy'},
{id: 3, label: 'March 2020 Assets'}
];

let DynamicBreadcrumbs = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing the above Breadcrumb dep array changes

let [breadcrumbs, setBreadcrumbs] = React.useState(folders);
let addBreadcrumb = () => {
let newBreadcrumbs = [...breadcrumbs];
newBreadcrumbs.push({
id: breadcrumbs.length + 1,
label: `Breadcrumb ${breadcrumbs.length + 1}`
});

setBreadcrumbs(newBreadcrumbs);
};

let removeBreadcrumb = () => {
let newBreadcrumbs = [...breadcrumbs];
newBreadcrumbs.pop();
setBreadcrumbs(newBreadcrumbs);
};

return (
<div>
<Breadcrumbs>
{breadcrumbs.map(f => <Item key={f.id}>{f.label}</Item>)}
</Breadcrumbs>
<ButtonGroup marginEnd="30px">
<Button variant="secondary" onPress={() => addBreadcrumb()}>
Add Breadcrumb
</Button>
<Button variant="secondary" onPress={() => removeBreadcrumb()}>
Remove Breadcrumb
</Button>
</ButtonGroup>
</div>
);
};
4 changes: 3 additions & 1 deletion packages/@react-spectrum/buttongroup/src/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function ButtonGroup(props: SpectrumButtonGroupProps, ref: DOMRef<HTMLDivElement
yield computeHasOverflow();
});
}
// We need scale and children in dependency array since it will affect overflow calcuation
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [domRef, orientation, scale, setHasOverflow, children]);

// There are two main reasons we need to remeasure:
Expand All @@ -77,7 +79,7 @@ function ButtonGroup(props: SpectrumButtonGroupProps, ref: DOMRef<HTMLDivElement
let parent = useRef<HTMLElement>();
useEffect(() => {
parent.current = domRef.current.parentElement;
}, [domRef.current]);
}, [domRef]);
useResizeObserver({ref: parent, onResize: checkForOverflow});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function ButtonGroupWithRefs(props) {
button2: button2.current.UNSAFE_getDOMNode(),
button3: button3.current.UNSAFE_getDOMNode()
});
}, []);
}, [props]);
return (
<Provider theme={theme}>
<ButtonGroup ref={buttonGroup} data-testid={buttonGroupId} {...props}>
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/combobox/src/MobileComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {AriaButtonProps} from '@react-types/button';
import buttonStyles from '@adobe/spectrum-css-temp/components/button/vars.css';
import CheckmarkMedium from '@spectrum-icons/ui/CheckmarkMedium';
import ChevronDownMedium from '@spectrum-icons/ui/ChevronDownMedium';
import {classNames, unwrapDOMRef} from '@react-spectrum/utils';
import {classNames, useUnwrapDOMRef} from '@react-spectrum/utils';
import {ClearButton} from '@react-spectrum/button';
import {ComboBoxState, useComboBoxState} from '@react-stately/combobox';
import comboboxStyles from './combobox.css';
Expand Down Expand Up @@ -303,7 +303,7 @@ function ComboBoxTray(props: ComboBoxTrayProps) {
...props,
// completionMode,
keyboardDelegate: layout,
buttonRef: unwrapDOMRef(buttonRef),
buttonRef: useUnwrapDOMRef(buttonRef),
popoverRef: popoverRef,
listBoxRef,
inputRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ let customFilterItems = [
let CustomFilterComboBox = (props) => {
let {startsWith} = useFilter({sensitivity: 'base'});
let [filterValue, setFilterValue] = React.useState('');
let filteredItems = React.useMemo(() => customFilterItems.filter(item => startsWith(item.name, filterValue)), [props.items, filterValue, startsWith]);
let filteredItems = React.useMemo(() => customFilterItems.filter(item => startsWith(item.name, filterValue)), [filterValue, startsWith]);

return (
<ComboBox
Expand Down
7 changes: 4 additions & 3 deletions packages/@react-spectrum/dialog/src/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import {ActionButton} from '@react-spectrum/button';
import {classNames, SlotProvider, unwrapDOMRef, useDOMRef, useHasChild, useStyleProps} from '@react-spectrum/utils';
import {classNames, SlotProvider, useDOMRef, useHasChild, useStyleProps, useUnwrapDOMRef} from '@react-spectrum/utils';
import CrossLarge from '@spectrum-icons/ui/CrossLarge';
import {DialogContext, DialogContextValue} from './context';
import {DismissButton} from '@react-aria/overlays';
Expand Down Expand Up @@ -54,11 +54,12 @@ function Dialog(props: SpectrumDialogProps, ref: DOMRef) {

let domRef = useDOMRef(ref);
let gridRef = useRef();
let unwrappedGridRef = useUnwrapDOMRef(gridRef);
let sizeVariant = sizeMap[type] || sizeMap[size];
let {dialogProps, titleProps} = useDialog(mergeProps(contextProps, props), domRef);

let hasHeader = useHasChild(`.${styles['spectrum-Dialog-header']}`, unwrapDOMRef(gridRef));
let hasFooter = useHasChild(`.${styles['spectrum-Dialog-footer']}`, unwrapDOMRef(gridRef));
let hasHeader = useHasChild(`.${styles['spectrum-Dialog-header']}`, unwrappedGridRef);
let hasFooter = useHasChild(`.${styles['spectrum-Dialog-footer']}`, unwrappedGridRef);

let slots = {
hero: {UNSAFE_className: styles['spectrum-Dialog-hero']},
Expand Down
6 changes: 3 additions & 3 deletions packages/@react-spectrum/dialog/src/DialogTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overla
import {PressResponder} from '@react-aria/interactions';
import React, {Fragment, ReactElement, useEffect, useRef} from 'react';
import {SpectrumDialogClose, SpectrumDialogProps, SpectrumDialogTriggerProps} from '@react-types/dialog';
import {unwrapDOMRef, useMediaQuery} from '@react-spectrum/utils';
import {useMediaQuery, useUnwrapDOMRef} from '@react-spectrum/utils';
import {useOverlayPosition, useOverlayTrigger} from '@react-aria/overlays';

function DialogTrigger(props: SpectrumDialogTriggerProps) {
Expand Down Expand Up @@ -63,7 +63,7 @@ function DialogTrigger(props: SpectrumDialogTriggerProps) {
console.warn('A DialogTrigger unmounted while open. This is likely due to being placed within a trigger that unmounts or inside a conditional. Consider using a DialogContainer instead.');
}
};
}, []);
}, [type]);

if (type === 'popover') {
return (
Expand Down Expand Up @@ -148,7 +148,7 @@ function PopoverTrigger({state, targetRef, trigger, content, hideArrow, isKeyboa
let overlayRef = useRef<DOMRefValue<HTMLDivElement>>();
let {overlayProps: popoverProps, placement, arrowProps} = useOverlayPosition({
targetRef: targetRef || triggerRef,
overlayRef: unwrapDOMRef(overlayRef),
overlayRef: useUnwrapDOMRef(overlayRef),
placement: props.placement,
containerPadding: props.containerPadding,
offset: props.offset,
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/menu/src/MenuTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {classNames, unwrapDOMRef, useDOMRef, useIsMobileDevice} from '@react-spectrum/utils';
import {classNames, useDOMRef, useIsMobileDevice, useUnwrapDOMRef} from '@react-spectrum/utils';
import {DismissButton, useOverlayPosition} from '@react-aria/overlays';
import {DOMRef, DOMRefValue} from '@react-types/shared';
import {FocusScope} from '@react-aria/focus';
Expand Down Expand Up @@ -60,7 +60,7 @@ function MenuTrigger(props: SpectrumMenuTriggerProps, ref: DOMRef<HTMLElement>)
let isMobile = useIsMobileDevice();
let {overlayProps: positionProps, placement} = useOverlayPosition({
targetRef: menuTriggerRef,
overlayRef: unwrapDOMRef(menuPopoverRef),
overlayRef: useUnwrapDOMRef(menuPopoverRef),
scrollRef: menuRef,
placement: initialPlacement,
shouldFlip: shouldFlip,
Expand Down
Loading