Skip to content

Commit

Permalink
Replace ESLint and Prettier with Biome
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jun 5, 2024
1 parent e39844e commit 5c29e39
Show file tree
Hide file tree
Showing 27 changed files with 234 additions and 1,535 deletions.
51 changes: 6 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Cache Yarn cache
uses: actions/cache@v4
env:
cache-name: yarn-cache
with:
path: ~/.yarn/berry/cache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Enable Corepack
run: corepack enable

- name: Install dependencies
run: yarn --immutable

- name: Build package
run: yarn build
- name: Setup Biome
uses: biomejs/setup-biome@v2

- name: Run tests
run: yarn lint
run: biome lint

typescript:
name: Type checking
Expand Down Expand Up @@ -88,29 +67,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Cache Yarn cache
uses: actions/cache@v4
env:
cache-name: yarn-cache
with:
path: ~/.yarn/berry/cache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Enable Corepack
run: corepack enable

- name: Install dependencies
run: yarn --immutable
- name: Setup Biome
uses: biomejs/setup-biome@v2

- name: Run formatting
run: yarn format
run: biome format

unit:
name: Unit tests
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarn lint-staged
yarn format --staged --no-errors-on-unmatched --write
3 changes: 0 additions & 3 deletions .lintstagedrc.json

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "eamodio.gitlens", "esbenp.prettier-vscode"],
"recommendations": ["biomejs.biome", "eamodio.gitlens"],
"unwantedRecommendations": ["dbaeumer.jshint"]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
"search.exclude": {
"**/.yarn": true
Expand Down
43 changes: 43 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.0/schema.json",
"files": {
"ignore": [".tsimp", "coverage", "dist", ".pnp.cjs", ".pnp.loader.mjs"]
},
"formatter": {
"lineWidth": 100,
"indentStyle": "space"
},
"linter": {
"rules": {
"complexity": {
"noUselessSwitchCase": "off"
},
"suspicious": {
"noConsoleLog": "warn"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
},
"overrides": [
{
"include": ["**/package.json"],
"formatter": {
"lineWidth": 1
}
},
{
"include": ["**/vite.config.ts"],
"linter": {
"rules": {
"suspicious": {
"noConsoleLog": "off"
}
}
}
}
]
}
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
"unit": "yarn workspaces foreach --all run unit"
},
"devDependencies": {
"husky": "^9.0.0",
"lint-staged": "^15.0.0",
"prettier": "^3.2.0"
},
"resolutions": {
"eslint-plugin-import": "npm:eslint-plugin-i@^2.28.0"
"husky": "^9.0.0"
},
"packageManager": "[email protected]"
}
2 changes: 0 additions & 2 deletions packages/react-date-picker/.eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions packages/react-date-picker/.eslintrc.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/react-date-picker/.prettierignore

This file was deleted.

8 changes: 3 additions & 5 deletions packages/react-date-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"build-js-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
"clean": "rimraf dist",
"copy-styles": "cpy 'src/**/*.css' dist",
"format": "prettier --check . --cache",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"format": "biome format",
"lint": "biome lint",
"prepack": "yarn clean && yarn build",
"test": "yarn lint && yarn tsc && yarn format && yarn unit",
"tsc": "tsc",
Expand Down Expand Up @@ -115,18 +115,16 @@
"update-input-width": "^1.4.0"
},
"devDependencies": {
"@biomejs/biome": "^1.8.0",
"@testing-library/dom": "^10.0.0",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^15.0.0",
"@testing-library/user-event": "^14.5.0",
"@types/node": "*",
"@types/react": "*",
"cpy-cli": "^5.0.0",
"eslint": "^8.56.0",
"eslint-config-wojtekmaj": "^1.0.0",
"happy-dom": "^12.6.0",
"nodemon": "^3.0.0",
"prettier": "^3.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^3.0.0",
Expand Down
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
23 changes: 9 additions & 14 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 @@ -143,11 +143,11 @@ function renderCustomInputs(

return placeholder.split(pattern).reduce<React.ReactNode[]>((arr, element, index) => {
const divider = element && (
// eslint-disable-next-line react/no-array-index-key
// biome-ignore lint/suspicious/noArrayIndexKey: index is stable here
<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 @@ -240,6 +240,7 @@ export default function DateInput({
setIsCalendarOpen(isCalendarOpenProps);
}, [isCalendarOpenProps]);

// biome-ignore lint/correctness/useExhaustiveDependencies: useEffect intentionally triggered on props change
useEffect(() => {
const nextValue = getDetailValueFrom({
value: valueProps,
Expand Down Expand Up @@ -405,7 +406,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 +456,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 Expand Up @@ -570,7 +569,6 @@ export default function DateInput({
key="day"
{...commonInputProps}
ariaLabel={dayAriaLabel}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={index === 0 && autoFocus}
inputRef={dayInput}
month={month}
Expand All @@ -593,7 +591,6 @@ export default function DateInput({
key="month"
{...commonInputProps}
ariaLabel={monthAriaLabel}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={index === 0 && autoFocus}
inputRef={monthSelect}
locale={locale}
Expand All @@ -612,7 +609,6 @@ export default function DateInput({
key="month"
{...commonInputProps}
ariaLabel={monthAriaLabel}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={index === 0 && autoFocus}
inputRef={monthInput}
placeholder={monthPlaceholder}
Expand All @@ -629,7 +625,6 @@ export default function DateInput({
key="year"
{...commonInputProps}
ariaLabel={yearAriaLabel}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={index === 0 && autoFocus}
inputRef={yearInput}
placeholder={yearPlaceholder}
Expand Down Expand Up @@ -668,7 +663,7 @@ export default function DateInput({
}

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
// biome-ignore lint/a11y/useKeyWithClickEvents: This interaction is designed for mouse users only
<div className={className} onClick={onClick}>
{renderNativeInput()}
{renderCustomInputsInternal()}
Expand Down
5 changes: 2 additions & 3 deletions packages/react-date-picker/src/DateInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { useEffect, useLayoutEffect } from 'react';
import clsx from 'clsx';
import updateInputWidth, { getFontShorthand } from 'update-input-width';

/* eslint-disable jsx-a11y/no-autofocus */

type InputProps = {
ariaLabel?: string;
autoFocus?: boolean;
Expand Down Expand Up @@ -95,7 +93,7 @@ function getSelectionString(input: HTMLInputElement) {

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

return null;
Expand Down Expand Up @@ -172,6 +170,7 @@ export default function Input({
<input
aria-label={ariaLabel}
autoComplete="off"
// biome-ignore lint/a11y/noAutofocus: This is up to developers' decision
autoFocus={autoFocus}
className={clsx(
`${className}__input`,
Expand Down
Loading

0 comments on commit 5c29e39

Please sign in to comment.