Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(alint): require routed-host evidence for view switch warnings (#23347)

AmAzing-5a121796282d
diff --git a/packages/alint/fixtures/ui-view-switch-tabs/bad-routed-local-tabs.tsx b/packages/alint/fixtures/ui-view-switch-tabs/bad-routed-local-tabs.tsx
new file mode 100644
index 00000000000..e409e502c35
--- /dev/null
+++ b/packages/alint/fixtures/ui-view-switch-tabs/bad-routed-local-tabs.tsx
@@ -0,0 +1,25 @@
+import { Flexbox, Tabs } from '@lobehub/ui';
+import { useState } from 'react';
+
+import ConnectorCatalog from './ConnectorCatalog';
+import SkillCatalog from './SkillCatalog';
+
+// Routed page entry for /settings/catalog; the route table imports it from another file.
+export const Catalog = () => {
+ const [tab, setTab] = useState('skills');
+
+ return (
+ <Flexbox>
+ {/* alint-expect */}
+ <Tabs
+ activeKey={tab}
+ items={[
+ { key: 'skills', label: 'Skills' },
+ { key: 'connectors', label: 'Connectors' },
+ ]}
+ onChange={setTab}
+ />
+ {tab === 'skills' ? <SkillCatalog /> : <ConnectorCatalog />}
+ </Flexbox>
+ );
+};
diff --git a/packages/alint/fixtures/ui-view-switch-tabs/bad-segmented-views.tsx b/packages/alint/fixtures/ui-view-switch-tabs/bad-segmented-views.tsx
index f936b5c45b1..5492a590ce4 100644
--- a/packages/alint/fixtures/ui-view-switch-tabs/bad-segmented-views.tsx
+++ b/packages/alint/fixtures/ui-view-switch-tabs/bad-segmented-views.tsx
@@ -1,8 +1,8 @@
-// Fixture: a Segmented switching whole panels, kept only in local state.
-import { Flexbox } from '@lobehub/ui';
-import { Segmented } from '@lobehub/ui';
+// Fixture: a routed page uses Segmented to switch whole panels in local state.
+import { Flexbox, Segmented } from '@lobehub/ui';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { Route, Routes } from 'react-router-dom';
import DirectoryTree from './DirectoryTree';
import HealthOverview from './HealthOverview';
@@ -31,4 +31,8 @@ const DeviceDetail = memo<{ deviceId: string }>(({ deviceId }) => {
);
});
-export default DeviceDetail;
+export const DeviceRoutes = () => (
+ <Routes>
+ <Route element={<DeviceDetail deviceId={'current'} />} path={'/devices/current'} />
+ </Routes>
+);
diff --git a/packages/alint/fixtures/ui-view-switch-tabs/good-extracted-store-content.tsx b/packages/alint/fixtures/ui-view-switch-tabs/good-extracted-store-content.tsx
new file mode 100644
index 00000000000..442f48983c2
--- /dev/null
+++ b/packages/alint/fixtures/ui-view-switch-tabs/good-extracted-store-content.tsx
@@ -0,0 +1,78 @@
+'use client';
+
+import { Flexbox, Segmented } from '@lobehub/ui';
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useToolStore } from '@/store/tool';
+
+import Search from './Search';
+import AddSkillButton from './SkillList/AddSkillButton';
+import LobeHubList from './SkillList/LobeHub';
+import MarketSkillList from './SkillList/MarketSkills';
+import MCPList from './SkillList/MCP';
+
+export enum SkillStoreTab {
+ LobeHub = 'lobehub',
+ MCP = 'mcp',
+ Skills = 'skills',
+}
+
+export const SkillStoreContent = () => {
+ const { t } = useTranslation('setting');
+ const [activeTab, setActiveTab] = useState<SkillStoreTab>(SkillStoreTab.LobeHub);
+ const [lobehubKeywords, setLobehubKeywords] = useState('');
+ const [skillKeywords, setSkillKeywords] = useState('');
+
+ // Refresh builtin-tool install state for the active workspace whenever the
+ // modal mounts, so entries opened from contexts that don't host the chat
+ // input (e.g. Home banner) don't read leftover personal-scope state.
+ const useFetchUninstalledBuiltinTools = useToolStore((s) => s.useFetchUninstalledBuiltinTools);
+ useFetchUninstalledBuiltinTools(true);
+
+ const options = [
+ { label: t('skillStore.tabs.lobehub'), value: SkillStoreTab.LobeHub },
+ { label: t('skillStore.tabs.skills'), value: SkillStoreTab.Skills },
+ { label: t('skillStore.tabs.mcp'), value: SkillStoreTab.MCP },
+ ];
+
+ const isLobeHub = activeTab === SkillStoreTab.LobeHub;
+ const isSkills = activeTab === SkillStoreTab.Skills;
+ const isMCP = activeTab === SkillStoreTab.MCP;
+
+ return (
+ <Flexbox gap={8} style={{ maxHeight: '75vh' }} width={'100%'}>
+ {/* Source chips, then search and Add on one row, like the connectors page header. */}
+ <Flexbox gap={12}>
+ <Segmented<SkillStoreTab>
+ aria-label={t('connectorMarket.source')}
+ options={options}
+ style={{ alignSelf: 'flex-start' }}
+ value={activeTab}
+ onChange={setActiveTab}
+ />
+ <Flexbox horizontal align={'center'} gap={8}>
+ <Flexbox flex={1}>
+ <Search
+ activeTab={activeTab}
+ onLobeHubSearch={setLobehubKeywords}
+ onSkillSearch={setSkillKeywords}
+ />
+ </Flexbox>
+ <AddSkillButton />
+ </Flexbox>
+ </Flexbox>
+ <Flexbox height={496} style={{ marginBlockEnd: -12, marginInline: -16 }}>
+ <Flexbox flex={1} style={{ display: isLobeHub ? 'flex' : 'none', overflow: 'auto' }}>
+ <LobeHubList keywords={lobehubKeywords} />
+ </Flexbox>
+ <Flexbox flex={1} style={{ display: isSkills ? 'flex' : 'none', overflow: 'auto' }}>
+ <MarketSkillList keywords={skillKeywords} />
+ </Flexbox>
+ <Flexbox flex={1} style={{ display: isMCP ? 'flex' : 'none', overflow: 'auto' }}>
+ <MCPList />
+ </Flexbox>
+ </Flexbox>
+ </Flexbox>
+ );
+};
diff --git a/packages/alint/fixtures/ui-view-switch-tabs/good-modal-views.tsx b/packages/alint/fixtures/ui-view-switch-tabs/good-modal-views.tsx
new file mode 100644
index 00000000000..a69a538d1c5
--- /dev/null
+++ b/packages/alint/fixtures/ui-view-switch-tabs/good-modal-views.tsx
@@ -0,0 +1,28 @@
+import { Flexbox, Segmented, Tabs } from '@lobehub/ui';
+import { createModal } from '@lobehub/ui/base-ui';
+import { useState } from 'react';
+
+import ConnectorCatalog from './ConnectorCatalog';
+import SkillCatalog from './SkillCatalog';
+
+const CatalogContent = () => {
+ const [source, setSource] = useState('skills');
+ const [tab, setTab] = useState('installed');
+
+ return (
+ <Flexbox>
+ <Segmented options={['skills', 'connectors']} value={source} onChange={setSource} />
+ <Tabs
+ activeKey={tab}
+ items={[
+ { key: 'installed', label: 'Installed' },
+ { key: 'discover', label: 'Discover' },
+ ]}
+ onChange={setTab}
+ />
+ {source === 'skills' ? <SkillCatalog tab={tab} /> : <ConnectorCatalog tab={tab} />}
+ </Flexbox>
+ );
+};
+
+export const openCatalog = () => createModal({ content: <CatalogContent /> });
diff --git a/packages/alint/fixtures/ui-view-switch-tabs/good-segmented-filter.tsx b/packages/alint/fixtures/ui-view-switch-tabs/good-segmented-filter.tsx
index 8073d56625e..57f83a465a3 100644
--- a/packages/alint/fixtures/ui-view-switch-tabs/good-segmented-filter.tsx
+++ b/packages/alint/fixtures/ui-view-switch-tabs/good-segmented-filter.tsx
@@ -1,8 +1,8 @@
// Fixture: a Segmented that only filters the same list.
-import { Flexbox } from '@lobehub/ui';
-import { Segmented } from '@lobehub/ui';
+import { Flexbox, Segmented } from '@lobehub/ui';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { Route, Routes } from 'react-router-dom';
import TaskList from './TaskList';
@@ -25,4 +25,8 @@ const TaskFilterList = memo(() => {
);
});
-export default TaskFilterList;
+export const TaskRoutes = () => (
+ <Routes>
+ <Route element={<TaskFilterList />} path={'/tasks'} />
+ </Routes>
+);
diff --git a/packages/alint/fixtures/ui-view-switch-tabs/good-unknown-host.tsx b/packages/alint/fixtures/ui-view-switch-tabs/good-unknown-host.tsx
new file mode 100644
index 00000000000..2ea3b4a0270
--- /dev/null
+++ b/packages/alint/fixtures/ui-view-switch-tabs/good-unknown-host.tsx
@@ -0,0 +1,21 @@
+import { Flexbox, Segmented } from '@lobehub/ui';
+import { useState } from 'react';
+
+import DirectoryTree from './DirectoryTree';
+import HealthOverview from './HealthOverview';
+
+// The caller is outside this file; different panels do not establish a routed host.
+export const DeviceDetail = ({ deviceId }: { deviceId: string }) => {
+ const [view, setView] = useState<'overview' | 'files'>('overview');
+
+ return (
+ <Flexbox>
+ <Segmented options={['overview', 'files']} value={view} onChange={setView} />
+ {view === 'overview' ? (
+ <HealthOverview deviceId={deviceId} />
+ ) : (
+ <DirectoryTree deviceId={deviceId} />
+ )}
+ </Flexbox>
+ );
+};
diff --git a/packages/alint/rules/ui-view-switch-tabs/rule.alint.toml b/packages/alint/rules/ui-view-switch-tabs/rule.alint.toml
index e8905c86580..16b2753dd8b 100644
--- a/packages/alint/rules/ui-view-switch-tabs/rule.alint.toml
+++ b/packages/alint/rules/ui-view-switch-tabs/rule.alint.toml
@@ -5,17 +5,19 @@ You are reviewing one React component file from LobeHub's web client.
Team rule, distilled from the product owner's review rejections ("这个用 tab 而不是 Segmented,URL 也要对应变的", "你怎么给我改成 segmented 了??我要的是 tab 啊??", "验收流程应该是第二个 tab,默认应该进到验收清单里"): switching between the main views of a page or panel is navigation. It uses tabs (`Tabs` from @lobehub/ui or antd), and the active tab lives in the URL (a route segment or a search param through the router), so a view can be linked, reloaded and navigated back to.
-Report:
-1. a `Segmented` (or a row of toggle buttons) whose options switch between whole views / panels of a page or portal — each option mounts a different section with its own content — rather than filtering or toggling one list;
-2. page- or panel-level `Tabs` whose active key is kept only in `useState` when the surface has its own route (a page, a portal view, a settings panel), so the view is lost on reload and cannot be linked.
-Anchor on the line of the `Segmented` / `Tabs` element. In the message, name the views being switched. In the suggestion, say to use `Tabs` and where the active key should live in the URL.
+Check the host BEFORE judging the switcher. You see only this file, not its callers or imports' implementations. Both report patterns below require positive evidence that this switcher is navigation for a routed page or portal: a same-file route definition mounting this component; the supplied file path identifying the exported component as a page segment at `src/routes/.../index.tsx`; or an explicit in-file contract stating which route this module implements. The route table itself may live elsewhere. A component name, an export, router imports/hooks alone, or several independently rendered panels do not establish that contract. If no such evidence is present and its render host is external or unknown, return no finding. Do not guess that an extracted content component owns a route.
-Do not report:
+Do not report (these exclusions take priority over both report patterns):
- `Segmented` used as a filter, a sort order, a unit or a display mode of the same data (list / grid, day / week, all / mine);
- small in-card or in-popover switches, form controls, and tabs inside modals;
- tabs whose key is already read from the URL or passed in by a parent (controlled `activeTab` / `onTabChange` props);
-- tabs in a component hosted by a modal (`*Modal` files, `createModal`, `open*Modal` helpers). If you cannot see that the component is a routed page or portal view, return no finding;
+- any switcher (`Segmented`, toggle buttons, or `Tabs`) hosted by a modal, including content extracted from `createModal` / `open*Modal` into another file or wrapped in providers. Different source lists, independent search state, and local active-tab state do not turn modal content into routed navigation. A modal can be opened from a routed page and still qualifies for this exclusion;
- sheet / slide strips inside document viewers, filter pills in sidebar sections, and transient switchers inside a chat message.
-If an exclusion applies, return no finding. If uncertain, use low confidence.
+Only AFTER the host check passes and no exclusion applies, report:
+1. a `Segmented` (or a row of toggle buttons) switching between whole views / panels of that routed page or portal, rather than filtering or toggling one list;
+2. page- or panel-level `Tabs` whose active key is kept only in `useState`, so the routed view is lost on reload and cannot be linked.
+Anchor on the line of the `Segmented` / `Tabs` element. In the message, name the views and cite the file-path or in-file evidence that this switcher belongs to routed navigation. In the suggestion, say to use `Tabs` and where the active key should live in the URL.
+
+If an exclusion applies or the host cannot be established, return no finding, not a low-confidence warning. Never emit a conditional finding such as "if this is only hosted inside a modal, this does not apply": that uncertainty means the host check failed.
"""