Skip to content

Commit 1a983e6

Browse files
cijiugechucsr632
andauthored
chore: use prettier to format code (#82)
* chore: introduce prettier * chore: use husky to run pre-commit format * ci: add format * chore: ignore missing lib * format should ignore copied files * reset workflow Co-authored-by: csr632 <[email protected]>
1 parent 399ba8c commit 1a983e6

File tree

16 files changed

+79
-45
lines changed

16 files changed

+79
-45
lines changed

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
pnpm format

.prettierignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
packages/**/node_modules
2+
packages/**/dist
3+
packages/**/lib
4+
packages/playground-temp
5+
6+
packages/react-pages/src/client/jotai/index.js
7+
packages/react-pages/src/client/jotai/utils.js
8+
9+
doc-site/dist
10+
doc-site/node_modules
11+
12+
playground-report

doc-site/pages/_theme.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { createTheme, defaultSideNavs } from 'vite-pages-theme-doc'
33

4-
import Component404 from "./404";
4+
import Component404 from './404'
55

66
export default createTheme({
77
topNavs: [

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"license": "MIT",
77
"scripts": {
8+
"format": "prettier --write ./**/*.{js,ts,tsx}",
89
"ver": "pnpm recursive --filter create-vite-pages --filter vite-plugin-react-pages --filter vite-pages-theme-basic --filter vite-pages-theme-doc exec -- npm version",
910
"ver:p": "npm run ver -- patch",
1011
"ver:mi": "npm run ver -- minor",
@@ -19,7 +20,8 @@
1920
"test-debug": "pnpm test -- --debug",
2021
"build:docs": "pnpm --filter doc-site run ssr-for-deploy",
2122
"postinstall": "node ./scripts/linkBins.js",
22-
"install-test-deps": "playwright install --with-deps chromium"
23+
"install-test-deps": "playwright install --with-deps chromium",
24+
"prepare": "husky install"
2325
},
2426
"devDependencies": {
2527
"@playwright/test": "~1.23.4",
@@ -30,6 +32,8 @@
3032
"cross-env": "^7.0.3",
3133
"execa": "^5.1.1",
3234
"get-port": "^5.1.1",
35+
"husky": "^8.0.1",
36+
"prettier": "^2.7.1",
3337
"sirv": "^2.0.2",
3438
"slash": "^3.0.0",
3539
"typescript": "^4.7.4",

packages/playground/custom-find-pages/vite.config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ module.exports = {
2828
runtimeDataPaths[demoPath] = absolute
2929
const staticData = api.getStaticData(pageId)
3030
staticData[demoPath] = await helpers.extractStaticData(file)
31-
if (!staticData.title)
32-
staticData.title = `${componentName} Title`
31+
if (!staticData.title) staticData.title = `${componentName} Title`
3332
}
3433
)
3534

packages/playground/custom-find-pages2/pages/sub-path/index.tsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
* @sort 2
44
*/
55

6-
import React from 'react'
6+
import React from 'react'
77

8-
const Page = () => {
9-
return (
10-
<div>
11-
<h1>sub-path</h1>
12-
</div>
13-
)
14-
}
15-
16-
export default Page
17-
8+
const Page = () => {
9+
return (
10+
<div>
11+
<h1>sub-path</h1>
12+
</div>
13+
)
14+
}
15+
16+
export default Page

packages/playground/lib-monorepo/packages/demos/vite.demos.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ module.exports = {
2828
runtimeDataPaths[demoPath] = absolute
2929
const staticData = api.getStaticData(pageId)
3030
staticData[demoPath] = await helpers.extractStaticData(file)
31-
if (!staticData.title)
32-
staticData.title = `${componentName} Title`
31+
if (!staticData.title) staticData.title = `${componentName} Title`
3332
}
3433
)
3534

packages/react-pages/client.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import type { UseStaticData } from './clientTypes'
1010

1111
// access globalThis['__vite_pages_use_static_data'] lazily
1212
export const useStaticData: UseStaticData = (...params: any[]) => {
13-
const actualUseStaticData = (globalThis as any)['__vite_pages_use_static_data']
13+
const actualUseStaticData = (globalThis as any)[
14+
'__vite_pages_use_static_data'
15+
]
1416
return actualUseStaticData(...params)
1517
}
1618

packages/react-pages/src/client/PageLoader.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ const PageLoader = React.memo(({ routePath }: Props) => {
1212
const loadState = useAppState(routePath)
1313
const dataCache = useContext(dataCacheCtx)
1414

15-
return (
16-
<Theme
17-
loadState={loadState}
18-
loadedData={dataCache}
19-
/>
20-
)
15+
return <Theme loadState={loadState} loadedData={dataCache} />
2116
})
2217

2318
export default PageLoader
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import fs from 'fs-extra';
2-
import * as path from 'path';
1+
import fs from 'fs-extra'
2+
import * as path from 'path'
33

44
export class File {
5-
content: Promise<string> | null = null;
5+
content: Promise<string> | null = null
66

7-
constructor(readonly path: string, readonly base: string) { }
7+
constructor(readonly path: string, readonly base: string) {}
88

99
get relative() {
10-
return path.posix.relative(this.base, this.path);
10+
return path.posix.relative(this.base, this.path)
1111
}
1212

1313
get extname() {
14-
return path.posix.extname(this.path).slice(1);
14+
return path.posix.extname(this.path).slice(1)
1515
}
1616

1717
read() {
18-
return this.content || (this.content = fs.readFile(this.path, 'utf-8'));
18+
return this.content || (this.content = fs.readFile(this.path, 'utf-8'))
1919
}
2020
}

packages/theme-basic/src/layout/search.tsx

+13-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ const SiteSearch = ({ pagesStaticData }: Props) => {
2525
setFilteredData(search(pagesStaticData, ''))
2626
}, [pagesStaticData])
2727

28-
const onChange = useCallback((value, type, _) => {
29-
if (type === 'itemClick' || type === 'enter') {
30-
// user confirm search result
31-
history.push(value)
32-
} else if (type === 'change') {
33-
// user input search text
34-
setFilteredData(search(pagesStaticData, value))
35-
setSearchVal(value)
36-
}
37-
}, [pagesStaticData])
28+
const onChange = useCallback(
29+
(value, type, _) => {
30+
if (type === 'itemClick' || type === 'enter') {
31+
// user confirm search result
32+
history.push(value)
33+
} else if (type === 'change') {
34+
// user input search text
35+
setFilteredData(search(pagesStaticData, value))
36+
setSearchVal(value)
37+
}
38+
},
39+
[pagesStaticData]
40+
)
3841

3942
return (
4043
<Search

packages/theme-doc/src/Layout/TsInfo/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import type { TsInterfaceInfo } from 'vite-plugin-react-pages/clientTypes'
33

4-
import s from "./index.module.css";
4+
import s from './index.module.css'
55

66
interface Props {
77
data: TsInterfaceInfo

packages/theme-doc/src/Layout/renderMenu.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const renderMenuHelper = (isTopNav: boolean) =>
4343
{item.label}
4444
{rightIcon}
4545
</a>
46-
)
46+
),
4747
}
4848
}
4949

@@ -58,7 +58,7 @@ export const renderMenuHelper = (isTopNav: boolean) =>
5858
{item.label}
5959
{rightIcon}
6060
</Link>
61-
)
61+
),
6262
}
6363
}
6464

pnpm-lock.yaml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prettier.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ module.exports = {
22
trailingComma: 'es5',
33
semi: false,
44
singleQuote: true,
5+
endOfLine: 'lf',
56
}

test-setup/utils/fsUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function setupActualTestPlayground(
2727
return !file.includes('__tests__')
2828
},
2929
})
30-
return {playgroundPath: copyTo, restore}
30+
return { playgroundPath: copyTo, restore }
3131

3232
async function restore(subPath: string = 'pages') {
3333
await fs.copy(

0 commit comments

Comments
 (0)