Skip to content

Commit fdd808f

Browse files
committed
fix: improve react code based on @eslint-react plugin
Add some TODO for some legacy code
1 parent 02a3188 commit fdd808f

File tree

27 files changed

+607
-70
lines changed

27 files changed

+607
-70
lines changed

.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"next/core-web-vitals",
66
"plugin:storybook/recommended"
77
],
8+
"plugins": ["@eslint-react/eslint-plugin"],
89
"rules": {
910
"react/no-unescaped-entities": "off",
1011
"@typescript-eslint/no-unused-vars": [
@@ -18,6 +19,10 @@
1819
"sonarjs/prefer-immediate-return": "warn"
1920
},
2021
"overrides": [
22+
{
23+
"files": ["**/*.{ts,tsx}"],
24+
"extends": ["plugin:@eslint-react/recommended-legacy"]
25+
},
2126
{
2227
"files": ["./src/**/*.*"],
2328
"rules": {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"@babel/eslint-parser": "7.24.7",
107107
"@babel/parser": "7.24.7",
108108
"@chakra-ui/cli": "2.4.1",
109+
"@eslint-react/eslint-plugin": "1.14.3",
109110
"@next/eslint-plugin-next": "14.2.4",
110111
"@playwright/test": "1.45.1",
111112
"@storybook/addon-actions": "8.1.11",

pnpm-lock.yaml

Lines changed: 471 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ConfirmMenuItem/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ export const ConfirmMenuItem = forwardRef<ConfirmMenuItemProps, 'button'>(
179179
},
180180
},
181181
icon: icon
182-
? React.cloneElement(icon, { color: 'transparent' })
182+
? // TODO @eslint-react rule
183+
// eslint-disable-next-line @eslint-react/no-clone-element
184+
React.cloneElement(icon, { color: 'transparent' })
183185
: icon,
184186
}
185187
: {};

src/components/ConfirmModal/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ export const ConfirmModal: React.FC<
4343
!title && !message ? t('components:confirmModal.heading') : title;
4444

4545
if (!isEnabled) {
46+
// TODO @eslint-react rule
47+
// eslint-disable-next-line @eslint-react/no-clone-element
4648
const childrenWithOnClick = React.cloneElement(children, {
4749
onClick: onConfirm,
4850
});
4951
return <>{childrenWithOnClick}</>;
5052
}
5153

54+
// TODO @eslint-react rule
55+
// eslint-disable-next-line @eslint-react/no-clone-element
5256
const childrenWithOnOpen = React.cloneElement(children, {
5357
onClick: confirmModal.onOpen,
5458
});

src/components/ConfirmPopover/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export const ConfirmPopover: React.FC<
5050
const initialFocusRef = useRef<HTMLButtonElement>(null);
5151

5252
if (!isEnabled) {
53+
// TODO @eslint-react rule
54+
// eslint-disable-next-line @eslint-react/no-clone-element
5355
const childrenWithOnClick = React.cloneElement(children, {
5456
onClick: onConfirm,
5557
});

src/components/DateAgo/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export type DateAgoProps = Omit<TooltipProps, 'children'> & {
2222
};
2323

2424
export const DateAgo: FC<React.PropsWithChildren<DateAgoProps>> = forwardRef(
25-
function DateAgo({ date = new Date(), format, ...rest }, ref) {
25+
function DateAgo({ date, format, ...rest }, ref) {
2626
const { t } = useTranslation(['components']);
2727
const [, setForceUpdate] = useState(0);
28-
const dayjsDate = dayjs(date);
28+
const dayjsDate = dayjs(date ?? new Date());
2929
const dateFormatted = dayjsDate.format();
3030

3131
useEffect(() => {

src/components/DayPicker/_partials/DayPickerContent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ export const DayPickerContent = forwardRef<
134134
selected={value ?? undefined}
135135
onSelect={handleDaySelect}
136136
components={{
137+
// TODO @eslint-react rule
138+
// eslint-disable-next-line @eslint-react/no-nested-components
137139
Caption: (props) => (
138140
<Caption
139141
{...props}

src/components/DayPicker/hooks/useDayPickerInputManagement.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ export const useDayPickerInputManagement = (
3131
// Pour mettre à jour l'input selon la value
3232
useEffect(() => {
3333
if (!!dateValue) {
34+
// TODO @eslint-react rule
35+
// eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
3436
setInputValue(dayjs(dateValue).format(dateFormat));
3537
} else {
38+
// TODO @eslint-react rule
39+
// eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
3640
setInputValue('');
3741
}
3842
}, [dateFormat, dateValue]);

src/components/DayPicker/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export const DayPicker: FC<DayPickerProps> = ({
4848
id,
4949
value,
5050
onChange,
51-
onClose = () => {},
51+
onClose,
5252
popperPlacement = 'bottom-start',
5353
dateFormat = DATE_FORMAT,
5454
placeholder = 'JJ/MM/AAAA',
55-
inputProps = {},
55+
inputProps,
5656
isDisabled = false,
5757
autoFocus = false,
58-
onMonthChange = () => {},
58+
onMonthChange,
5959
...rest
6060
}) => {
6161
const containerRef = useRef<HTMLDivElement>(null);
@@ -69,7 +69,7 @@ export const DayPicker: FC<DayPickerProps> = ({
6969

7070
// Popper management
7171
const onClosePopper = () => {
72-
onClose(value);
72+
onClose?.(value);
7373
setMode('DAY');
7474
};
7575

@@ -112,21 +112,21 @@ export const DayPicker: FC<DayPickerProps> = ({
112112
const { setMode, setMonth, selectMonth } = hookMonthNavigation;
113113

114114
const handleChangeMonth = (date?: Date | null) => {
115-
onMonthChange(date);
115+
onMonthChange?.(date);
116116
setMonth(date);
117117
};
118118

119119
// Change to day view once we have selected a month on the month picker
120120
const handleSelectMonth = (date: Date) => {
121-
onMonthChange(date);
121+
onMonthChange?.(date);
122122
selectMonth(date);
123123
};
124124

125125
const valueRef = useRef(value);
126126
valueRef.current = value;
127127

128128
return (
129-
<InputGroup ref={containerRef} size={size} width={inputProps.width}>
129+
<InputGroup ref={containerRef} size={size} width={inputProps?.width}>
130130
<InputLeftElement pointerEvents="none">
131131
<Icon
132132
icon={FiCalendar}

0 commit comments

Comments
 (0)