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

Clean up all lint warnings #1199

wants to merge 30 commits into from

Conversation

snowystinger
Copy link
Member

Our lint warnings are getting away from us, this is a start to clean that up so that we can catch meaningful problems.
Add comments explaining why some are disabled/not needed

Closes

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

Comment on lines 36 to 37
let stableEmptyObject = useRef({});
let parentSlots = useContext(SlotContext) || stableEmptyObject.current;
Copy link
Member

Choose a reason for hiding this comment

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

Mind giving me the rundown on this change? Any particular reason for going with this approach rather than moving parentSlots into the useMemo below?

Copy link
Member Author

@snowystinger snowystinger Nov 4, 2020

Choose a reason for hiding this comment

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

you mean like this instead?

  let parentSlots = useContext(SlotContext);
  let {slots = {}, children} = props;

  // Merge props for each slot from parent context and props
  let value = useMemo(() => {
    let slotObj = parentSlots || {}
    Object.keys(slotObj)
      .concat(Object.keys(slots))
      .reduce((o, p) => ({
        ...o,
        [p]: mergeProps(slotObj[p]) || {}, slots[p] || {})}), {})
      , [parentSlots, slots]);

I'm fine doing that too, it's probably slightly better

Copy link
Member Author

Choose a reason for hiding this comment

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

so I tried that, and broke like every test... I'm not sure what went wrong, so sticking with stableEmptyObject for the moment

Copy link
Member

Choose a reason for hiding this comment

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

Why is stableEmptyObject used instead of {}? things like that make me nervous that something more important is wrong.

ktabors
ktabors previously approved these changes Nov 11, 2020
Copy link
Member

@ktabors ktabors left a comment

Choose a reason for hiding this comment

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

LGTM

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

}, deps);

// Update position when anything changes
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Member Author

Choose a reason for hiding this comment

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

Out of curiosity, is it just not checking in deps? or is deps actually missing some?
Lets add a comment when we // disable so that we know why we're ignoring it. It looks like you've started doing that a bit, so that's good. We should make sure every disable of this rule has an explanation

Copy link
Member

Choose a reason for hiding this comment

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

For this one, the linter states " React Hook useCallback was passed a dependency list that is not an array literal" and I tried facebook/react#14476 (comment) w/ the JSON.stringify but it broke a lot of stuff so I opted for disabling it. I'll go ahead and put an explanation though, good idea

Copy link
Member

Choose a reason for hiding this comment

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

actually, looking at it again maybe I can do away with the dep array since the useEffect below can have a dep on updatePosition

also changed useDomRef to use useUnwrapDOMRef so that it does not infinite loop
@adobe-bot
Copy link

Build successful! 🎉

