Skip to content

Commit 0cba1e3

Browse files
committed
refactor: 优化 prettier 配置
1 parent 5d7d8f8 commit 0cba1e3

File tree

10 files changed

+148
-28
lines changed

10 files changed

+148
-28
lines changed

.prettierrc.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,18 @@
1313
"semi": true,
1414
"arrowParens": "avoid",
1515
"trailingComma": "none",
16-
"endOfLine": "auto"
16+
"endOfLine": "auto",
17+
"bracketSameLine": true,
18+
"plugins": [
19+
"@ianvs/prettier-plugin-sort-imports",
20+
"prettier-plugin-packagejson"
21+
],
22+
"importOrder": [
23+
"<BUILTIN_MODULES>",
24+
"<THIRD_PARTY_MODULES>",
25+
"",
26+
"^@/(.*)$",
27+
"",
28+
"^[./]"
29+
]
1730
}

package.json

+24-23
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@
44
"private": true,
55
"description": "Web site created using create-react-app with craco",
66
"scripts": {
7-
"prepare": "husky install",
8-
"start": "craco start",
7+
"analyze": "cross-env ANALYZE=TRUE craco build",
98
"build": "craco build",
10-
"analyze": "cross-env ANALYZE=TRUE craco build"
9+
"prepare": "husky install",
10+
"start": "craco start"
11+
},
12+
"lint-staged": {
13+
"src/**/*.{js,ts,tsx}": "eslint --fix",
14+
"src/**/*": "prettier --write --ignore-unknown",
15+
"src/**/*.{css,scss}": "stylelint"
16+
},
17+
"browserslist": {
18+
"production": [
19+
">0.2%",
20+
"not dead",
21+
"not op_mini all"
22+
],
23+
"development": [
24+
"last 1 chrome version",
25+
"last 1 firefox version",
26+
"last 1 safari version"
27+
]
1128
},
1229
"dependencies": {
1330
"classnames": "^2.3.2",
@@ -33,6 +50,7 @@
3350
"husky": "^8.0.3",
3451
"lint-staged": "^13.1.2",
3552
"prettier": "^2.8.4",
53+
"prettier-plugin-packagejson": "^2.4.9",
3654
"react-scripts": "^5.0.1",
3755
"sass": "^1.58.3",
3856
"speed-measure-webpack-plugin": "^1.5.0",
@@ -43,23 +61,6 @@
4361
"webpack-bundle-analyzer": "^4.8.0",
4462
"webpack-subresource-integrity": "^5.1.0"
4563
},
46-
"browserslist": {
47-
"production": [
48-
">0.2%",
49-
"not dead",
50-
"not op_mini all"
51-
],
52-
"development": [
53-
"last 1 chrome version",
54-
"last 1 firefox version",
55-
"last 1 safari version"
56-
]
57-
},
58-
"cracoConfig": "./config/craco.js",
59-
"lint-staged": {
60-
"src/**/*.{js,ts,tsx}": "eslint --fix",
61-
"src/**/*": "prettier --write --ignore-unknown",
62-
"src/**/*.{css,scss}": "stylelint"
63-
},
64-
"packageManager": "[email protected]"
65-
}
64+
"packageManager": "[email protected]",
65+
"cracoConfig": "./config/craco.js"
66+
}

pnpm-lock.yaml

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

src/App.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { BrowserRouter, Routes, Route } from 'react-router-dom';
2+
import { BrowserRouter, Route, Routes } from 'react-router-dom';
3+
34
import Layout from './layouts/Basic';
45
import NotFound from './pages/Error/404';
56
import routes from './routes';

src/components/Link/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { type PropsWithChildren } from 'react';
2+
23
import styles from './index.scss';
34

45
interface Props {

src/components/Logo/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
2+
23
import logo from '@/assets/images/logo.svg';
4+
35
import styles from './index.scss';
46

57
function Logo(): JSX.Element {

src/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom/client';
3+
34
import App from './App';
5+
46
import './styles/global.scss';
57

68
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);

src/layouts/Basic/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { type PropsWithChildren } from 'react';
2+
23
import styles from './index.scss';
34

45
function Layout(props: PropsWithChildren): JSX.Element {

src/pages/Home/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
2-
import { Logo, Link } from '@/components';
2+
3+
import { Link, Logo } from '@/components';
4+
35
import styles from './index.scss';
46

57
function Home(): JSX.Element {

src/routes.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PathRouteProps } from 'react-router-dom';
2+
23
import Home from './pages/Home';
34

45
interface Route extends PathRouteProps {
@@ -9,8 +10,8 @@ interface Route extends PathRouteProps {
910
const routes: Route[] = [
1011
{
1112
path: '/',
12-
page: Home,
13-
},
13+
page: Home
14+
}
1415
];
1516

1617
export default routes;

0 commit comments

Comments
 (0)