Skip to content

Commit 5b59ad8

Browse files
authored
Use prettier (#169)
* Use prettier * width 100
1 parent 692dd47 commit 5b59ad8

File tree

15 files changed

+414
-140
lines changed

15 files changed

+414
-140
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"node": true
77
},
88
"rules": {
9+
"arrow-parens": "off",
910
"no-plusplus": "off",
1011
"react/require-default-props": "off",
1112
"react/jsx-filename-extension": ["error", { "extensions": [".js"] }],

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"build:umd:min": "cross-env MINIFY=1 webpack --config webpack.build.js",
1111
"build": "npm run clean && npm run build:commonjs",
1212
"bundle": "mkdir -p dist && npm run build:umd && npm run build:umd:min",
13+
"format": "prettier --write --single-quote --print-width 100 --trailing-comma all \"src/**/*.js\"",
1314
"lint": "eslint src",
15+
"precommit": "lint-staged",
1416
"preversion": "npm run lint && npm test && npm run build && npm run bundle && git add dist/ && git commit -m 'publish: Distribution'",
1517
"prepublish": "npm run build",
1618
"test": "jest",
@@ -59,7 +61,10 @@
5961
"eslint-plugin-import": "^2.2.0",
6062
"eslint-plugin-jsx-a11y": "^4.0.0",
6163
"eslint-plugin-react": "^6.2.1",
64+
"husky": "^0.13.3",
6265
"jest-cli": "^19.0.2",
66+
"lint-staged": "^3.4.0",
67+
"prettier": "^1.2.2",
6368
"react": "^15.0.0",
6469
"react-addons-test-utils": "^15.0.0",
6570
"react-dom": "^15.0.0",
@@ -79,5 +84,11 @@
7984
"roots": [
8085
"src"
8186
]
87+
},
88+
"lint-staged": {
89+
"src/**/*.js": [
90+
"prettier --single-quote --print-width 100 --trailing-comma all --write",
91+
"git add"
92+
]
8293
}
8394
}

src/components/Tab.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React, { Component } from 'react';
33
import cx from 'classnames';
44

