Skip to content

Commit aa82e65

Browse files
Copilothi-ogawa
andcommitted
chore: setup oxfmt for formatting
Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
1 parent 4207c40 commit aa82e65

File tree

167 files changed

+834
-2244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+834
-2244
lines changed

.oxfmtrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"semi": false,
4+
"singleQuote": true
5+
}

eslint.config.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ import globals from 'globals'
99

1010
export default tseslint.config(
1111
{
12-
ignores: [
13-
'**/dist/**',
14-
'**/playground-temp/**',
15-
'**/temp/**',
16-
'packages/plugin-rsc/**',
17-
],
12+
ignores: ['**/dist/**', '**/playground-temp/**', '**/temp/**', 'packages/plugin-rsc/**'],
1813
},
1914
eslint.configs.recommended,
2015
...tseslint.configs.recommended,
@@ -65,10 +60,7 @@ export default tseslint.config(
6560
'error',
6661
{ allowArgumentsExplicitlyTypedAsAny: true },
6762
],
68-
'@typescript-eslint/no-empty-function': [
69-
'error',
70-
{ allow: ['arrowFunctions'] },
71-
],
63+
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
7264
'@typescript-eslint/no-empty-interface': 'off',
7365
'@typescript-eslint/no-explicit-any': 'off',
7466
'no-extra-semi': 'off',

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"scripts": {
1919
"preinstall": "npx only-allow pnpm",
2020
"postinstall": "simple-git-hooks",
21-
"format": "prettier --write --cache .",
21+
"format": "oxfmt",
2222
"lint": "eslint --cache .",
2323
"typecheck": "tsc -p scripts && tsc -p playground && tsc -p packages/plugin-react",
2424
"test": "pnpm run test-unit && pnpm run test-serve && pnpm run test-build && pnpm --filter ./packages/plugin-react-swc run test",
@@ -44,6 +44,7 @@
4444
"fs-extra": "^11.3.2",
4545
"globals": "^16.5.0",
4646
"lint-staged": "^16.2.7",
47+
"oxfmt": "^0.16.0",
4748
"picocolors": "^1.1.1",
4849
"playwright-chromium": "^1.57.0",
4950
"prettier": "^3.6.2",
@@ -58,8 +59,8 @@
5859
"pre-commit": "pnpm exec lint-staged --concurrent false"
5960
},
6061
"lint-staged": {
61-
"*": [
62-
"prettier --write --cache --ignore-unknown"
62+
"*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,vue,astro,svelte,json,jsonc}": [
63+
"oxfmt"
6364
],
6465
"packages/*/{src,types}/**/*.ts": [
6566
"eslint --cache --fix"

packages/common/refresh-runtime.js

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ function performReactRefresh() {
190190
failedRootsSnapshot.forEach((root) => {
191191
const helpers = helpersByRootSnapshot.get(root)
192192
if (helpers === undefined) {
193-
throw new Error(
194-
'Could not find helpers for a root. This is a bug in React Refresh.',
195-
)
193+
throw new Error('Could not find helpers for a root. This is a bug in React Refresh.')
196194
}
197195
if (!failedRoots.has(root)) {
198196
// No longer failed.
@@ -217,9 +215,7 @@ function performReactRefresh() {
217215
mountedRootsSnapshot.forEach((root) => {
218216
const helpers = helpersByRootSnapshot.get(root)
219217
if (helpers === undefined) {
220-
throw new Error(
221-
'Could not find helpers for a root. This is a bug in React Refresh.',
222-
)
218+
throw new Error('Could not find helpers for a root. This is a bug in React Refresh.')
223219
}
224220
if (!mountedRoots.has(root)) {
225221
// No longer mounted.
@@ -405,8 +401,7 @@ export function injectIntoGlobalHook(globalObject) {
405401
alternate.memoizedState.element != null &&
406402
mountedRoots.has(root)
407403

408-
const isMounted =
409-
current.memoizedState != null && current.memoizedState.element != null
404+
const isMounted = current.memoizedState != null && current.memoizedState.element != null
410405

411406
if (!wasMounted && isMounted) {
412407
// Mount a new root.
@@ -481,10 +476,7 @@ export function createSignatureFunctionForTransform() {
481476
// Set the signature for all types (even wrappers!) in case
482477
// they have no signatures of their own. This is to prevent
483478
// problems like https://github.com/facebook/react/issues/20417.
484-
if (
485-
type != null &&
486-
(typeof type === 'function' || typeof type === 'object')
487-
) {
479+
if (type != null && (typeof type === 'function' || typeof type === 'object')) {
488480
setSignature(type, key, forceReset, getCustomHooks)
489481
}
490482
return type
@@ -578,10 +570,7 @@ export function registerExportsForReactRefresh(filename, moduleExports) {
578570
register(exportValue, filename + ' export ' + key)
579571
} else if (isCompoundComponent(exportValue)) {
580572
for (const subKey in exportValue) {
581-
register(
582-
exportValue[subKey],
583-
filename + ' export ' + key + '-' + subKey,
584-
)
573+
register(exportValue[subKey], filename + ' export ' + key + '-' + subKey)
585574
}
586575
}
587576
}
@@ -604,28 +593,12 @@ const enqueueUpdate = debounce(async () => {
604593
performReactRefresh()
605594
}, 16)
606595

607-
export function validateRefreshBoundaryAndEnqueueUpdate(
608-
id,
609-
prevExports,
610-
nextExports,
611-
) {
596+
export function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
612597
const ignoredExports = window.__getReactRefreshIgnoredExports?.({ id }) ?? []
613-
if (
614-
predicateOnExport(
615-
ignoredExports,
616-
prevExports,
617-
(key) => key in nextExports,
618-
) !== true
619-
) {
598+
if (predicateOnExport(ignoredExports, prevExports, (key) => key in nextExports) !== true) {
620599
return 'Could not Fast Refresh (export removed)'
621600
}
622-
if (
623-
predicateOnExport(
624-
ignoredExports,
625-
nextExports,
626-
(key) => key in prevExports,
627-
) !== true
628-
) {
601+
if (predicateOnExport(ignoredExports, nextExports, (key) => key in prevExports) !== true) {
629602
return 'Could not Fast Refresh (new export)'
630603
}
631604

packages/common/refresh-utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ injectIntoGlobalHook(window);
1414
window.$RefreshReg$ = () => {};
1515
window.$RefreshSig$ = () => (type) => type;`
1616

17-
export const getPreambleCode = (base: string): string =>
18-
preambleCode.replace('__BASE__', base)
17+
export const getPreambleCode = (base: string): string => preambleCode.replace('__BASE__', base)
1918

2019
export function addRefreshWrapper(
2120
code: string,
@@ -41,9 +40,7 @@ if (import.meta.hot && !inWebWorker) {
4140
}
4241
4342
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
44-
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(
45-
id,
46-
)}, currentExports);
43+
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
4744
import.meta.hot.accept((nextExports) => {
4845
if (!nextExports) return;
4946
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(

packages/common/warning.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import type { BuildOptions, UserConfig } from 'vite'
22

3-
export const silenceUseClientWarning = (
4-
userConfig: UserConfig,
5-
): BuildOptions => ({
3+
export const silenceUseClientWarning = (userConfig: UserConfig): BuildOptions => ({
64
rollupOptions: {
75
onwarn(warning, defaultHandler) {
86
if (
97
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
10-
(warning.message.includes('use client') ||
11-
warning.message.includes('use server'))
8+
(warning.message.includes('use client') || warning.message.includes('use server'))
129
) {
1310
return
1411
}

packages/plugin-react-oxc/src/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ export default function viteReact(opts: Options = {}): Plugin[] {
5151
jsxRefreshExclude: exclude,
5252
},
5353
optimizeDeps: {
54-
include: [
55-
'react',
56-
'react-dom',
57-
jsxImportDevRuntime,
58-
jsxImportRuntime,
59-
],
54+
include: ['react', 'react-dom', jsxImportDevRuntime, jsxImportRuntime],
6055
rolldownOptions: { transform: { jsx: { runtime: 'automatic' } } },
6156
},
6257
}
@@ -134,9 +129,7 @@ export default function viteReact(opts: Options = {}): Plugin[] {
134129
const useFastRefresh =
135130
!skipFastRefresh &&
136131
!ssr &&
137-
(isJSX ||
138-
code.includes(jsxImportDevRuntime) ||
139-
code.includes(jsxImportRuntime))
132+
(isJSX || code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime))
140133
if (!useFastRefresh) return
141134

142135
const newCode = addRefreshWrapper(code, '@vitejs/plugin-react-oxc', id)

packages/plugin-react-swc/playground/emotion-plugin/__tests__/emotion-plugin.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { expect, test } from '@playwright/test'
2-
import {
3-
expectColor,
4-
setupBuildAndPreview,
5-
setupDevServer,
6-
setupWaitForLogs,
7-
} from '../../utils.ts'
2+
import { expectColor, setupBuildAndPreview, setupDevServer, setupWaitForLogs } from '../../utils.ts'
83

94
test('Emotion plugin build', async ({ page }) => {
105
const { testUrl, server } = await setupBuildAndPreview('emotion-plugin')
@@ -39,10 +34,7 @@ test('Emotion plugin HMR', async ({ page }) => {
3934
const code = page.locator('code')
4035
await expectColor(code, 'color', '#646cff')
4136

42-
editFile('src/Button.jsx', [
43-
'background-color: #d26ac2;',
44-
'background-color: #646cff;',
45-
])
37+
editFile('src/Button.jsx', ['background-color: #d26ac2;', 'background-color: #646cff;'])
4638
await waitForLogs('[vite] hot updated: /src/Button.jsx')
4739
await expect(button).toHaveText('count is 1')
4840
await expectColor(button, 'backgroundColor', '#646cff')

packages/plugin-react-swc/playground/emotion-plugin/src/App.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ export const App = () => (
88
<img src="/vite.svg" className="logo" alt="Vite logo" />
99
</a>
1010
<a href="https://emotion.sh/" target="_blank" rel="noreferrer">
11-
<img
12-
src="https://emotion.sh/logo-96x96.png"
13-
className="logo emotion"
14-
alt="Emotion logo"
15-
/>
11+
<img src="https://emotion.sh/logo-96x96.png" className="logo emotion" alt="Emotion logo" />
1612
</a>
1713
</div>
1814
<div className="card">
@@ -21,8 +17,6 @@ export const App = () => (
2117
Edit <StyledCode>src/Button.tsx</StyledCode> and save to test HMR
2218
</p>
2319
</div>
24-
<p className="read-the-docs">
25-
Click on the Vite and Emotion logos to learn more
26-
</p>
20+
<p className="read-the-docs">Click on the Vite and Emotion logos to learn more</p>
2721
</div>
2822
)

packages/plugin-react-swc/playground/emotion/__tests__/emotion.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { expect, test } from '@playwright/test'
2-
import {
3-
expectColor,
4-
setupBuildAndPreview,
5-
setupDevServer,
6-
setupWaitForLogs,
7-
} from '../../utils.ts'
2+
import { expectColor, setupBuildAndPreview, setupDevServer, setupWaitForLogs } from '../../utils.ts'
83

94
test('Emotion build', async ({ page }) => {
105
const { testUrl, server } = await setupBuildAndPreview('emotion')
@@ -39,10 +34,7 @@ test('Emotion HMR', async ({ page }) => {
3934
const code = page.locator('code')
4035
await expectColor(code, 'color', '#646cff')
4136

42-
editFile('src/Button.tsx', [
43-
'background-color: #d26ac2;',
44-
'background-color: #646cff;',
45-
])
37+
editFile('src/Button.tsx', ['background-color: #d26ac2;', 'background-color: #646cff;'])
4638
await waitForLogs('[vite] hot updated: /src/Button.tsx')
4739
await expect(button).toHaveText('count is 1')
4840
await expectColor(button, 'backgroundColor', '#646cff')

0 commit comments

Comments
 (0)