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

chore(linting): Add react-hooks eslint rules #18208

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 @@ -59,6 +60,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 @@ -252,6 +255,12 @@ module.exports = {
node: true,
},
},
{
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
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 @@ -62,6 +64,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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const EventsFree: StoryFn<typeof TaxonomicFilter> = (args) => {
// Highlight the second item, as the first one is "All events", which doesn't have a definition to show
// - we do want to show the definition popover here too
setIndex(1)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<div className="w-fit border rounded p-2 bg-bg-light">
Expand Down Expand Up @@ -66,6 +68,8 @@ export const Actions: StoryFn<typeof TaxonomicFilter> = (args) => {
// Highlight the second item, as the first one is "All events", which doesn't have a definition to show
// - we do want to show the definition popover here too
setIndex(0)
// FIXME
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<div className="w-fit border rounded p-2 bg-white">
Expand Down
Loading
Loading