55
export default class Tab extends Component {
6-
76
static defaultProps = {
87
className: 'ReactTabs__Tab',
98
disabledClassName: 'ReactTabs__Tab--disabled',
@@ -15,11 +14,7 @@ export default class Tab extends Component {
1514
};
1615

1716
static propTypes = {
18-
children: PropTypes.oneOfType([
19-
PropTypes.array,
20-
PropTypes.object,
21-
PropTypes.string,
22-
]),
17+
children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
2318
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
2419
disabled: PropTypes.bool,
2520
disabledClassName: PropTypes.string, // private
@@ -57,19 +52,20 @@ export default class Tab extends Component {
5752
selected,
5853
selectedClassName,
5954
tabRef,
60-
...attributes } = this.props;
55+
...attributes
56+
} = this.props;
6157

6258
return (
6359
<li
6460
{...attributes}
65-
className={cx(
66-
className,
67-
{
68-
[selectedClassName]: selected,
69-
[disabledClassName]: disabled,
70-
},
71-
)}
72-
ref={(node) => { this.node = node; if (tabRef) tabRef(node); }}
61+
className={cx(className, {
62+
[selectedClassName]: selected,
63+
[disabledClassName]: disabled,
64+
})}
65+
ref={node => {
66+
this.node = node;
67+
if (tabRef) tabRef(node);
68+
}}
7369
role="tab"
7470
id={id}
7571
aria-selected={selected ? 'true' : 'false'}

src/components/TabList.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,20 @@ import React, { Component } from 'react';
33
import cx from 'classnames';
44

55
export default class TabList extends Component {
6-
76
static defaultProps = {
87
className: 'ReactTabs__TabList',
98
};
109

1110
static propTypes = {
12-
children: PropTypes.oneOfType([
13-
PropTypes.object,
14-
PropTypes.array,
15-
]),
11+
children: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
1612
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
1713
};
1814

1915
render() {
20-
const {
21-
children,
22-
className,
23-
...attributes } = this.props;
16+
const { children, className, ...attributes } = this.props;
2417

2518
return (
26-
<ul
27-
{...attributes}
28-
className={cx(className)}
29-
role="tablist"
30-
>
19+
<ul {...attributes} className={cx(className)} role="tablist">
3120
{children}
3221
</ul>
3322
);

src/components/TabPanel.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React, { Component } from 'react';
33
import cx from 'classnames';
44

55
export default class TabPanel extends Component {
6-
76
static defaultProps = {
87
className: 'ReactTabs__TabPanel',
98
forceRender: false,
@@ -32,22 +31,20 @@ export default class TabPanel extends Component {
3231
selectedClassName,
3332
style,
3433
tabId,
35-
...attributes } = this.props;
34+
...attributes
35+
} = this.props;
3636

3737
return (
3838
<div
3939
{...attributes}
40-
className={cx(
41-
className,
42-
{
43-
[selectedClassName]: selected,
44-
},
45-
)}
40+
className={cx(className, {
41+
[selectedClassName]: selected,
42+
})}
4643
role="tabpanel"
4744
id={id}
4845
aria-labelledby={tabId}
4946
>
50-
{(forceRender || selected) ? children : null}
47+
{forceRender || selected ? children : null}
5148
</div>
5249
);
5350
}

src/components/Tabs.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import UncontrolledTabs from './UncontrolledTabs';
55
import { getTabsCount } from '../helpers/count';
66

77
export default class Tabs extends Component {
8-
98
static defaultProps = {
109
defaultFocus: false,
1110
forceRenderTabPanel: false,
@@ -38,9 +37,9 @@ export default class Tabs extends Component {
3837
Tabs.inUncontrolledMode(newProps) !== Tabs.inUncontrolledMode(this.props)
3938
) {
4039
throw new Error(
41-
`Switching between controlled mode (by using \`selectedIndex\`) and uncontrolled mode is not supported in \`Tabs\`.
40+
`Switching between controlled mode (by using \`selectedIndex\`) and uncontrolled mode is not supported in \`Tabs\`.
4241
For more information about controlled and uncontrolled mode of react-tabs see the README.`,
43-
);
42+
);
4443
}
4544
// Use a transactional update to prevent race conditions
4645
// when reading the state in copyPropsToState
@@ -70,7 +69,7 @@ For more information about controlled and uncontrolled mode of react-tabs see th
7069
}
7170

7271
this.setState(state);
73-
}
72+
};
7473

7574
// preserve the existing selectedIndex from state.
7675
// If the state has not selectedIndex, default to the defaultIndex or 0

src/components/UncontrolledTabs.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function isTabDisabled(node) {
1919
}
2020

2121
export default class UncontrolledTabs extends Component {
22-
2322
static defaultProps = {
2423
className: 'ReactTabs',
2524
focus: false,
@@ -129,7 +128,7 @@ export default class UncontrolledTabs extends Component {
129128
}
130129

131130
// Map children to dynamically setup refs
132-
return React.Children.map(children, (child) => {
131+
return React.Children.map(children, child => {
133132
// null happens when conditionally rendering TabPanel/Tab
134133
// see https://github.com/reactjs/react-tabs/issues/37
135134
if (child === null) {
@@ -144,12 +143,13 @@ export default class UncontrolledTabs extends Component {
144143

145144
// Figure out if the current focus in the DOM is set on a Tab
146145
// If it is we should keep the focus on the next selected tab
147-
const wasTabFocused = React.Children.toArray(child.props.children)
146+
const wasTabFocused = React.Children
147+
.toArray(child.props.children)
148148
.filter(tab => tab.type === Tab)
149149
.some((tab, i) => document.activeElement === this.getTab(i));
150150

151151
result = cloneElement(child, {
152-
children: React.Children.map(child.props.children, (tab) => {
152+
children: React.Children.map(child.props.children, tab => {
153153
// null happens when conditionally rendering TabPanel/Tab
154154
// see https://github.com/reactjs/react-tabs/issues/37
155155
if (tab === null) {
@@ -164,7 +164,9 @@ export default class UncontrolledTabs extends Component {
164164
const selected = selectedIndex === listIndex;
165165

166166
const props = {
167-
tabRef: (node) => { this.tabNodes[key] = node; },
167+
tabRef: node => {
168+
this.tabNodes[key] = node;
169+
},
168170
id: this.tabIds[listIndex],
169171
panelId: this.panelIds[listIndex],
170172
selected,
@@ -198,7 +200,7 @@ export default class UncontrolledTabs extends Component {
198200
});
199201
}
200202

201-
handleKeyDown = (e) => {
203+
handleKeyDown = e => {
202204
if (this.isTabFromContainer(e.target)) {
203205
let index = this.props.selectedIndex;
204206
let preventDefault = false;
@@ -222,9 +224,10 @@ export default class UncontrolledTabs extends Component {
222224
}
223225
};
224226

225-
handleClick = (e) => {
227+
handleClick = e => {
226228
let node = e.target;
227-
do { // eslint-disable-line no-cond-assign
229+
// eslint-disable-next-line no-cond-assign
230+
do {
228231
if (this.isTabFromContainer(node)) {
229232
if (isTabDisabled(node)) {
230233
return;
@@ -263,16 +266,16 @@ export default class UncontrolledTabs extends Component {
263266
render() {
264267
// Delete all known props, so they don't get added to DOM
265268
const {
266-
children,
267-
className,
268-
disabledTabClassName,
269-
focus,
270-
forceRenderTabPanel,
271-
onSelect,
272-
selectedIndex,
273-
selectedTabClassName,
274-
selectedTabPanelClassName,
275-
...attributes
269+
children,
270+
className,
271+
disabledTabClassName,
272+
focus,
273+
forceRenderTabPanel,
274+
onSelect,
275+
selectedIndex,
276+
selectedTabClassName,
277+
selectedTabPanelClassName,
278+
...attributes
276279
} = this.props;
277280

278281
return (
@@ -281,7 +284,9 @@ export default class UncontrolledTabs extends Component {
281284
className={cx(className)}
282285
onClick={this.handleClick}
283286
onKeyDown={this.handleKeyDown}
284-
ref={(node) => { this.node = node; }}
287+
ref={node => {
288+
this.node = node;
289+
}}
285290
data-tabs
286291
>
287292
{this.getChildren()}

src/components/__tests__/Tab-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Tab from '../Tab';
66
describe('<Tab />', () => {
77
beforeAll(() => {
88
// eslint-disable-next-line no-console
9-
console.error = (error) => {
9+
console.error = error => {
1010
throw new Error(error);
1111
};
1212
});

src/components/__tests__/TabList-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function hasClassAt(wrapper, index, className) {
1313
describe('<TabList />', () => {
1414
beforeAll(() => {
1515
// eslint-disable-next-line no-console
16-
console.error = (error) => {
16+
console.error = error => {
1717
throw new Error(error);
1818
};
1919
});
@@ -87,7 +87,9 @@ describe('<TabList />', () => {
8787
<Tabs defaultIndex={0}>
8888
<TabList>
8989
<Tab selectedClassName="active" disabledClassName="disabled">Foo</Tab>
90-
<Tab disabled selectedClassName="active" disabledClassName="disabled">Bar</Tab>
90+
<Tab disabled selectedClassName="active" disabledClassName="disabled">
91+
Bar
92+
</Tab>
9193
</TabList>
9294
<TabPanel>Foo</TabPanel>
9395
<TabPanel>Bar</TabPanel>

src/components/__tests__/TabPanel-test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TabPanel from '../TabPanel';
66
describe('<TabPanel />', () => {
77
beforeAll(() => {
88
// eslint-disable-next-line no-console
9-
console.error = (error) => {
9+
console.error = error => {
1010
throw new Error(error);
1111
};
1212
});
@@ -49,7 +49,11 @@ describe('<TabPanel />', () => {
4949
});
5050

5151
it('should support being selected with custom class name', () => {
52-
const wrapper = shallow(<TabPanel selected id="abcd" tabId="1234" selectedClassName="selected">Hola</TabPanel>);
52+
const wrapper = shallow(
53+
<TabPanel selected id="abcd" tabId="1234" selectedClassName="selected">
54+
Hola
55+
</TabPanel>,
56+
);
5357

5458
expect(wrapper.hasClass('ReactTabs__TabPanel')).toBe(true);
5559
expect(wrapper.hasClass('ReactTabs__TabPanel--selected')).toBe(false);
@@ -72,4 +76,3 @@ describe('<TabPanel />', () => {
7276
expect(wrapper.prop('role')).toBe('tabpanel');
7377
});
7478
});
75-

0 commit comments

Comments
 (0)