@@ -65,8 +67,8 @@ const ComboBoxBase = React.forwardRef(function ComboBoxBase<T extends object>(pr
{
...props,
keyboardDelegate: layout,
buttonRef: unwrapDOMRef(buttonRef),
popoverRef: unwrapDOMRef(popoverRef),
buttonRef: unwrappedButtonRef,
Copy link
Member Author

Choose a reason for hiding this comment

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

I think these changes are going to conflict with #1333

Copy link
Member

Choose a reason for hiding this comment

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

yep, I pulled the combobox and picker ones from your PR so hopefully it won't be too bad

not entirely sure why props.children is still needed in context useMemo
.eslintrc.js Outdated
@@ -112,7 +112,7 @@ module.exports = {
'space-in-parens': [ERROR, 'never'],
'space-unary-ops': [ERROR, {words: true, nonwords: false}],
'spaced-comment': [ERROR, 'always', {exceptions: ['*'], markers: ['/']}],
'max-depth': [WARN, 4],
'max-depth': [WARN, 5],
Copy link
Member

Choose a reason for hiding this comment

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

bumped this up since there is some deep logic in TableCollection

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm.... i don't like bumping this up, it makes it easier to write that kind of code, how many problem spots are there? can we comment them? or can we pull out any of it to reduce the depth?

Copy link
Member

Choose a reason for hiding this comment

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

luckily there are only two instances I believe, I'll suppress the warning for them for now

{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

Comment on lines 54 to 56
// Props.children is required here in case new rows are added/removed
// eslint-disable-next-line react-hooks/exhaustive-deps
}), [props.children, props.showSelectionCheckboxes, selectionState.selectionMode]);
Copy link
Member

Choose a reason for hiding this comment

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

This one I'm kinda puzzled about since it doesn't look like context has any reliance on props.children and useCollection already has props.children in it's useMemo, but removing it broke adding rows in the CRUD example

Copy link
Member Author

Choose a reason for hiding this comment

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

I think @devongovett wrote the answer to this at one point in the slack channel but i can't find it. or maybe it was an old comment in a PR. Maybe he'll remember

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

ktabors
ktabors previously approved these changes Jul 14, 2021
Copy link
Member

@ktabors ktabors left a comment

Choose a reason for hiding this comment

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

LGTM

# Conflicts:
#	packages/@react-aria/focus/src/useFocusable.tsx
#	packages/@react-aria/interactions/src/useInteractOutside.ts
#	packages/@react-spectrum/utils/src/Slots.tsx
@adobe-bot
Copy link

Build successful! 🎉

ktabors
ktabors previously approved these changes Sep 21, 2021
@adobe-bot
Copy link

Build successful! 🎉

@snowystinger snowystinger changed the title Clean up a few lint warnings Clean up all lint warnings Sep 21, 2021
Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

Looks like there were 3 more to fix after with the latest update:

react-spectrum/packages/@react-spectrum/cards/src/CardBase.tsx

  • 78:6 warning React Hook useLayoutEffect has a missing dependency: 'orientation'. Either include it or remove the dependency array react-hooks/exhaustive-deps
  • 97:7 warning React Hook useMemo has a missing dependency: 'aspectRatioEnforce'. Either include it or remove the dependency array react-hooks/exhaustive-deps

react-spectrum/packages/@react-spectrum/dialog/src/Dialog.tsx

  • 73:7 warning React Hook useMemo has an unnecessary dependency: 'styles'. Either exclude it or remove the dependency array. Outer scope values like 'styles' aren't valid dependencies because mutating them doesn't re-render the component react-hooks/exhaustive-deps

@LFDanLu
Copy link
Member

LFDanLu commented Sep 21, 2021

Cleaned up the new lint warnings, thanks @reidbarber for catching those. The orientation one is handled #2362

@@ -94,7 +94,7 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
actionmenu: {UNSAFE_className: classNames(styles, 'spectrum-Card-actions'), align: 'end', isQuiet: true},
footer: {UNSAFE_className: classNames(styles, 'spectrum-Card-footer'), isHidden: isQuiet},
divider: {UNSAFE_className: classNames(styles, 'spectrum-Card-divider'), size: 'S'}
}), [titleProps, contentProps, height, isQuiet, orientation]);
}), [titleProps, contentProps, height, isQuiet, orientation, aspectRatioEnforce]);
Copy link
Member Author

Choose a reason for hiding this comment

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

This one isn't quite right, aspectRatioEnforce isn't a memoized value, I'll go make a commit to address that

Copy link
Member

Choose a reason for hiding this comment

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

Ah, thanks for catching that

# Conflicts:
#	packages/@react-spectrum/cards/src/CardBase.tsx
@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

LFDanLu
LFDanLu previously approved these changes Sep 23, 2021
@adobe-bot
Copy link

Build successful! 🎉

two failing tests will need looking into, in Table.test
# Conflicts:
#	packages/@react-aria/interactions/src/useFocusVisible.ts
#	packages/@react-aria/overlays/src/useOverlayPosition.ts
#	packages/@react-spectrum/card/src/CardBase.tsx
#	packages/@react-spectrum/tabs/src/Tabs.tsx
@reidbarber reidbarber mentioned this pull request Oct 7, 2022
5 tasks
@snowystinger
Copy link
Member Author

closing due to #3612

@snowystinger snowystinger deleted the clean-up-lint-warnings branch October 14, 2022 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants