Create codemod for addressing ESLint warnings (#10032)

This commit is contained in:
DS Boyce
2026-03-11 15:51:31 -07:00
committed by GitHub
parent 80429ec902
commit 1db01a09a8
240 changed files with 1560 additions and 1347 deletions
+14 -10
View File
@@ -1,25 +1,29 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
type StateContext = persisted.Schema['requireAltTextEnabled']
type SetContext = (v: persisted.Schema['requireAltTextEnabled']) => void
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
persisted.defaults.requireAltTextEnabled,
)
stateContext.displayName = 'AltTextRequiredStateContext'
const setContext = React.createContext<SetContext>(
const setContext = createContext<SetContext>(
(_: persisted.Schema['requireAltTextEnabled']) => {},
)
setContext.displayName = 'AltTextRequiredSetContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(
persisted.get('requireAltTextEnabled'),
)
const [state, setState] = useState(persisted.get('requireAltTextEnabled'))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(requireAltTextEnabled: persisted.Schema['requireAltTextEnabled']) => {
setState(requireAltTextEnabled)
persisted.write('requireAltTextEnabled', requireAltTextEnabled)
@@ -27,7 +31,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate(
'requireAltTextEnabled',
nextRequireAltTextEnabled => {
@@ -46,9 +50,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useRequireAltTextEnabled() {
return React.useContext(stateContext)
return useContext(stateContext)
}
export function useSetRequireAltTextEnabled() {
return React.useContext(setContext)
return useContext(setContext)
}
+14 -10
View File
@@ -1,23 +1,27 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
type StateContext = boolean
type SetContext = (v: boolean) => void
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
Boolean(persisted.defaults.disableAutoplay),
)
stateContext.displayName = 'AutoplayStateContext'
const setContext = React.createContext<SetContext>((_: boolean) => {})
const setContext = createContext<SetContext>((_: boolean) => {})
setContext.displayName = 'AutoplaySetContext'
export function Provider({children}: {children: React.ReactNode}) {
const [state, setState] = React.useState(
Boolean(persisted.get('disableAutoplay')),
)
const [state, setState] = useState(Boolean(persisted.get('disableAutoplay')))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(autoplayDisabled: persisted.Schema['disableAutoplay']) => {
setState(Boolean(autoplayDisabled))
persisted.write('disableAutoplay', autoplayDisabled)
@@ -25,7 +29,7 @@ export function Provider({children}: {children: React.ReactNode}) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('disableAutoplay', nextDisableAutoplay => {
setState(Boolean(nextDisableAutoplay))
})
@@ -40,5 +44,5 @@ export function Provider({children}: {children: React.ReactNode}) {
)
}
export const useAutoplayDisabled = () => React.useContext(stateContext)
export const useSetAutoplayDisabled = () => React.useContext(setContext)
export const useAutoplayDisabled = () => useContext(stateContext)
export const useSetAutoplayDisabled = () => useContext(setContext)
+14 -10
View File
@@ -1,23 +1,27 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
type StateContext = boolean
type SetContext = (v: boolean) => void
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
Boolean(persisted.defaults.disableHaptics),
)
stateContext.displayName = 'DisableHapticsStateContext'
const setContext = React.createContext<SetContext>((_: boolean) => {})
const setContext = createContext<SetContext>((_: boolean) => {})
setContext.displayName = 'DisableHapticsSetContext'
export function Provider({children}: {children: React.ReactNode}) {
const [state, setState] = React.useState(
Boolean(persisted.get('disableHaptics')),
)
const [state, setState] = useState(Boolean(persisted.get('disableHaptics')))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(hapticsEnabled: persisted.Schema['disableHaptics']) => {
setState(Boolean(hapticsEnabled))
persisted.write('disableHaptics', hapticsEnabled)
@@ -25,7 +29,7 @@ export function Provider({children}: {children: React.ReactNode}) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('disableHaptics', nextDisableHaptics => {
setState(Boolean(nextDisableHaptics))
})
@@ -40,5 +44,5 @@ export function Provider({children}: {children: React.ReactNode}) {
)
}
export const useHapticsDisabled = () => React.useContext(stateContext)
export const useSetHapticsDisabled = () => React.useContext(setContext)
export const useHapticsDisabled = () => useContext(stateContext)
export const useSetHapticsDisabled = () => useContext(setContext)
@@ -1,4 +1,10 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import {type EmbedPlayerSource} from '#/lib/strings/embed-player'
import * as persisted from '#/state/persisted'
@@ -9,17 +15,17 @@ type SetContext = (
value: 'show' | 'hide' | undefined,
) => void
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
persisted.defaults.externalEmbeds,
)
stateContext.displayName = 'ExternalEmbedsPrefsStateContext'
const setContext = React.createContext<SetContext>({} as SetContext)
const setContext = createContext<SetContext>({} as SetContext)
setContext.displayName = 'ExternalEmbedsPrefsSetContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(persisted.get('externalEmbeds'))
const [state, setState] = useState(persisted.get('externalEmbeds'))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(source: EmbedPlayerSource, value: 'show' | 'hide' | undefined) => {
setState(prev => {
persisted.write('externalEmbeds', {
@@ -36,7 +42,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('externalEmbeds', nextExternalEmbeds => {
setState(nextExternalEmbeds)
})
@@ -52,9 +58,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useExternalEmbedsPrefs() {
return React.useContext(stateContext)
return useContext(stateContext)
}
export function useSetExternalEmbedPref() {
return React.useContext(setContext)
return useContext(setContext)
}
+16 -11
View File
@@ -1,4 +1,11 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
@@ -11,20 +18,18 @@ type ApiContext = {
unhidePost: ({uri}: {uri: string}) => void
}
const stateContext = React.createContext<StateContext>(
persisted.defaults.hiddenPosts,
)
const stateContext = createContext<StateContext>(persisted.defaults.hiddenPosts)
stateContext.displayName = 'HiddenPostsStateContext'
const apiContext = React.createContext<ApiContext>({
const apiContext = createContext<ApiContext>({
hidePost: () => {},
unhidePost: () => {},
})
apiContext.displayName = 'HiddenPostsApiContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(persisted.get('hiddenPosts'))
const [state, setState] = useState(persisted.get('hiddenPosts'))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(fn: SetStateCb) => {
const s = fn(persisted.get('hiddenPosts'))
setState(s)
@@ -33,7 +38,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setState],
)
const api = React.useMemo(
const api = useMemo(
() => ({
hidePost: ({uri}: {uri: string}) => {
setStateWrapped(s => [...(s || []), uri])
@@ -45,7 +50,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setStateWrapped],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('hiddenPosts', nextHiddenPosts => {
setState(nextHiddenPosts)
})
@@ -59,9 +64,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useHiddenPosts() {
return React.useContext(stateContext)
return useContext(stateContext)
}
export function useHiddenPostsApi() {
return React.useContext(apiContext)
return useContext(apiContext)
}
+14 -8
View File
@@ -1,23 +1,29 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
type StateContext = persisted.Schema['useInAppBrowser']
type SetContext = (v: persisted.Schema['useInAppBrowser']) => void
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
persisted.defaults.useInAppBrowser,
)
stateContext.displayName = 'InAppBrowserStateContext'
const setContext = React.createContext<SetContext>(
const setContext = createContext<SetContext>(
(_: persisted.Schema['useInAppBrowser']) => {},
)
setContext.displayName = 'InAppBrowserSetContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(persisted.get('useInAppBrowser'))
const [state, setState] = useState(persisted.get('useInAppBrowser'))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(inAppBrowser: persisted.Schema['useInAppBrowser']) => {
setState(inAppBrowser)
persisted.write('useInAppBrowser', inAppBrowser)
@@ -25,7 +31,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('useInAppBrowser', nextUseInAppBrowser => {
setState(nextUseInAppBrowser)
})
@@ -41,9 +47,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useInAppBrowser() {
return React.useContext(stateContext)
return useContext(stateContext)
}
export function useSetInAppBrowser() {
return React.useContext(setContext)
return useContext(setContext)
}
-2
View File
@@ -1,5 +1,3 @@
import type React from 'react'
import {Provider as AltTextRequiredProvider} from './alt-text-required'
import {Provider as AutoplayProvider} from './autoplay'
import {Provider as DisableHapticsProvider} from './disable-haptics'
+13 -9
View File
@@ -1,19 +1,23 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
import {IS_WEB} from '#/env'
type StateContext = persisted.Schema['kawaii']
const stateContext = React.createContext<StateContext>(
persisted.defaults.kawaii,
)
const stateContext = createContext<StateContext>(persisted.defaults.kawaii)
stateContext.displayName = 'KawaiiStateContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(persisted.get('kawaii'))
const [state, setState] = useState(persisted.get('kawaii'))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(kawaii: persisted.Schema['kawaii']) => {
setState(kawaii)
persisted.write('kawaii', kawaii)
@@ -21,13 +25,13 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('kawaii', nextKawaii => {
setState(nextKawaii)
})
}, [setStateWrapped])
React.useEffect(() => {
useEffect(() => {
// dumb and stupid but it's web only so just refresh the page if you want to change it
if (IS_WEB) {
@@ -47,5 +51,5 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useKawaiiMode() {
return React.useContext(stateContext)
return useContext(stateContext)
}
+3 -3
View File
@@ -1,4 +1,4 @@
import React from 'react'
import {createContext, useContext} from 'react'
import {
type AppBskyLabelerDefs,
type InterpretedLabelValueDefinition,
@@ -11,7 +11,7 @@ interface StateContext {
labelers: AppBskyLabelerDefs.LabelerViewDetailed[]
}
const stateContext = React.createContext<StateContext>({
const stateContext = createContext<StateContext>({
labelDefs: {},
labelers: [],
})
@@ -23,5 +23,5 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useLabelDefinitions() {
return React.useContext(stateContext)
return useContext(stateContext)
}
+16 -9
View File
@@ -1,4 +1,11 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import {type AppLanguage} from '#/locale/languages'
import * as persisted from '#/state/persisted'
@@ -16,11 +23,11 @@ type ApiContext = {
setAppLanguage: (code2: AppLanguage) => void
}
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
persisted.defaults.languagePrefs,
)
stateContext.displayName = 'LanguagePrefsStateContext'
const apiContext = React.createContext<ApiContext>({
const apiContext = createContext<ApiContext>({
setPrimaryLanguage: (_: string) => {},
setPostLanguage: (_: string) => {},
setContentLanguages: (_: string[]) => {},
@@ -30,9 +37,9 @@ const apiContext = React.createContext<ApiContext>({
apiContext.displayName = 'LanguagePrefsApiContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(() => persisted.get('languagePrefs'))
const [state, setState] = useState(() => persisted.get('languagePrefs'))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(fn: SetStateCb) => {
const s = fn(persisted.get('languagePrefs'))
setState(s)
@@ -41,13 +48,13 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('languagePrefs', nextLanguagePrefs => {
setState(nextLanguagePrefs)
})
}, [setStateWrapped])
const api = React.useMemo(
const api = useMemo(
() => ({
setPrimaryLanguage(code2: string) {
setStateWrapped(s => ({...s, primaryLanguage: code2}))
@@ -102,11 +109,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useLanguagePrefs() {
return React.useContext(stateContext)
return useContext(stateContext)
}
export function useLanguagePrefsApi() {
return React.useContext(apiContext)
return useContext(apiContext)
}
export function getContentLanguages() {
+14 -10
View File
@@ -1,25 +1,29 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
type StateContext = persisted.Schema['largeAltBadgeEnabled']
type SetContext = (v: persisted.Schema['largeAltBadgeEnabled']) => void
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
persisted.defaults.largeAltBadgeEnabled,
)
stateContext.displayName = 'LargeAltBadgeStateContext'
const setContext = React.createContext<SetContext>(
const setContext = createContext<SetContext>(
(_: persisted.Schema['largeAltBadgeEnabled']) => {},
)
setContext.displayName = 'LargeAltBadgeSetContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(
persisted.get('largeAltBadgeEnabled'),
)
const [state, setState] = useState(persisted.get('largeAltBadgeEnabled'))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(largeAltBadgeEnabled: persisted.Schema['largeAltBadgeEnabled']) => {
setState(largeAltBadgeEnabled)
persisted.write('largeAltBadgeEnabled', largeAltBadgeEnabled)
@@ -27,7 +31,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate(
'largeAltBadgeEnabled',
nextLargeAltBadgeEnabled => {
@@ -46,9 +50,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useLargeAltBadgeEnabled() {
return React.useContext(stateContext)
return useContext(stateContext)
}
export function useSetLargeAltBadgeEnabled() {
return React.useContext(setContext)
return useContext(setContext)
}
+14 -10
View File
@@ -1,23 +1,27 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
type StateContext = boolean
type SetContext = (v: boolean) => void
const stateContext = React.createContext<StateContext>(
const stateContext = createContext<StateContext>(
Boolean(persisted.defaults.subtitlesEnabled),
)
stateContext.displayName = 'SubtitlesStateContext'
const setContext = React.createContext<SetContext>((_: boolean) => {})
const setContext = createContext<SetContext>((_: boolean) => {})
setContext.displayName = 'SubtitlesSetContext'
export function Provider({children}: {children: React.ReactNode}) {
const [state, setState] = React.useState(
Boolean(persisted.get('subtitlesEnabled')),
)
const [state, setState] = useState(Boolean(persisted.get('subtitlesEnabled')))
const setStateWrapped = React.useCallback(
const setStateWrapped = useCallback(
(subtitlesEnabled: persisted.Schema['subtitlesEnabled']) => {
setState(Boolean(subtitlesEnabled))
persisted.write('subtitlesEnabled', subtitlesEnabled)
@@ -25,7 +29,7 @@ export function Provider({children}: {children: React.ReactNode}) {
[setState],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate('subtitlesEnabled', nextSubtitlesEnabled => {
setState(Boolean(nextSubtitlesEnabled))
})
@@ -40,5 +44,5 @@ export function Provider({children}: {children: React.ReactNode}) {
)
}
export const useSubtitlesEnabled = () => React.useContext(stateContext)
export const useSetSubtitlesEnabled = () => React.useContext(setContext)
export const useSubtitlesEnabled = () => useContext(stateContext)
export const useSetSubtitlesEnabled = () => useContext(setContext)
+17 -10
View File
@@ -1,4 +1,11 @@
import React from 'react'
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import * as persisted from '#/state/persisted'
@@ -18,22 +25,22 @@ type ApiContext = {
): void
}
const StateContext = React.createContext<StateContext>({
const StateContext = createContext<StateContext>({
trendingDisabled: Boolean(persisted.defaults.trendingDisabled),
trendingVideoDisabled: Boolean(persisted.defaults.trendingVideoDisabled),
})
StateContext.displayName = 'TrendingStateContext'
const ApiContext = React.createContext<ApiContext>({
const ApiContext = createContext<ApiContext>({
setTrendingDisabled() {},
setTrendingVideoDisabled() {},
})
ApiContext.displayName = 'TrendingApiContext'
function usePersistedBooleanValue<T extends keyof persisted.Schema>(key: T) {
const [value, _set] = React.useState(() => {
const [value, _set] = useState(() => {
return Boolean(persisted.get(key))
})
const set = React.useCallback<
const set = useCallback<
(value: Exclude<persisted.Schema[T], undefined>) => void
>(
hidden => {
@@ -42,7 +49,7 @@ function usePersistedBooleanValue<T extends keyof persisted.Schema>(key: T) {
},
[key, _set],
)
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate(key, hidden => {
_set(Boolean(hidden))
})
@@ -60,11 +67,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
/*
* Context
*/
const state = React.useMemo(
const state = useMemo(
() => ({trendingDisabled, trendingVideoDisabled}),
[trendingDisabled, trendingVideoDisabled],
)
const api = React.useMemo(
const api = useMemo(
() => ({setTrendingDisabled, setTrendingVideoDisabled}),
[setTrendingDisabled, setTrendingVideoDisabled],
)
@@ -77,9 +84,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}
export function useTrendingSettings() {
return React.useContext(StateContext)
return useContext(StateContext)
}
export function useTrendingSettingsApi() {
return React.useContext(ApiContext)
return useContext(ApiContext)
}
+7 -7
View File
@@ -1,17 +1,17 @@
import React from 'react'
import {createContext, useContext, useEffect, useState} from 'react'
import * as persisted from '#/state/persisted'
type StateContext = boolean | undefined
type SetContext = (v: boolean) => void
const stateContext = React.createContext<StateContext>(false)
const stateContext = createContext<StateContext>(false)
stateContext.displayName = 'UsedStarterPacksStateContext'
const setContext = React.createContext<SetContext>((_: boolean) => {})
const setContext = createContext<SetContext>((_: boolean) => {})
setContext.displayName = 'UsedStarterPacksSetContext'
export function Provider({children}: {children: React.ReactNode}) {
const [state, setState] = React.useState<StateContext>(() =>
const [state, setState] = useState<StateContext>(() =>
persisted.get('hasCheckedForStarterPack'),
)
@@ -20,7 +20,7 @@ export function Provider({children}: {children: React.ReactNode}) {
persisted.write('hasCheckedForStarterPack', v)
}
React.useEffect(() => {
useEffect(() => {
return persisted.onUpdate(
'hasCheckedForStarterPack',
nextHasCheckedForStarterPack => {
@@ -38,5 +38,5 @@ export function Provider({children}: {children: React.ReactNode}) {
)
}
export const useHasCheckedForStarterPack = () => React.useContext(stateContext)
export const useSetHasCheckedForStarterPack = () => React.useContext(setContext)
export const useHasCheckedForStarterPack = () => useContext(stateContext)
export const useSetHasCheckedForStarterPack = () => useContext(setContext)