Skip to content

Commit

Permalink
Add react-hooks eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Oct 26, 2023
1 parent 4c0a619 commit 4f09431
Show file tree
Hide file tree
Showing 147 changed files with 431 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:eslint-comments/recommended',
'plugin:storybook/recommended',
'prettier',
Expand Down Expand Up @@ -53,6 +54,8 @@ module.exports = {
html: true,
},
],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
Expand Down Expand Up @@ -236,6 +239,12 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['*Type.ts'],
rules: {
'no-restricted-imports': 'off',
},
},
],
reportUnusedDisableDirectives: true,
}
2 changes: 2 additions & 0 deletions frontend/src/layout/FeaturePreviews/FeaturePreviewsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function FeaturePreviewsModal({
useValues(featurePreviewsLogic)
const { hideFeaturePreviewsModal, loadEarlyAccessFeatures } = useActions(featurePreviewsLogic)

// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
useLayoutEffect(() => loadEarlyAccessFeatures(), [])

return (
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/layout/navigation-3000/Navigation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export function LightMode(): JSX.Element {
useEffect(() => {
router.actions.push(urls.projectHomepage())
overrideTheme(false)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return <App />
Expand All @@ -45,6 +47,8 @@ export function DarkMode(): JSX.Element {
useEffect(() => {
router.actions.push(urls.projectHomepage())
overrideTheme(true)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return <App />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export function Dashboards(): JSX.Element {
const { activeNavbarItem } = useValues(navigation3000Logic)
useEffect(() => {
showSidebar(Scene.Dashboards) // Active this sidebar
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return (
Expand All @@ -61,6 +63,8 @@ export function FeatureFlags(): JSX.Element {
const { activeNavbarItem } = useValues(navigation3000Logic)
useEffect(() => {
showSidebar(Scene.FeatureFlags) // Activate this sidebar
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return (
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/layout/navigation/Navigation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export function AppPageWithSideBarHidden(): JSX.Element {
useEffect(() => {
toggleSideBarBase(false)
toggleSideBarMobile(false)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return <BaseAppPage />
Expand All @@ -84,6 +86,8 @@ export function AppPageWithSideBarShown(): JSX.Element {
useEffect(() => {
toggleSideBarBase(true)
toggleSideBarMobile(true)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return <BaseAppPage />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ async function testSetup(
scope: ActivityScope,
url: string
): Promise<ReturnType<typeof activityLogLogic.build>> {
// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
useMocks({
get: {
[url]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ export function useAnnotationsPositioning(
firstTickLeftPx: 0,
}
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [chart, chartWidth, chartHeight])
}
2 changes: 2 additions & 0 deletions frontend/src/lib/components/BillingAlertsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function BillingAlertsV2(): JSX.Element | null {
if (billingAlert) {
reportBillingAlertShown(billingAlert)
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [billingAlert])

if (!billingAlert || alertHidden) {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/Cards/CardMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export function CardMeta({

useEffect(() => {
setPrimaryHeight?.(primaryHeight)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [primaryHeight])

const foldedHeight = `calc(${primaryHeight}px ${
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ export function FilterBasedCardContent({
) {
window.dispatchEvent(new Event('resize'))
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [style?.height])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,23 @@ export function ControlledDefinitionPopover({
return null
}

// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
const { state, singularType, isElement, definition } = useValues(definitionPopoverLogic)
// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
const { setDefinition } = useActions(definitionPopoverLogic)

const icon = group.getIcon?.(definition || item)

// Must use `useEffect` here to hydrate popover card with the newest item, since lifecycle of `ItemPopover` is controlled
// independently by `infiniteListLogic`
// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
setDefinition(item)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [item])

return (
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/lib/components/EditableField/EditableField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,16 @@ const AutosizeInput = ({

const inputStyles = useMemo(() => {
return inputRef.current ? window.getComputedStyle(inputRef.current) : null
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [inputRef.current])

useLayoutEffect(() => {
if (inputStyles && placeHolderSizerRef.current) {
copyStyles(inputStyles, placeHolderSizerRef.current)
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [placeHolderSizerRef, placeHolderSizerRef])

useLayoutEffect(() => {
Expand All @@ -291,6 +295,8 @@ const AutosizeInput = ({
if (newInputWidth !== inputWidth) {
setInputWidth(newInputWidth)
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sizerRef.current, placeHolderSizerRef.current, placeholder, value])

return (
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/ExportButton/exporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ function DelayedContent({ atStart, afterDelay }: DelayedContentProps): JSX.Eleme
setTimeout(() => {
setContent(afterDelay)
}, 30000)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return <>{content}</>
}
2 changes: 2 additions & 0 deletions frontend/src/lib/components/FullScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export function FullScreen({ onExit }: { onExit?: () => any }): null {
// will break on IE11
}
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return null
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/lib/components/HedgehogBuddy/HedgehogBuddy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ export function HedgehogBuddy({

useEffect(() => {
return actor.setupKeyboardListeners()
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -422,10 +424,14 @@ export function HedgehogBuddy({

useEffect(() => {
actor.accessories = accessories
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [accessories])

useEffect(() => {
actor.darkMode = isDarkModeOn
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isDarkModeOn])

useEffect(() => {
Expand All @@ -441,6 +447,8 @@ export function HedgehogBuddy({
return () => {
clearTimeout(timer)
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useEffect(() => {
Expand All @@ -455,6 +463,8 @@ export function HedgehogBuddy({

useEffect(() => {
onPositionChange?.(actor)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actor.x, actor.y])

const onClick = (): void => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export function MapComponent({ center, markers, className, mapLibreStyleUrl }: M
marker.addTo(map.current)
}
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useResizeObserver({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export function PropertiesTable({
)
}

// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
const objectProperties = useMemo(() => {
if (!properties || !(properties instanceof Object)) {
return []
Expand Down Expand Up @@ -243,6 +245,8 @@ export function PropertiesTable({
})
}
return entries
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [properties, sortProperties, searchTerm, filtered])

if (properties instanceof Object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export function PathItemFilters({
if (propertyFilters && !objectsEqual(propertyFilters, filtersWithNew)) {
setFilters([...propertyFilters, {} as EmptyPropertyFilter])
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [propertyFilters])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export function PropertyFilters({
// Update the logic's internal filters when the props change
useEffect(() => {
setFilters(propertyFilters ?? [])
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [propertyFilters])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export function OperatorValueSelect({
} else if (limitedElementProperty && !operators.includes(currentOperator)) {
setCurrentOperator(PropertyOperator.Exact)
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [propertyDefinition, propkey, operator])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export function PropertyValue({
setInput(toString(value))
}
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value])

const load = (newInput: string | undefined): void => {
Expand All @@ -94,6 +96,8 @@ export function PropertyValue({

useEffect(() => {
load('')
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [propertyKey])

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/ResizableTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export function ResizableTable<RecordType extends Record<any, any> = any>({
updateScrollGradient()
setHeaderShouldRender(true)
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return (
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/RestrictedArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export function RestrictedArea({
)}s and up. Your level is ${membershipLevelToName.get(scopeAccessLevel)}.`
}
return null
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentOrganization])

return restrictionReason ? (
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/StickyView/StickyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export function StickyView({ children, top = '0px', marginTop = 0 }: StickyViewP
window.addEventListener('scroll', onScroll)

return () => window.removeEventListener('scroll', onScroll)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fixed])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export function EditSubscription({
if (subscription?.target_type === 'slack' && slackIntegration) {
loadSlackChannels()
}
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [subscription?.target_type, slackIntegration])

// If slackChannels aren't loaded, make sure we display only the channel name and not the actual underlying value
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/components/Support/SupportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ export function SupportModal({ loggedIn = true }: { loggedIn?: boolean }): JSX.E
}
return null
}
// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
const dropRef = useRef<HTMLDivElement>(null)

// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
const { setFilesToUpload, filesToUpload, uploading } = useUploadFiles({
onUpload: (url, fileName) => {
setSendSupportRequestValue('message', sendSupportRequest.message + `\n\nAttachment "${fileName}": ${url}`)
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/components/TZLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const TZLabelPopoverContent = React.memo(function TZLabelPopoverContent({

useEffect(() => {
reportTimezoneComponentViewed('label', currentTeam?.timezone, shortTimeZone())
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return (
Expand Down Expand Up @@ -106,6 +108,8 @@ function TZLabelRaw({
}
}, 1000)
return () => clearInterval(interval)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [parsedTime, format])

const innerContent = (
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export function createdAtColumn<T extends Record<string, any> = Record<string, a
}

export function createdByColumn<T extends Record<string, any> = Record<string, any>>(items: T[]): ColumnType<T> {
// FIXME
// eslint-disable-next-line react-hooks/rules-of-hooks
const { user } = useValues(userLogic)
return {
title: normalizeColumnTitle('Created by'),
Expand Down
Loading

0 comments on commit 4f09431

Please sign in to comment.