Skip to content

Commit

Permalink
Fix issues found by Biome
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jun 5, 2024
1 parent e39844e commit 1d6b663
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
6 changes: 3 additions & 3 deletions packages/react-date-picker/src/DateInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ describe('DateInput', () => {

const { container } = render(<DateInput {...defaultProps} onChange={onChange} value={date} />);

const customInputs = container.querySelectorAll('input[data-input]');
const customInputs = Array.from(container.querySelectorAll('input[data-input]'));

customInputs.forEach((customInput) => {
for (const customInput of customInputs) {
fireEvent.change(customInput, { target: { value: '' } });
});
}

expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(null, false);
Expand Down
14 changes: 6 additions & 8 deletions packages/react-date-picker/src/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function getValue(

const valueDate = toDate(rawValue);

if (isNaN(valueDate.getTime())) {
if (Number.isNaN(valueDate.getTime())) {
throw new Error(`Invalid date: ${value}`);
}

Expand Down Expand Up @@ -147,7 +147,7 @@ function renderCustomInputs(
<Divider key={`separator_${index}`}>{element}</Divider>
);
arr.push(divider);
const currentMatch = matches && matches[index];
const currentMatch = matches?.[index];

if (currentMatch) {
const renderFunction =
Expand Down Expand Up @@ -405,7 +405,7 @@ export default function DateInput({
return;
}

const isNumberKey = !isNaN(Number(key));
const isNumberKey = !Number.isNaN(Number(key));

if (!isNumberKey) {
return;
Expand Down Expand Up @@ -455,12 +455,10 @@ export default function DateInput({
].filter(filterBoolean);

const values: Record<string, number> = {};
formElements.forEach((formElement) => {
for (const formElement of formElements) {
values[formElement.name] =
'valueAsNumber' in formElement
? formElement.valueAsNumber
: Number((formElement as unknown as HTMLInputElement).value);
});
'valueAsNumber' in formElement ? formElement.valueAsNumber : Number(formElement.value);
}

const isEveryValueEmpty = formElements.every((formElement) => !formElement.value);

Expand Down
2 changes: 1 addition & 1 deletion packages/react-date-picker/src/DateInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function getSelectionString(input: HTMLInputElement) {

if ('getSelection' in window) {
const selection = window.getSelection();
return selection && selection.toString();
return selection?.toString();
}

return null;
Expand Down
32 changes: 16 additions & 16 deletions packages/react-date-picker/src/DateInput/MonthSelect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ describe('MonthSelect', () => {
const { container } = render(<MonthSelect {...defaultProps} />);

const select = container.querySelector('select') as HTMLSelectElement;
const options = select.querySelectorAll('option');
const options = Array.from(select.querySelectorAll('option'));

options.forEach((option) => {
for (const option of options) {
expect(option).not.toBeDisabled();
});
}
});

it('has all options enabled given minDate in a past year', () => {
Expand All @@ -138,11 +138,11 @@ describe('MonthSelect', () => {
);

const select = container.querySelector('select') as HTMLSelectElement;
const options = select.querySelectorAll('option[value]');
const options = Array.from(select.querySelectorAll('option[value]'));

options.forEach((option) => {
for (const option of options) {
expect(option).not.toBeDisabled();
});
}
});

it('has first (month in minDate) options disabled given minDate in a current year', () => {
Expand All @@ -154,13 +154,13 @@ describe('MonthSelect', () => {
const options = Array.from(select.querySelectorAll('option')).slice(1); // Getting rid of "--" option

// January - June
options.slice(0, 6).forEach((option) => {
for (const option of options.slice(0, 6)) {
expect(option).toBeDisabled();
});
}
// July - December
options.slice(6).forEach((option) => {
for (const option of options.slice(6)) {
expect(option).not.toBeDisabled();
});
}
});

it('has all options enabled given maxDate in a future year', () => {
Expand All @@ -171,9 +171,9 @@ describe('MonthSelect', () => {
const select = container.querySelector('select') as HTMLSelectElement;
const options = Array.from(select.querySelectorAll('option')).slice(1); // Getting rid of "--" option

options.forEach((option) => {
for (const option of options) {
expect(option).not.toBeDisabled();
});
}
});

it('has last (month in maxDate) options disabled given maxDate in a current year', () => {
Expand All @@ -185,12 +185,12 @@ describe('MonthSelect', () => {
const options = Array.from(select.querySelectorAll('option')).slice(1); // Getting rid of "--" option

// January - July
options.slice(0, 7).forEach((option) => {
for (const option of options.slice(0, 7)) {
expect(option).not.toBeDisabled();
});
}
// August - December
options.slice(7).forEach((option) => {
for (const option of options.slice(7)) {
expect(option).toBeDisabled();
});
}
});
});
6 changes: 3 additions & 3 deletions packages/react-date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,18 +477,18 @@ export default function DatePicker(props: DatePickerProps) {
closeCalendar({ reason: 'outsideAction' });
}
},
[calendarWrapper, closeCalendar, wrapper],
[closeCalendar],
);

const handleOutsideActionListeners = useCallback(
(shouldListen = isOpen) => {
outsideActionEvents.forEach((event) => {
for (const event of outsideActionEvents) {
if (shouldListen) {
document.addEventListener(event, onOutsideAction);
} else {
document.removeEventListener(event, onOutsideAction);
}
});
}

if (shouldListen) {
document.addEventListener('keydown', onKeyDown);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-date-picker/src/shared/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('safeMin', () => {
it('returns Infinity given no values', () => {
const result = safeMin();

expect(result).toBe(Infinity);
expect(result).toBe(Number.POSITIVE_INFINITY);
});

it('returns the smallest value given valid numbers', () => {
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('safeMax', () => {
it('returns -Infinity given no values', () => {
const result = safeMax();

expect(result).toBe(-Infinity);
expect(result).toBe(Number.NEGATIVE_INFINITY);
});

it('returns the largest value given valid numbers', () => {
Expand Down

0 comments on commit 1d6b663

Please sign in to comment.