TypeScript
chore(lint): reject use* functions that call no hooks (#21260)
Julius Marminge92224ddfa282
diff --git a/apps/mobile/src/features/files/FileMarkdownPreview.tsx b/apps/mobile/src/features/files/FileMarkdownPreview.tsxindex 039352ad627..f2c30e59f12 100644--- a/apps/mobile/src/features/files/FileMarkdownPreview.tsx+++ b/apps/mobile/src/features/files/FileMarkdownPreview.tsx@@ -5,7 +5,7 @@ import { useCallback, useMemo, useState } from "react";import { RefreshControl, ScrollView, View } from "react-native";import { tryOpenExternalUrl } from "../../lib/openExternalUrl";-import { useFontFamily } from "../../lib/useFontFamily";+import { FONT_FAMILIES } from "../../lib/fontFamilies";import { resolveNativeMarkdownTypography } from "../../lib/appearancePreferences";import { useUniwindTheme } from "../../lib/useUniwindTheme";import {@@ -45,8 +45,8 @@ export function useMarkdownPreviewStyles(): MarkdownPreviewStyles {const codeBackground = theme["--color-md-code-bg"];const codeText = theme["--color-md-code-text"];const horizontalRule = theme["--color-md-hr"];- const regularFontFamily = useFontFamily("regular");- const boldFontFamily = useFontFamily("bold");+ const regularFontFamily = FONT_FAMILIES.regular;+ const boldFontFamily = FONT_FAMILIES.bold;return useMemo(() => {return {diff --git a/apps/mobile/src/features/review/useReviewHeaderPresentation.android.ts b/apps/mobile/src/features/review/useReviewHeaderPresentation.android.tsindex 914b3545b86..294ee0e7cfc 100644--- a/apps/mobile/src/features/review/useReviewHeaderPresentation.android.ts+++ b/apps/mobile/src/features/review/useReviewHeaderPresentation.android.ts@@ -1,5 +1,6 @@import type { useReviewHeaderPresentation as useIosReviewHeaderPresentation } from "./useReviewHeaderPresentation";+// oxlint-disable-next-line t3code/no-hookless-use-function -- Android stub of a hook; the iOS file calls hooks.export function useReviewHeaderPresentation(props: Parameters<typeof useIosReviewHeaderPresentation>[0],): ReturnType<typeof useIosReviewHeaderPresentation> {diff --git a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsxindex 915d69fbeb5..02a20015435 100644--- a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx+++ b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx@@ -28,7 +28,7 @@ import {import Animated from "react-native-reanimated";import { useSafeAreaInsets } from "react-native-safe-area-context";import { useUniwindTheme } from "../../lib/useUniwindTheme";-import { useFontFamily } from "../../lib/useFontFamily";+import { FONT_FAMILIES } from "../../lib/fontFamilies";import {AuthOrchestrationOperateScope,PROVIDER_SEND_TURN_MAX_ATTACHMENTS,@@ -641,7 +641,7 @@ export function NewTaskDraftScreen(props: {const theme = useUniwindTheme();const foregroundColor = theme["--color-foreground"];- const regularFontFamily = useFontFamily("regular");+ const regularFontFamily = FONT_FAMILIES.regular;const bodyText = useScaledTextRole("body");const lastInitialProjectRefRef = useRef(props.initialProjectRef);diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsxindex 762685e2f83..2a43d6794b2 100644--- a/apps/mobile/src/features/threads/ThreadFeed.tsx+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx@@ -112,7 +112,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";import Animated, { FadeIn, FadeInUp, type SharedValue } from "react-native-reanimated";import { useUniwindTheme } from "../../lib/useUniwindTheme";import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics";-import { useFontFamily } from "../../lib/useFontFamily";+import { FONT_FAMILIES } from "../../lib/fontFamilies";import { scopedThreadKey } from "../../lib/scopedEntities";import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";import { tryOpenExternalUrl } from "../../lib/openExternalUrl";@@ -861,8 +861,8 @@ function useMarkdownStyles(): MarkdownStyleSets {const markdownUserFenceBg = theme["--color-md-user-fence-bg"];const inlineSkillForeground = theme["--color-inline-skill-foreground"];const userBubbleSkillForeground = theme["--color-user-bubble-skill-foreground"];- const regularFontFamily = useFontFamily("regular");- const boldFontFamily = useFontFamily("bold");+ const regularFontFamily = FONT_FAMILIES.regular;+ const boldFontFamily = FONT_FAMILIES.bold;return useMemo(() => {return {diff --git a/apps/mobile/src/features/threads/ThreadGitControls.android.tsx b/apps/mobile/src/features/threads/ThreadGitControls.android.tsxindex 718513201cd..4ec85db2eeb 100644--- a/apps/mobile/src/features/threads/ThreadGitControls.android.tsx+++ b/apps/mobile/src/features/threads/ThreadGitControls.android.tsx@@ -9,10 +9,12 @@ export type { ThreadGitMenuProps } from "./ThreadGitControls";type ThreadGitControlsProps = Parameters<typeof IosThreadGitControls>[0];const EMPTY_HEADER_ITEMS: ReturnType<typeof useIosThreadGitRightHeaderItems> = [];+// oxlint-disable-next-line t3code/no-hookless-use-function -- Android stub of a hook; the iOS file calls hooks.export function useThreadGitRightHeaderItems(_props: ThreadGitControlsProps) {return EMPTY_HEADER_ITEMS;}+// oxlint-disable-next-line t3code/no-hookless-use-function -- Android stub of a hook; the iOS file calls hooks.export function useThreadGitCenterHeaderItems(_props: ThreadGitControlsProps) {return EMPTY_HEADER_ITEMS;}@@ -25,6 +27,7 @@ export function ThreadGitMenu(_props: Parameters<typeof IosThreadGitMenu>[0]) {return null;}+// oxlint-disable-next-line t3code/no-hookless-use-function -- Android stub of a hook; the iOS file calls hooks.export function useThreadGitMenuDefinition(_props: Parameters<typeof IosThreadGitMenu>[0]) {return null;}diff --git a/apps/mobile/src/features/threads/useThreadHeaderOptions.android.ts b/apps/mobile/src/features/threads/useThreadHeaderOptions.android.tsindex 40594d45c13..263852f87b1 100644--- a/apps/mobile/src/features/threads/useThreadHeaderOptions.android.ts+++ b/apps/mobile/src/features/threads/useThreadHeaderOptions.android.ts@@ -1,5 +1,6 @@import type { useThreadHeaderOptions as useIosThreadHeaderOptions } from "./useThreadHeaderOptions";+// oxlint-disable-next-line t3code/no-hookless-use-function -- Android stub of a hook; the iOS file calls hooks.export function useThreadHeaderOptions(props: Parameters<typeof useIosThreadHeaderOptions>[0],): ReturnType<typeof useIosThreadHeaderOptions> {diff --git a/apps/mobile/src/lib/fontFamilies.ts b/apps/mobile/src/lib/fontFamilies.tsnew file mode 100644index 00000000000..38602ec7c98--- /dev/null+++ b/apps/mobile/src/lib/fontFamilies.ts@@ -0,0 +1,5 @@+export const FONT_FAMILIES = {+ regular: "DMSans-Regular",+ medium: "DMSans-Medium",+ bold: "DMSans-Bold",+} as const;diff --git a/apps/mobile/src/lib/useFontFamily.ts b/apps/mobile/src/lib/useFontFamily.tsdeleted file mode 100644index f6c63388961..00000000000--- a/apps/mobile/src/lib/useFontFamily.ts+++ /dev/null@@ -1,9 +0,0 @@-const FONT_FAMILIES = {- regular: "DMSans-Regular",- medium: "DMSans-Medium",- bold: "DMSans-Bold",-} as const;--export function useFontFamily(weight: keyof typeof FONT_FAMILIES): string {- return FONT_FAMILIES[weight];-}diff --git a/apps/mobile/src/native/NativeWorkspaceColumns.tsx b/apps/mobile/src/native/NativeWorkspaceColumns.tsxindex ef4b22e4c7b..e0eace5dbc3 100644--- a/apps/mobile/src/native/NativeWorkspaceColumns.tsx+++ b/apps/mobile/src/native/NativeWorkspaceColumns.tsx@@ -1,10 +1,12 @@import { Platform } from "react-native";export const NATIVE_WORKSPACE_COLUMNS_SUPPORTED = Platform.OS === "ios" && Platform.isPad;+// oxlint-disable-next-line t3code/no-hookless-use-function -- Non-iOS stub of a hook; the .ios.tsx file calls hooks.export function useNativeWorkspaceColumnsReady() {return true;}+// oxlint-disable-next-line t3code/no-hookless-use-function -- Non-iOS stub of a hook; the .ios.tsx file calls hooks.export function useNativeWorkspaceColumnsSupported() {return NATIVE_WORKSPACE_COLUMNS_SUPPORTED;}diff --git a/apps/mobile/src/native/T3ComposerEditor.ios.tsx b/apps/mobile/src/native/T3ComposerEditor.ios.tsxindex 76a2dad558f..1865e7d66c3 100644--- a/apps/mobile/src/native/T3ComposerEditor.ios.tsx+++ b/apps/mobile/src/native/T3ComposerEditor.ios.tsx@@ -20,7 +20,7 @@ import { composerChipSizeSuffix, contextChipPresentation } from "../lib/composerimport { resolveMarkdownFileIcon } from "../lib/markdownLinks";import { useUniwindTheme } from "../lib/useUniwindTheme";import { createNativeComposerTheme } from "../lib/nativeComposerTheme";-import { useFontFamily } from "../lib/useFontFamily";+import { FONT_FAMILIES } from "../lib/fontFamilies";import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";import {acknowledgeComposerNativeEvent,@@ -139,7 +139,7 @@ export function ComposerEditor({const confirmedTokensRef = useRef(collectComposerInlineTokens(props.value));const bodyText = useScaledTextRole("body");const theme = useUniwindTheme();- const fontFamily = useFontFamily("regular");+ const fontFamily = FONT_FAMILIES.regular;useImperativeHandle(ref,diff --git a/apps/mobile/src/native/T3ComposerEditor.native.tsx b/apps/mobile/src/native/T3ComposerEditor.native.tsxindex 1be467375d0..1263a7ded76 100644--- a/apps/mobile/src/native/T3ComposerEditor.native.tsx+++ b/apps/mobile/src/native/T3ComposerEditor.native.tsx@@ -21,7 +21,7 @@ import { composerChipSizeSuffix, contextChipPresentation } from "../lib/composerimport { resolveMarkdownFileIcon } from "../lib/markdownLinks";import { MOBILE_TYPOGRAPHY } from "../lib/typography";import { useNativePaste } from "../lib/useNativePaste";-import { useFontFamily } from "../lib/useFontFamily";+import { FONT_FAMILIES } from "../lib/fontFamilies";import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";import { useUniwindTheme } from "../lib/useUniwindTheme";import { createNativeComposerTheme } from "../lib/nativeComposerTheme";@@ -257,7 +257,7 @@ export function ComposerEditor({selection: Platform.OS === "android" || systemColorsActive ? theme["--color-focus"] : null,});const resolvedTextStyle = StyleSheet.flatten(textStyle) ?? {};- const regularFontFamily = useFontFamily("regular");+ const regularFontFamily = FONT_FAMILIES.regular;return (<TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}><NativeViewdiff --git a/apps/mobile/src/native/T3ComposerEditor.tsx b/apps/mobile/src/native/T3ComposerEditor.tsxindex 5df13972af0..20554b4f1eb 100644--- a/apps/mobile/src/native/T3ComposerEditor.tsx+++ b/apps/mobile/src/native/T3ComposerEditor.tsx@@ -2,7 +2,7 @@ import { TextInputWrapper } from "expo-paste-input";import { useImperativeHandle, useRef } from "react";import { TextInput, type TextInputInstance } from "react-native";-import { useFontFamily } from "../lib/useFontFamily";+import { FONT_FAMILIES } from "../lib/fontFamilies";import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";import { useNativePaste } from "../lib/useNativePaste";import type { ComposerEditorProps } from "./T3ComposerEditor.types";@@ -23,7 +23,7 @@ export function ComposerEditor({}: ComposerEditorProps) {const inputRef = useRef<TextInputInstance>(null);const bodyText = useScaledTextRole("body");- const fontFamily = useFontFamily("regular");+ const fontFamily = FONT_FAMILIES.regular;const handlePaste = useNativePaste((uris) => onPasteImages?.(uris));useImperativeHandle(diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 5ec681b483a..063e9ecd086 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -3329,7 +3329,7 @@ export default function ChatView(props: ChatViewProps) {});};const scheduleComposerFocusStable = useStableCallback(scheduleComposerFocus);- const useArtifactTemplate = (template: CodexArtifactTemplate) => {+ const insertArtifactTemplate = (template: CodexArtifactTemplate) => {const composer = composerRef.current;if (!composer) return;@@ -3345,7 +3345,7 @@ export default function ChatView(props: ChatViewProps) {}scheduleComposerFocus();};- const useArtifactTemplateStable = useStableCallback(useArtifactTemplate);+ const insertArtifactTemplateStable = useStableCallback(insertArtifactTemplate);const sendAppMessage = async (text: string) => {if (!isServerThread || activeThreadId === null) {throw new Error("Messages from apps need a started thread.");@@ -8018,7 +8018,7 @@ export default function ChatView(props: ChatViewProps) {}{...(!paintOnlyDisplayedTimeline? {- onUseArtifactTemplate: useArtifactTemplateStable,+ onUseArtifactTemplate: insertArtifactTemplateStable,onSendAppMessage: sendAppMessageStable,}: {})}diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsxindex c1ef7334690..b4083eac66b 100644--- a/apps/web/src/components/DiffPanel.tsx+++ b/apps/web/src/components/DiffPanel.tsx@@ -46,7 +46,7 @@ import { PREFERRED_HIGHLIGHTER } from "../lib/syntaxHighlighting";import { areAllDiffFilesCollapsed, toggleAllDiffFiles } from "../lib/diffCollapse";import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefresh";import { useProject, useThreadCheckpointSummaries, useQuietThreadShell } from "../state/entities";-import { useClientSettings, useUpdateClientSettings } from "../hooks/useSettings";+import { useClientSettings, updateClientSettings } from "../hooks/useSettings";import { formatShortTimestamp } from "../timestampFormat";import { DiffFilePathCopyButton } from "./DiffFilePathCopyButton";import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./DiffPanelShell";@@ -204,7 +204,6 @@ export default function DiffPanel({wordWrap: settings.wordWrap,}));const diffLayout = settings.diffLayout;- const updateClientSettings = useUpdateClientSettings();const [wordWrap, setWordWrap] = useState(settings.wordWrap);const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);const [fileTreeOpen, setFileTreeOpen] = useLocalStorage(diff --git a/apps/web/src/components/LegacySidebar.tsx b/apps/web/src/components/LegacySidebar.tsxindex 654a01d8410..b9c03f52bc3 100644--- a/apps/web/src/components/LegacySidebar.tsx+++ b/apps/web/src/components/LegacySidebar.tsx@@ -205,7 +205,7 @@ import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChromimport { useCopyToClipboard } from "~/hooks/useCopyToClipboard";import { useIsMobile } from "~/hooks/useMediaQuery";import { CommandDialogTrigger } from "./ui/command";-import { useClientSettings, useUpdateClientSettings } from "~/hooks/useSettings";+import { useClientSettings, updateClientSettings } from "~/hooks/useSettings";import { primaryServerKeybindingsAtom } from "../state/server";import {derivePhysicalProjectKey,@@ -1277,7 +1277,6 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjecconst updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {reportFailure: false,});- const updateSettings = useUpdateClientSettings();const router = useRouter();const queuePendingFileDrop = useSidebarPendingFileDropStore((s) => s.queuePendingFileDrop);const clearPendingFileDrop = useSidebarPendingFileDropStore((s) => s.clearPendingFileDrop);@@ -2124,7 +2123,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec} else {nextOverrides[overrideKey] = projectGroupingSelection;}- updateSettings({+ updateClientSettings({sidebarProjectGroupingOverrides: nextOverrides,});closeProjectGroupingDialog();@@ -2769,7 +2768,6 @@ interface SidebarProjectsContentProps {projectSortOrder: SidebarProjectSortOrder;threadSortOrder: SidebarThreadSortOrder;threadPreviewCount: SidebarThreadPreviewCount;- updateSettings: ReturnType<typeof useUpdateClientSettings>;openAddProject: () => void;isManualProjectSorting: boolean;projectDnDSensors: ReturnType<typeof useSensors>;@@ -2813,7 +2811,6 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(projectSortOrder,threadSortOrder,threadPreviewCount,- updateSettings,openAddProject,isManualProjectSorting,projectDnDSensors,@@ -2845,13 +2842,13 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(} = props;const handleProjectSortOrderChange = (sortOrder: SidebarProjectSortOrder) => {- updateSettings({ sidebarProjectSortOrder: sortOrder });+ updateClientSettings({ sidebarProjectSortOrder: sortOrder });};const handleThreadSortOrderChange = (sortOrder: SidebarThreadSortOrder) => {- updateSettings({ sidebarThreadSortOrder: sortOrder });+ updateClientSettings({ sidebarThreadSortOrder: sortOrder });};const handleThreadPreviewCountChange = (count: SidebarThreadPreviewCount) => {- updateSettings({ sidebarThreadPreviewCount: count });+ updateClientSettings({ sidebarThreadPreviewCount: count });};return (@@ -3246,7 +3243,6 @@ export default function LegacySidebar() {const sidebarThreadSortOrder = useClientSettings((s) => s.sidebarThreadSortOrder);const sidebarProjectSortOrder = useClientSettings((s) => s.sidebarProjectSortOrder);const sidebarThreadPreviewCount = useClientSettings((s) => s.sidebarThreadPreviewCount);- const updateSettings = useUpdateClientSettings();const handleNewThread = useNewThreadHandler();const { archiveThread, deleteThread, markThreadUnread } = useThreadActions();const { isMobile, setOpenMobile } = useSidebar();@@ -3629,7 +3625,6 @@ export default function LegacySidebar() {projectSortOrder={sidebarProjectSortOrder}threadSortOrder={sidebarThreadSortOrder}threadPreviewCount={sidebarThreadPreviewCount}- updateSettings={updateSettings}openAddProject={openAddProjectCommandPalette}isManualProjectSorting={isManualProjectSorting}projectDnDSensors={projectDnDSensors}diff --git a/apps/web/src/components/files/AttachmentFilePreview.tsx b/apps/web/src/components/files/AttachmentFilePreview.tsxindex 4425f95f21c..16b8c279023 100644--- a/apps/web/src/components/files/AttachmentFilePreview.tsx+++ b/apps/web/src/components/files/AttachmentFilePreview.tsx@@ -16,7 +16,7 @@ import { MorphIcon } from "~/components/MorphIcon";import { ScrollArea } from "~/components/ui/scroll-area";import { toastManager } from "~/components/ui/toast";import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";-import { useClientSettings, useUpdateClientSettings } from "~/hooks/useSettings";+import { useClientSettings, updateClientSettings } from "~/hooks/useSettings";import { cn } from "~/lib/utils";import { AudioPreview } from "./AudioPreview";@@ -159,7 +159,6 @@ export function AttachmentFilePreview(props: {}, [url, needsText, revision, props.sizeBytes, props.file, refresh]);const failure = error ?? (needsText ? contentError : null);const wordWrap = useClientSettings((settings) => settings.wordWrap);- const updateClientSettings = useUpdateClientSettings();const showsRawText =failure === null &&needsText &&diff --git a/apps/web/src/components/files/FilePreviewPanel.tsx b/apps/web/src/components/files/FilePreviewPanel.tsxindex 6a81ef7c4fe..fac7852f1e7 100644--- a/apps/web/src/components/files/FilePreviewPanel.tsx+++ b/apps/web/src/components/files/FilePreviewPanel.tsx@@ -49,7 +49,7 @@ import { MediaVideoPlayer } from "~/components/media/MediaVideoPlayer";import { MediaActions, type MediaActionSource } from "~/components/media/MediaActions";import { MorphIcon } from "~/components/MorphIcon";import { useRemoteOpenState } from "~/remoteOpen";-import { useClientSettings, useUpdateClientSettings } from "~/hooks/useSettings";+import { useClientSettings, updateClientSettings } from "~/hooks/useSettings";import { useTheme } from "~/hooks/useTheme";import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "~/hooks/useLocalStorage";import { useWorkspaceMutationRefresh } from "~/hooks/useWorkspaceMutationRefresh";@@ -1084,7 +1084,6 @@ export default function FilePreviewPanel({: null;const canToggleRendered =previewPath !== null && attachment === undefined && renderedMode !== null;- const updateClientSettings = useUpdateClientSettings();const showsRawText =previewPath !== null &&file.data !== null &&diff --git a/apps/web/src/components/onboarding/FirstRunGate.tsx b/apps/web/src/components/onboarding/FirstRunGate.tsxindex ec5f92e0f58..72fc3c1f015 100644--- a/apps/web/src/components/onboarding/FirstRunGate.tsx+++ b/apps/web/src/components/onboarding/FirstRunGate.tsx@@ -10,7 +10,7 @@ import {useClientSettingsHydrationStatus,} from "../../hooks/useSettings";import { isLocalEnvironmentDisabled } from "../../localEnvironment";-import { useCompleteOnboarding } from "../../onboarding/firstRun";+import { completeOnboarding } from "../../onboarding/firstRun";import {isFirstRunWorkspaceProvenanceAuthoritative,isFreshFirstRunWorkspace,@@ -82,7 +82,6 @@ export function FirstRunGate({const pathname = useLocation({ select: (location) => location.pathname });const hydrationStatus = useClientSettingsHydrationStatus();const hydrated = hydrationStatus === "ready";- const completeOnboarding = useCompleteOnboarding();const onboardingCompletedAt = useClientSettings((settings) => settings.onboardingCompletedAt);const bootstrapped = useAllEnvironmentShellsBootstrapped();const { environments, isReady: environmentCatalogReady } = useEnvironments();@@ -160,7 +159,7 @@ export function FirstRunGate({if (persistCompletion && onboardingCompletedAt === null) {void completeOnboarding().catch(() => undefined);}- }, [completeOnboarding, decision, hydrated, onboardingCompletedAt, persistCompletion]);+ }, [decision, hydrated, onboardingCompletedAt, persistCompletion]);useEffect(() => {if (!enabled || decision !== "pending" || !hydrated) return;diff --git a/apps/web/src/components/onboarding/WelcomeWizard.browser.test.tsx b/apps/web/src/components/onboarding/WelcomeWizard.browser.test.tsxindex fc9f9a70a43..760173b4906 100644--- a/apps/web/src/components/onboarding/WelcomeWizard.browser.test.tsx+++ b/apps/web/src/components/onboarding/WelcomeWizard.browser.test.tsx@@ -27,7 +27,7 @@ vi.mock("../../state/use-atom-command", () => ({? mocks.createProject: mocks.refresh,}));-vi.mock("../../onboarding/firstRun", () => ({ useCompleteOnboarding: () => mocks.complete }));+vi.mock("../../onboarding/firstRun", () => ({ completeOnboarding: mocks.complete }));vi.mock("../../state/entities", () => ({useProjects: () => mocks.projects,readProjects: () => mocks.projects,diff --git a/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx b/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsxindex c89050d2fc6..76f5f65ef64 100644--- a/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx+++ b/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx@@ -57,7 +57,7 @@ vi.mock(import("../../cloud/publicConfig"), async (original) => ({}));vi.mock(import("../../onboarding/firstRun"), async (original) => ({...(await original()),- useCompleteOnboarding: () => state.completeOnboarding,+ completeOnboarding: state.completeOnboarding,}));vi.mock(import("../../state/environments"), async (original) => {const environment = (environmentId: string) => ({diff --git a/apps/web/src/components/onboarding/WelcomeWizard.terminal.browser.test.tsx b/apps/web/src/components/onboarding/WelcomeWizard.terminal.browser.test.tsxindex 069c582d856..ebc2f504480 100644--- a/apps/web/src/components/onboarding/WelcomeWizard.terminal.browser.test.tsx+++ b/apps/web/src/components/onboarding/WelcomeWizard.terminal.browser.test.tsx@@ -114,7 +114,7 @@ vi.mock(import("../../onboarding/useProjectScans"), async (original) => ({}));vi.mock(import("../../onboarding/firstRun"), async (original) => ({...(await original()),- useCompleteOnboarding: () => state.complete,+ completeOnboarding: state.complete,}));vi.mock(import("../../cloud/publicConfig"), async (original) => ({...(await original()),diff --git a/apps/web/src/components/onboarding/WelcomeWizard.tsx b/apps/web/src/components/onboarding/WelcomeWizard.tsxindex 9cf3b9d60fa..2e87c712a02 100644--- a/apps/web/src/components/onboarding/WelcomeWizard.tsx+++ b/apps/web/src/components/onboarding/WelcomeWizard.tsx@@ -39,7 +39,7 @@ import { useLocalStorage } from "../../hooks/useLocalStorage";import { hasCloudPublicConfig } from "../../cloud/publicConfig";import { PRIVACY_POLICY_URL } from "../../legalLinks";import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt";-import { useCompleteOnboarding } from "../../onboarding/firstRun";+import { completeOnboarding } from "../../onboarding/firstRun";import {groupOnboardingProjects,partitionOnboardingProjects,@@ -116,7 +116,6 @@ export function WelcomeWizard({readonly resumeEnvironmentId?: EnvironmentId | undefined;readonly onDone: (projectRef?: ScopedProjectRef) => void | Promise<void>;}) {- const completeOnboarding = useCompleteOnboarding();const [step, setStep] = useState<WizardStep>(resumeEnvironmentId ? "agents" : "connection");const { environments } = useEnvironments();const [selection, setSelection] = useState<ReadonlySet<EnvironmentId> | null>(null);diff --git a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsxindex 399c3c5f97d..751b34ecdc0 100644--- a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx+++ b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx@@ -37,7 +37,7 @@ import {} from "react";import { useLocalStorage } from "~/hooks/useLocalStorage";-import { useClientSettings, useUpdateClientSettings } from "~/hooks/useSettings";+import { useClientSettings, updateClientSettings } from "~/hooks/useSettings";import { useTheme } from "~/hooks/useTheme";import { areAllDiffFilesCollapsed } from "~/lib/diffCollapse";import { pullRequestFindingKey, type PullRequestFinding } from "./pullRequestDetail.logic";@@ -281,7 +281,6 @@ function PullRequestCodeTab({const effectiveFoldOverride =foldOverride ?? (settings.diffFilesCollapsed ? "folded" : "expanded");const diffLayout = settings.diffLayout;- const updateClientSettings = useUpdateClientSettings();const [wordWrap, setWordWrap] = useState(settings.wordWrap);const [ignoreWhitespace, setIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);const [fileTreeOpen, setFileTreeOpen] = useLocalStorage(diff --git a/apps/web/src/components/settings/LoadBalancingSettings.tsx b/apps/web/src/components/settings/LoadBalancingSettings.tsxindex eca6eb3f423..63fde84c878 100644--- a/apps/web/src/components/settings/LoadBalancingSettings.tsx+++ b/apps/web/src/components/settings/LoadBalancingSettings.tsx@@ -3,7 +3,7 @@ import { resolveEnvironmentMachineKind } from "@t3tools/contracts";import {useClientSettings,useClientSettingsHydrated,- useUpdateClientSettings,+ updateClientSettings,} from "~/hooks/useSettings";import type { EnvironmentPresentation } from "~/state/environments";import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";@@ -54,7 +54,6 @@ export function LoadBalancingSettings({loadBalancingWeights: current.loadBalancingWeights,}));const settingsHydrated = useClientSettingsHydrated();- const updateSettings = useUpdateClientSettings();if (environments.length < 2) return null;@@ -73,7 +72,7 @@ export function LoadBalancingSettings({aria-label="Automatically balance load"checked={settings.loadBalancingEnabled}disabled={!settingsHydrated}- onCheckedChange={(loadBalancingEnabled) => updateSettings({ loadBalancingEnabled })}+ onCheckedChange={(loadBalancingEnabled) => updateClientSettings({ loadBalancingEnabled })}/>}>@@ -96,7 +95,7 @@ export function LoadBalancingSettings({disabled={!settingsHydrated || !settings.loadBalancingEnabled}onValueChange={(value) => {if (value === null) return;- updateSettings({+ updateClientSettings({loadBalancingWeights: {...settings.loadBalancingWeights,[environment.environmentId]: value,diff --git a/apps/web/src/components/settings/SnapShotSettings.browser.test.tsx b/apps/web/src/components/settings/SnapShotSettings.browser.test.tsxindex ada82678c49..2c813f07dac 100644--- a/apps/web/src/components/settings/SnapShotSettings.browser.test.tsx+++ b/apps/web/src/components/settings/SnapShotSettings.browser.test.tsx@@ -54,7 +54,7 @@ vi.mock(import("../../hooks/useSettings"), async (original) => {...(await original()),useClientSettings: (() =>useSyncExternalStore(subscribe, () => settingsStore.current)) as never,- useUpdateClientSettings: () => settingsStore.update as never,+ updateClientSettings: settingsStore.update as never,};});diff --git a/apps/web/src/components/settings/SnapShotSettings.tsx b/apps/web/src/components/settings/SnapShotSettings.tsxindex 3f8716d6e00..e9b54c4885b 100644--- a/apps/web/src/components/settings/SnapShotSettings.tsx+++ b/apps/web/src/components/settings/SnapShotSettings.tsx@@ -13,7 +13,7 @@ import * as Cause from "effect/Cause";import { useEffect, useRef, useState } from "react";import { useStableCallback } from "../../hooks/useStableCallback";-import { useClientSettings, useUpdateClientSettings } from "../../hooks/useSettings";+import { useClientSettings, updateClientSettings } from "../../hooks/useSettings";import { getDesktopSnapShotBridge } from "../../lib/desktopSnapShot";import {readSnapShotSetupResume,@@ -86,7 +86,6 @@ export function SnapShotSettings() {snapShotShortcut: current.snapShotShortcut,snapShotSound: current.snapShotSound,}));- const updateSettings = useUpdateClientSettings();const keybindings = useAtomValue(primaryServerKeybindingsAtom);const bridge = getDesktopSnapShotBridge();const [state, setState] = useState<DesktopSnapShotState | null>(null);@@ -226,7 +225,7 @@ export function SnapShotSettings() {const save = async (patch: ClientSettingsPatch) => {setSetupError(null);try {- await updateSettings(patch);+ await updateClientSettings(patch);return await refreshState();} catch (error) {setSetupError(captureSettingsError("Couldn't save capture settings", error));diff --git a/apps/web/src/hooks/useSettings.ts b/apps/web/src/hooks/useSettings.tsindex 64ecfb6596e..985a06d1acc 100644--- a/apps/web/src/hooks/useSettings.ts+++ b/apps/web/src/hooks/useSettings.ts@@ -728,8 +728,8 @@ export function useUpdatePrimarySettings() {return useUpdateSettingsTarget(usePrimaryEnvironment()?.environmentId ?? null);}-export function useUpdateClientSettings() {- return (patch: ClientSettingsPatch) => persistClientSettingsPatch(patch);+export function updateClientSettings(patch: ClientSettingsPatch): Promise<void> {+ return persistClientSettingsPatch(patch);}export function __resetClientSettingsPersistenceForTests(): void {diff --git a/apps/web/src/onboarding/firstRun.ts b/apps/web/src/onboarding/firstRun.tsindex 932c76a9046..357be71bb00 100644--- a/apps/web/src/onboarding/firstRun.ts+++ b/apps/web/src/onboarding/firstRun.ts@@ -1,11 +1,7 @@import { ensureClientSettingsHydrated, persistClientSettingsUpdate } from "../hooks/useSettings";-async function completeOnboarding(): Promise<void> {+export async function completeOnboarding(): Promise<void> {await ensureClientSettingsHydrated();const onboardingCompletedAt = new Date().toISOString();await persistClientSettingsUpdate((current) => ({ ...current, onboardingCompletedAt }));}--export function useCompleteOnboarding(): () => Promise<void> {- return completeOnboarding;-}diff --git a/docs/internals/mobile-development.md b/docs/internals/mobile-development.mdindex 1b29cf37012..b5b5bf3b143 100644--- a/docs/internals/mobile-development.md+++ b/docs/internals/mobile-development.md@@ -79,3 +79,6 @@ manual `useMemo`/`useCallback`/`memo` in the same change. Most mobile bailouts a`catch` or with `finally`, and refs read during render; see [Web UI](web-ui.md#react-compiler)for the usual rewrites. Mobile runs `t3code/no-manual-memo` with `allowMemoHooks`, so memodirectives are errors but the hooks stay legal until `KNOWN_BAILOUTS` is empty.+`t3code/no-hookless-use-function` rejects a `use*` function that calls no hook, since the compiler+leaves it uncached. A platform stub of a real hook, such as an `.android.ts` file, keeps the hook+name and suppresses the rule with a reason.diff --git a/docs/internals/web-ui.md b/docs/internals/web-ui.mdindex 31b98c5c2c1..13b7d9df99f 100644--- a/docs/internals/web-ui.md+++ b/docs/internals/web-ui.md@@ -68,7 +68,8 @@ scope when a value reaches plain function calls on both sides of a hook call. Ahelper forces one, but hides the ordering problem. Fix the order instead: plain uses of a value gobefore the hook, or the helper is inlined. A `use*` helper that calls no hook is compiled as aplain function and caches nothing, so a derived-value helper reads its source hook itself instead-of taking the value as an argument. Lint misses some bailouts, notably `try` with `finally` and+of taking the value as an argument. `t3code/no-hookless-use-function` rejects a `use*` function+that calls no hook. Lint misses some bailouts, notably `try` with `finally` and`throw` inside `try`, so [`reactCompilerCoverage.test.ts`](../../apps/web/src/reactCompilerCoverage.test.ts)compiles every file and fails on any skip. Async handlers rarely need `try`: anatom command settles into a result, so cleanup can follow the `await`. `useStableCallback` stilldiff --git a/oxlint-plugin-t3code/index.ts b/oxlint-plugin-t3code/index.tsindex edd1050e290..7809bcc1b9b 100644--- a/oxlint-plugin-t3code/index.ts+++ b/oxlint-plugin-t3code/index.ts@@ -3,6 +3,7 @@ import { definePlugin } from "@oxlint/plugins";import namespaceNodeImports from "./rules/namespace-node-imports.ts";import noGlobalProcessRuntime from "./rules/no-global-process-runtime.ts";import noHermesUnsupportedApis from "./rules/no-hermes-unsupported-apis.ts";+import noHooklessUseFunction from "./rules/no-hookless-use-function.ts";import noInlineSchemaCompile from "./rules/no-inline-schema-compile.ts";import noLowValueComments from "./rules/no-low-value-comments.ts";import noManualMemo from "./rules/no-manual-memo.ts";@@ -28,6 +29,7 @@ export default definePlugin({"namespace-node-imports": namespaceNodeImports,"no-global-process-runtime": noGlobalProcessRuntime,"no-hermes-unsupported-apis": noHermesUnsupportedApis,+ "no-hookless-use-function": noHooklessUseFunction,"no-inline-schema-compile": noInlineSchemaCompile,"no-low-value-comments": noLowValueComments,"no-manual-effect-runtime-in-tests": noManualEffectRuntimeInTests,diff --git a/oxlint-plugin-t3code/rules/no-hookless-use-function.test.ts b/oxlint-plugin-t3code/rules/no-hookless-use-function.test.tsnew file mode 100644index 00000000000..7ce79d7a40d--- /dev/null+++ b/oxlint-plugin-t3code/rules/no-hookless-use-function.test.ts@@ -0,0 +1,48 @@+import { describe } from "@effect/vitest";++import { createOxlintRuleHarness } from "../test/utils.ts";++const rule = createOxlintRuleHarness("t3code/no-hookless-use-function", {+ filename: "fixture.tsx",+});++describe("t3code/no-hookless-use-function", () => {+ rule.valid(+ "allows a hook that calls useState",+ `function useCount() { const [count] = useState(0); return count; }`,+ );++ rule.valid(+ "allows a hook that only calls use()",+ `const useTheme = () => { return use(ThemeContext); };`,+ );++ rule.valid(+ "allows a hook that calls a member hook",+ `const useStore = () => React.useContext(StoreContext);`,+ );++ rule.valid("allows a plain function", `function formatLabel(value) { return String(value); }`);++ rule.valid("allows names that only start with use", `function user() { return null; }`);++ rule.invalid(+ "reports a hook-less function declaration",+ `function useFontFamily(weight) { return FONT_FAMILIES[weight]; }`,+ );++ rule.invalid(+ "reports a hook-less arrow returning a closure",+ `const useUpdateSettings = () => (patch) => persist(patch);`,+ );++ rule.invalid(+ "reports a hook-less function expression",+ `const useCompleteOnboarding = function () { return completeOnboarding; };`,+ );++ rule.invalid(+ "reports a hook call that only happens inside a nested callback",+ `function useHandler() { return () => useState(0); }`,+ );+});diff --git a/oxlint-plugin-t3code/rules/no-hookless-use-function.ts b/oxlint-plugin-t3code/rules/no-hookless-use-function.tsnew file mode 100644index 00000000000..10141d7dc3b--- /dev/null+++ b/oxlint-plugin-t3code/rules/no-hookless-use-function.ts@@ -0,0 +1,75 @@+import { defineRule, type ESTree } from "@oxlint/plugins";++const HOOK_NAME = /^use[A-Z]/;+// Bare `use` is React 19's `use(promise | context)`, which is a hook call too.+const HOOK_CALLEE = /^use([A-Z]|$)/;++type FunctionNode = ESTree.Function | ESTree.ArrowFunctionExpression;++function isFunctionNode(node: ESTree.Node): node is FunctionNode {+ return (+ node.type === "FunctionDeclaration" ||+ node.type === "FunctionExpression" ||+ node.type === "ArrowFunctionExpression"+ );+}++function isHookCallee(callee: ESTree.Node): boolean {+ if (callee.type === "Identifier") return HOOK_CALLEE.test(callee.name);+ if (callee.type === "MemberExpression" && !callee.computed) {+ return callee.property.type === "Identifier" && HOOK_CALLEE.test(callee.property.name);+ }+ return false;+}++// A hook call inside a nested callback runs when the callback runs, not during render,+// so it does not make the outer function a hook.+function callsHook(node: unknown, root: unknown): boolean {+ if (typeof node !== "object" || node === null) return false;+ if (Array.isArray(node)) return node.some((child) => callsHook(child, root));+ if (!("type" in node) || typeof node.type !== "string") return false;+ const typed = node as ESTree.Node;+ if (typed !== root && isFunctionNode(typed)) return false;+ if (typed.type === "CallExpression" && isHookCallee(typed.callee)) return true;+ for (const [key, value] of Object.entries(typed)) {+ if (key === "parent") continue;+ if (callsHook(value, root)) return true;+ }+ return false;+}++export default defineRule({+ meta: {+ type: "problem",+ docs: {+ description:+ "Disallow use* functions that call no hooks; the React Compiler only compiles functions that do. Mirrors eslint-react's no-unnecessary-use-prefix, which oxlint does not ship.",+ },+ schema: [],+ },+ create(context) {+ const check = (name: string, fn: FunctionNode, reportNode: ESTree.Node) => {+ if (!HOOK_NAME.test(name)) return;+ if (callsHook(fn.body, fn)) return;+ context.report({+ node: reportNode,+ message: `"${name}" calls no hooks, so the React Compiler skips it and whatever it returns is rebuilt on every render. Rename it to a plain function, or read the hook it depends on inside it.`,+ });+ };+ return {+ FunctionDeclaration(node) {+ if (node.id) check(node.id.name, node, node.id);+ },+ VariableDeclarator(node) {+ if (node.id.type !== "Identifier" || node.init == null) return;+ if (+ node.init.type !== "ArrowFunctionExpression" &&+ node.init.type !== "FunctionExpression"+ ) {+ return;+ }+ check(node.id.name, node.init, node.id);+ },+ };+ },+});diff --git a/vite.config.ts b/vite.config.tsindex 29c6816d526..1de21faa5f6 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -377,6 +377,13 @@ export default defineConfig({files: ["apps/mobile/src/**/*.{ts,tsx}"],rules: { "t3code/no-manual-memo": ["error", { allowMemoHooks: true }] },},+ {+ // The compiler only compiles a use* function that calls a hook; one that calls none is+ // silently left as a plain function, so whatever it returns loses its caching.+ files: ["apps/web/src/**/*.{ts,tsx}", "apps/mobile/src/**/*.{ts,tsx}"],+ excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],+ rules: { "t3code/no-hookless-use-function": "error" },+ },{files: ["apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx",