Skip to content

Commit 53b6294

Browse files
authored
ci: add code style hook checksum (#301)
* chore: code style lint * test: git hook * chore: test rule * test: ci * chore: update * fix: code style * chore: update code style npm run prettier * chore: update config * chore: update config
1 parent ca4067a commit 53b6294

File tree

12 files changed

+92
-113
lines changed

12 files changed

+92
-113
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ module.exports = {
1414
'jsx-a11y/label-has-for': 0,
1515
'jsx-a11y/no-noninteractive-tabindex': 0,
1616
'import/no-extraneous-dependencies': 0,
17+
'@typescript-eslint/consistent-type-exports': 2,
1718
},
1819
};

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install lint-staged

docs/examples/_util/motionUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion';
1+
import type { CSSMotionProps, MotionEndEventHandler, MotionEventHandler } from 'rc-motion';
22

33
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
44
const getRealHeight: MotionEventHandler = (node) => ({ height: node.scrollHeight, opacity: 1 });

docs/examples/custom-icon.tsx

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as React from 'react';
21
import Collapse, { Panel } from 'rc-collapse';
3-
import motion from './_util/motionUtil';
2+
import * as React from 'react';
43
import '../../assets/index.less';
4+
import motion from './_util/motionUtil';
55

66
const initLength = 3;
77

