Rework atom naming (#18240)

## Summary

- **Enhanced the `matching-state-variable` ESLint rule** to enforce
consistent naming for `ComponentState`, `FamilyState`, and
`ComponentFamilyState` hooks — previously it only covered `useAtomState`
and `useAtomStateValue`
- **The rule now checks 12 hooks** across three categories: value hooks
(`useAtomComponentStateValue`, `useAtomFamilyStateValue`, etc.), state
hooks (`useAtomComponentState`, `useAtomComponentFamilyState`), and
setter hooks (`useSetAtomState`, `useSetAtomComponentState`,
`useSetAtomFamilyState`, `useSetAtomComponentFamilyState`)
- **Fixed all 225 resulting lint violations** across 151 files, renaming
variables to match their state atom names (e.g. `currentViewId` →
`contextStoreCurrentViewId`, `selectedRecord` → `recordStore`). Cases
where the same state is accessed with different family keys/instance IDs
are suppressed with `eslint-disable-next-line`.

## Naming convention

| Hook | State argument | Valid | Invalid |
|------|---------------|-------|---------|
| `useAtomStateValue` | `fooState` | `const foo = ...` | `const bar =
...` |
| `useAtomComponentStateValue` | `fooComponentState` | `const foo = ...`
| `const bar = ...` |
| `useAtomFamilyStateValue` | `fooFamilyState` | `const foo = ...` |
`const bar = ...` |
| `useAtomComponentFamilyStateValue` | `fooComponentFamilyState` |
`const foo = ...` | `const bar = ...` |
| `useAtomState` | `fooState` | `const [foo, setFoo] = ...` | `const
[bar, setBar] = ...` |
| `useAtomComponentState` | `fooComponentState` | `const [foo, setFoo] =
...` | `const [bar, setBar] = ...` |
| `useAtomComponentFamilyState` | `fooComponentFamilyState` | `const
[foo, setFoo] = ...` | `const [bar, setBar] = ...` |
| `useSetAtomState` | `fooState` | `const setFoo = ...` | `const setBar
= ...` |
| `useSetAtomComponentState` | `fooComponentState` | `const setFoo =
...` | `const setBar = ...` |
| `useSetAtomFamilyState` | `fooFamilyState` | `const setFoo = ...` |
`const setBar = ...` |
| `useSetAtomComponentFamilyState` | `fooComponentFamilyState` | `const
setFoo = ...` | `const setBar = ...` |
This commit is contained in:
Charles Bochet
2026-02-25 22:28:25 +01:00
committed by GitHub
parent 1b805a36f3
commit bc4ae35bc4
321 changed files with 1824 additions and 1518 deletions
@@ -17,7 +17,7 @@ export const ContextStoreDecorator: Decorator = (Story, context) => {
componentInstanceId = MAIN_CONTEXT_STORE_INSTANCE_ID;
}
const setCurrentObjectMetadataItemId = useSetAtomComponentState(
const setContextStoreCurrentObjectMetadataItemId = useSetAtomComponentState(
contextStoreCurrentObjectMetadataItemIdComponentState,
componentInstanceId,
);
@@ -27,9 +27,9 @@ export const ContextStoreDecorator: Decorator = (Story, context) => {
const objectMetadataItem = getMockCompanyObjectMetadataItem();
useEffect(() => {
setCurrentObjectMetadataItemId(objectMetadataItem.id);
setContextStoreCurrentObjectMetadataItemId(objectMetadataItem.id);
setIsLoaded(true);
}, [setCurrentObjectMetadataItemId, objectMetadataItem]);
}, [setContextStoreCurrentObjectMetadataItemId, objectMetadataItem]);
return (
<ContextStoreComponentInstanceContext.Provider
@@ -5,17 +5,18 @@ import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { useSetAtomFamilyState } from '@/ui/utilities/state/jotai/hooks/useSetAtomFamilyState';
export const PrefetchLoadedDecorator: Decorator = (Story) => {
const setAreFavoritesPrefetched = useSetAtomFamilyState(
const setPrefetchIsLoaded = useSetAtomFamilyState(
prefetchIsLoadedFamilyState,
PrefetchKey.AllFavorites,
);
const setAreFavoritesFoldersPrefetched = useSetAtomFamilyState(
// eslint-disable-next-line twenty/matching-state-variable
const setPrefetchIsLoadedFolders = useSetAtomFamilyState(
prefetchIsLoadedFamilyState,
PrefetchKey.AllFavoritesFolders,
);
setAreFavoritesPrefetched(true);
setAreFavoritesFoldersPrefetched(true);
setPrefetchIsLoaded(true);
setPrefetchIsLoadedFolders(true);
return <Story />;
};
@@ -10,12 +10,13 @@ export const PrefetchLoadingDecorator: Decorator = (Story, context) => {
const prefetchLoadingSetDelay = parameters.prefetchLoadingSetDelay ?? 0;
const setAreFavoritesFoldersPrefetched = useSetAtomFamilyState(
const setPrefetchIsLoaded = useSetAtomFamilyState(
prefetchIsLoadedFamilyState,
PrefetchKey.AllFavoritesFolders,
);
const setAreFavoritesPrefetched = useSetAtomFamilyState(
// eslint-disable-next-line twenty/matching-state-variable
const setPrefetchIsLoadedFavorites = useSetAtomFamilyState(
prefetchIsLoadedFamilyState,
PrefetchKey.AllFavorites,
);
@@ -30,14 +31,14 @@ export const PrefetchLoadingDecorator: Decorator = (Story, context) => {
setIsInitialized(true);
setTimeout(() => {
setAreFavoritesPrefetched(false);
setAreFavoritesFoldersPrefetched(false);
setPrefetchIsLoadedFavorites(false);
setPrefetchIsLoaded(false);
}, prefetchLoadingSetDelay);
}, [
isInitialized,
prefetchLoadingSetDelay,
setAreFavoritesFoldersPrefetched,
setAreFavoritesPrefetched,
setPrefetchIsLoaded,
setPrefetchIsLoadedFavorites,
]);
return <Story />;
@@ -64,12 +64,12 @@ export const JestContextStoreSetter = ({
instanceId,
);
const setContextStoreFiltersComponentState = useSetAtomComponentState(
const setContextStoreFilters = useSetAtomComponentState(
contextStoreFiltersComponentState,
instanceId,
);
const setContextStoreFilterGroupsComponentState = useSetAtomComponentState(
const setContextStoreFilterGroups = useSetAtomComponentState(
contextStoreFilterGroupsComponentState,
instanceId,
);
@@ -96,8 +96,8 @@ export const JestContextStoreSetter = ({
setContextStoreTargetedRecordsRule(contextStoreTargetedRecordsRule);
setContextStoreCurrentObjectMetadataItemId(objectMetadataItem.id);
setContextStoreNumberOfSelectedRecords(contextStoreNumberOfSelectedRecords);
setContextStoreFiltersComponentState(contextStoreFilters);
setContextStoreFilterGroupsComponentState(contextStoreFilterGroups);
setContextStoreFilters(contextStoreFilters);
setContextStoreFilterGroups(contextStoreFilterGroups);
setContextStoreCurrentViewType(contextStoreCurrentViewType ?? null);
setIsLoaded(true);
}, [
@@ -107,14 +107,14 @@ export const JestContextStoreSetter = ({
contextStoreCurrentObjectMetadataId,
setContextStoreNumberOfSelectedRecords,
contextStoreNumberOfSelectedRecords,
setContextStoreFiltersComponentState,
setContextStoreFilters,
contextStoreFilters,
objectMetadataItem,
setContextStoreCurrentViewId,
contextStoreCurrentViewId,
setContextStoreCurrentViewType,
contextStoreCurrentViewType,
setContextStoreFilterGroupsComponentState,
setContextStoreFilterGroups,
contextStoreFilterGroups,
]);