@@ -48,40 +48,32 @@ const App: React.FC = () => {
4848

4949
const time = random();
5050

51-
const panelItems = Array
52-
.from<object, React.ReactNode>(
53-
{ length: initLength },
54-
(_, i) => {
55-
const key = i + 1;
56-
return (
57-
<Panel
58-
header={`This is panel header ${key}`}
59-
key={key}
60-
>
61-
<p>{text.repeat(time)}</p>
62-
</Panel>
63-
)
64-
})
65-
.concat(
66-
<Panel header={`This is panel header ${initLength + 1}`} key={initLength + 1}>
67-
<Collapse defaultActiveKey="1" expandIcon={expandIcon}>
68-
<Panel header="This is panel nest panel" key="1" id="header-test">
69-
<p>{text}</p>
70-
</Panel>
71-
</Collapse>
72-
</Panel>,
73-
<Panel header={`This is panel header ${initLength + 2}`} key={initLength + 2}>
74-
<Collapse defaultActiveKey="1">
75-
<Panel header="This is panel nest panel" key="1" id="another-test">
76-
<form>
77-
<label htmlFor="test">Name:&nbsp;</label>
78-
<input type="text" id="test" />
79-
</form>
80-
</Panel>
81-
</Collapse>
51+
const panelItems = Array.from<object, React.ReactNode>({ length: initLength }, (_, i) => {
52+
const key = i + 1;
53+
return (
54+
<Panel header={`This is panel header ${key}`} key={key}>
55+
<p>{text.repeat(time)}</p>
8256
</Panel>
8357
);
84-
58+
}).concat(
59+
<Panel header={`This is panel header ${initLength + 1}`} key={initLength + 1}>
60+
<Collapse defaultActiveKey="1" expandIcon={expandIcon}>
61+
<Panel header="This is panel nest panel" key="1" id="header-test">
62+
<p>{text}</p>
63+
</Panel>
64+
</Collapse>
65+
</Panel>,
66+
<Panel header={`This is panel header ${initLength + 2}`} key={initLength + 2}>
67+
<Collapse defaultActiveKey="1">
68+
<Panel header="This is panel nest panel" key="1" id="another-test">
69+
<form>
70+
<label htmlFor="test">Name:&nbsp;</label>
71+
<input type="text" id="test" />
72+
</form>
73+
</Panel>
74+
</Collapse>
75+
</Panel>,
76+
);
8577

8678
const tools = (
8779
<>
@@ -90,7 +82,7 @@ const App: React.FC = () => {
9082
</button>
9183
<br />
9284
<br />
93-
<button type="button" onClick={() => setAccordion(prev => !prev)}>
85+
<button type="button" onClick={() => setAccordion((prev) => !prev)}>
9486
{accordion ? 'Mode: accordion' : 'Mode: collapse'}
9587
</button>
9688
<br />
@@ -101,7 +93,7 @@ const App: React.FC = () => {
10193
<br />
10294
<br />
10395
</>
104-
)
96+
);
10597

10698
return (
10799
<>
@@ -116,7 +108,7 @@ const App: React.FC = () => {
116108
{panelItems}
117109
</Collapse>
118110
</>
119-
)
120-
}
111+
);
112+
};
121113

122114
export default App;

docs/examples/fragment.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import Collapse, { Panel } from 'rc-collapse';
12
import * as React from 'react';
23
import { Fragment } from 'react';
3-
import Collapse, { Panel } from 'rc-collapse';
44
import '../../assets/index.less';
55

66
const App = () => (

docs/examples/simple.tsx

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as React from 'react';
21
import type { CollapseProps } from 'rc-collapse';
32
import Collapse, { Panel } from 'rc-collapse';
4-
import motion from './_util/motionUtil';
3+
import * as React from 'react';
54
import '../../assets/index.less';
5+
import motion from './_util/motionUtil';
66

77
const initLength = 3;
88

@@ -50,65 +50,44 @@ const App: React.FC = () => {
5050

5151
const time = random();
5252

53-
const panelItems = Array
54-
.from<object, React.ReactNode>(
55-
{ length: initLength },
56-
(_, i) => {
57-
const key = i + 1;
58-
return (
59-
<Panel
60-
header={`This is panel header ${key}`}
61-
key={key}
62-
>
63-
<p>{text.repeat(time)}</p>
64-
</Panel>
65-
)
66-
})
67-
.concat(
68-
<Panel
69-
header={`This is panel header ${initLength + 1}`}
70-
key={initLength + 1}
71-
>
72-
<Collapse defaultActiveKey="1" expandIcon={expandIcon}>
73-
<Panel
74-
header="This is panel nest panel"
75-
key="1"
76-
id="header-test"
77-
>
78-
<p>{text}</p>
79-
</Panel>
80-
</Collapse>
81-
</Panel>,
82-
<Panel
83-
header={`This is panel header ${initLength + 2}`}
84-
key={initLength + 2}
85-
>
86-
<Collapse defaultActiveKey="1">
87-
<Panel
88-
header="This is panel nest panel"
89-
key="1"
90-
id="another-test"
91-
>
92-
<form>
93-
<label htmlFor="test">Name:&nbsp;</label>
94-
<input type="text" id="test" />
95-
</form>
96-
</Panel>
97-
</Collapse>
98-
</Panel>,
99-
<Panel
100-
header={`This is panel header ${initLength + 3}`}
101-
key={initLength + 3}
102-
extra={<span>Extra Node</span>}
103-
>
104-
<p>Panel with extra</p>
53+
const panelItems = Array.from<object, React.ReactNode>({ length: initLength }, (_, i) => {
54+
const key = i + 1;
55+
return (
56+
<Panel header={`This is panel header ${key}`} key={key}>
57+
<p>{text.repeat(time)}</p>
10558
</Panel>
10659
);
60+
}).concat(
61+
<Panel header={`This is panel header ${initLength + 1}`} key={initLength + 1}>
62+
<Collapse defaultActiveKey="1" expandIcon={expandIcon}>
63+
<Panel header="This is panel nest panel" key="1" id="header-test">
64+
<p>{text}</p>
65+
</Panel>
66+
</Collapse>
67+
</Panel>,
68+
<Panel header={`This is panel header ${initLength + 2}`} key={initLength + 2}>
69+
<Collapse defaultActiveKey="1">
70+
<Panel header="This is panel nest panel" key="1" id="another-test">
71+
<form>
72+
<label htmlFor="test">Name:&nbsp;</label>
73+
<input type="text" id="test" />
74+
</form>
75+
</Panel>
76+
</Collapse>
77+
</Panel>,
78+
<Panel
79+
header={`This is panel header ${initLength + 3}`}
80+
key={initLength + 3}
81+
extra={<span>Extra Node</span>}
82+
>
83+
<p>Panel with extra</p>
84+
</Panel>,
85+
);
10786

10887
const handleCollapsibleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
10988
const values = [undefined, 'header', 'icon', 'disabled'];
110-
setCollapsible(values[e.target.value])
111-
}
89+
setCollapsible(values[e.target.value]);
90+
};
11291

11392
const tools = (
11493
<>
@@ -117,7 +96,7 @@ const App: React.FC = () => {
11796
</button>
11897
<br />
11998
<br />
120-
<button type="button" onClick={() => setAccordion(prev => !prev)}>
99+
<button type="button" onClick={() => setAccordion((prev) => !prev)}>
121100
{accordion ? 'Mode: accordion' : 'Mode: collapse'}
122101
</button>
123102
<br />
@@ -138,7 +117,7 @@ const App: React.FC = () => {
138117
<br />
139118
<br />
140119
</>
141-
)
120+
);
142121

143122
return (
144123
<>
@@ -154,7 +133,7 @@ const App: React.FC = () => {
154133
{panelItems}
155134
</Collapse>
156135
</>
157-
)
158-
}
136+
);
137+
};
159138

160139
export default App;

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
"compile": "father build && lessc assets/index.less assets/index.css",
3333
"coverage": "npm test -- --coverage",
3434
"lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",
35+
"prepare": "husky install",
3536
"prepublishOnly": "npm run compile && np --yolo --no-publish",
3637
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
3738
"start": "dumi dev",
3839
"test": "rc-test"
3940
},
41+
"lint-staged": {
42+
"**/*.{ts,tsx,js,jsx,json,md}": "npm run prettier"
43+
},
4044
"dependencies": {
4145
"@babel/runtime": "^7.10.1",
4246
"classnames": "2.x",
@@ -55,8 +59,10 @@
5559
"dumi": "^2.1.1",
5660
"eslint": "^7.11.0",
5761
"father": "^4.1.3",
62+
"husky": "^8.0.3",
5863
"jest": "^29.1.2",
5964
"less": "^3.12.2",
65+
"lint-staged": "^13.1.0",
6066
"np": "^6.0.0",
6167
"prettier": "^2.1.2",
6268
"rc-test": "^7.0.14",

src/Collapse.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
21
import classNames from 'classnames';
32
import toArray from 'rc-util/lib/Children/toArray';
43
import useMergedState from 'rc-util/lib/hooks/useMergedState';
5-
import CollapsePanel from './Panel';
4+
import React from 'react';
65
import type { CollapseProps, CollapsibleType } from './interface';
6+
import CollapsePanel from './Panel';
77

88
function getActiveKeysArray(activeKey: React.Key | React.Key[]) {
99
let currentActiveKey = activeKey;

src/Panel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React from 'react';
21
import classNames from 'classnames';
3-
import type { CollapsePanelProps } from './interface';
4-
import KeyCode from 'rc-util/lib/KeyCode';
52
import CSSMotion from 'rc-motion';
3+
import KeyCode from 'rc-util/lib/KeyCode';
4+
import React from 'react';
5+
import type { CollapsePanelProps } from './interface';
66
import PanelContent from './PanelContent';
77

88
const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((props, ref) => {

src/PanelContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from 'react';
21
import classnames from 'classnames';
2+
import React from 'react';
33
import type { CollapsePanelProps } from './interface';
44

55
const PanelContent = React.forwardRef<

0 commit comments

Comments
 (0)