Skip to content

Commit 740b1dd

Browse files
authored
chore: use prettier for the code formatter (#737)
* chore: use prettier for the code formatter * chore: respect current code-format preferences * chore: remove an unused prettirerc
1 parent 7d8d28c commit 740b1dd

Some content is hidden

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

43 files changed

+1027
-1004
lines changed

.babelrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ module.exports = {
88
presets: [['babel-preset-jason', { modules: false }]],
99
},
1010
},
11-
}
11+
};

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parser: babel-eslint
22
extends:
33
- jason/react
44
- plugin:jsx-a11y/recommended
5+
- prettier
56
settings:
67
react:
78
version: detect

.github/ISSUE_TEMPLATE/bug-report.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ about: Something isn't working as expected.
88
<!-- ... -->
99

1010
> What is the expected behavior?
11+
1112
<!-- If your use case is complicated, please be as descriptive as possible. -->
1213

1314
<!-- ... -->

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/node_modules
2+
www/.cache/
3+
www/public/
4+
lib
5+
*.md

.storybook/config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { configure, addDecorator } from '@storybook/react';
22
import React from 'react';
33

4-
addDecorator(
5-
storyFn => <React.StrictMode>{storyFn()}</React.StrictMode>,
6-
)
4+
addDecorator((storyFn) => <React.StrictMode>{storyFn()}</React.StrictMode>);
75

86
function loadStories() {
97
require('../stories');

.storybook/main.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ const { plugins, rules } = require('webpack-atoms');
33
module.exports = {
44
webpackFinal: (config) => {
55
config.module = {
6-
rules: [
7-
rules.js(),
8-
rules.astroturf(),
9-
rules.css({ extract: false }),
10-
],
6+
rules: [rules.js(), rules.astroturf(), rules.css({ extract: false })],
117
};
128

13-
config.plugins.push(
14-
plugins.extractCss({ disable: true })
15-
)
9+
config.plugins.push(plugins.extractCss({ disable: true }));
1610

1711
return config;
1812
},

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "12.19"
4+
- '12.19'
55
env:
66
- REACT_DIST=16
77
- REACT_DIST=17

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
"build:pick": "cherry-pick --cwd=lib --input-dir=../src --cjs-dir=cjs --esm-dir=esm",
1616
"build:dist": "cross-env BABEL_ENV=esm rollup -c",
1717
"bootstrap": "yarn && yarn --cwd www",
18-
"lint": "eslint .",
18+
"fix": "run-s fix:eslint fix:prettier",
19+
"fix:eslint": "yarn lint:eslint --fix",
20+
"fix:prettier": "yarn lint:prettier --write",
21+
"lint": "run-p lint:*",
22+
"lint:eslint": "eslint .",
23+
"lint:prettier": "prettier . --check",
1924
"release": "release",
2025
"release:next": "release --preid beta --tag next",
2126
"deploy-docs": "yarn --cwd www run deploy",
@@ -91,7 +96,8 @@
9196
"eslint-plugin-react": "^7.19.0",
9297
"eslint-plugin-react-hooks": "^3.0.0",
9398
"jest": "^25.3.0",
94-
"prettier": "^2.0.4",
99+
"npm-run-all": "^4.1.5",
100+
"prettier": "^2.3.1",
95101
"react": "^17.0.1",
96102
"react-dom": "^17.0.1",
97103
"release-script": "^1.0.2",

prettier.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
singleQuote: true,
3+
};

rollup.config.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ const input = './src/index.js';
99
const name = 'ReactTransitionGroup';
1010
const globals = {
1111
react: 'React',
12-
'react-dom': 'ReactDOM'
12+
'react-dom': 'ReactDOM',
1313
};
1414

1515
const babelOptions = {
1616
exclude: /node_modules/,
17-
runtimeHelpers: true
18-
}
17+
runtimeHelpers: true,
18+
};
1919

2020
const commonjsOptions = {
2121
include: /node_modules/,
2222
namedExports: {
23-
'prop-types': ['object', 'oneOfType', 'element', 'bool', 'func']
24-
}
23+
'prop-types': ['object', 'oneOfType', 'element', 'bool', 'func'],
24+
},
2525
};
2626

2727
export default [
@@ -31,16 +31,16 @@ export default [
3131
file: './lib/dist/react-transition-group.js',
3232
format: 'umd',
3333
name,
34-
globals
34+
globals,
3535
},
3636
external: Object.keys(globals),
3737
plugins: [
3838
nodeResolve(),
3939
babel(babelOptions),
4040
commonjs(commonjsOptions),
4141
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
42-
sizeSnapshot()
43-
]
42+
sizeSnapshot(),
43+
],
4444
},
4545

4646
{
@@ -49,7 +49,7 @@ export default [
4949
file: './lib/dist/react-transition-group.min.js',
5050
format: 'umd',
5151
name,
52-
globals
52+
globals,
5353
},
5454
external: Object.keys(globals),
5555
plugins: [
@@ -58,7 +58,7 @@ export default [
5858
commonjs(commonjsOptions),
5959
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
6060
sizeSnapshot(),
61-
terser()
62-
]
63-
}
61+
terser(),
62+
],
63+
},
6464
];

src/CSSTransition.js

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import React from 'react';
77
import Transition from './Transition';
88
import { classNamesShape } from './utils/PropTypes';
99

10-
const addClass = (node, classes) => node && classes && classes.split(' ').forEach(c => addOneClass(node, c));
11-
const removeClass = (node, classes) => node && classes && classes.split(' ').forEach(c => removeOneClass(node, c));
10+
const addClass = (node, classes) =>
11+
node && classes && classes.split(' ').forEach((c) => addOneClass(node, c));
12+
const removeClass = (node, classes) =>
13+
node && classes && classes.split(' ').forEach((c) => removeOneClass(node, c));
1214

1315
/**
1416
* A transition component inspired by the excellent
@@ -81,91 +83,90 @@ const removeClass = (node, classes) => node && classes && classes.split(' ').for
8183
*/
8284
class CSSTransition extends React.Component {
8385
static defaultProps = {
84-
classNames: ''
85-
}
86+
classNames: '',
87+
};
8688

8789
appliedClasses = {
8890
appear: {},
8991
enter: {},
9092
exit: {},
91-
}
93+
};
9294

9395
onEnter = (maybeNode, maybeAppearing) => {
94-
const [node, appearing] = this.resolveArguments(maybeNode, maybeAppearing)
96+
const [node, appearing] = this.resolveArguments(maybeNode, maybeAppearing);
9597
this.removeClasses(node, 'exit');
9698
this.addClass(node, appearing ? 'appear' : 'enter', 'base');
9799

98100
if (this.props.onEnter) {
99-
this.props.onEnter(maybeNode, maybeAppearing)
101+
this.props.onEnter(maybeNode, maybeAppearing);
100102
}
101-
}
103+
};
102104

103105
onEntering = (maybeNode, maybeAppearing) => {
104-
const [node, appearing] = this.resolveArguments(maybeNode, maybeAppearing)
106+
const [node, appearing] = this.resolveArguments(maybeNode, maybeAppearing);
105107
const type = appearing ? 'appear' : 'enter';
106-
this.addClass(node, type, 'active')
108+
this.addClass(node, type, 'active');
107109

108110
if (this.props.onEntering) {
109-
this.props.onEntering(maybeNode, maybeAppearing)
111+
this.props.onEntering(maybeNode, maybeAppearing);
110112
}
111-
}
113+
};
112114

113115
onEntered = (maybeNode, maybeAppearing) => {
114-
const [node, appearing] = this.resolveArguments(maybeNode, maybeAppearing)
115-
const type = appearing ? 'appear' : 'enter'
116+
const [node, appearing] = this.resolveArguments(maybeNode, maybeAppearing);
117+
const type = appearing ? 'appear' : 'enter';
116118
this.removeClasses(node, type);
117119
this.addClass(node, type, 'done');
118120

119121
if (this.props.onEntered) {
120-
this.props.onEntered(maybeNode, maybeAppearing)
122+
this.props.onEntered(maybeNode, maybeAppearing);
121123
}
122-
}
124+
};
123125

124126
onExit = (maybeNode) => {
125-
const [node] = this.resolveArguments(maybeNode)
127+
const [node] = this.resolveArguments(maybeNode);
126128
this.removeClasses(node, 'appear');
127129
this.removeClasses(node, 'enter');
128-
this.addClass(node, 'exit', 'base')
130+
this.addClass(node, 'exit', 'base');
129131

130132
if (this.props.onExit) {
131-
this.props.onExit(maybeNode)
133+
this.props.onExit(maybeNode);
132134
}
133-
}
135+
};
134136

135137
onExiting = (maybeNode) => {
136-
const [node] = this.resolveArguments(maybeNode)
137-
this.addClass(node, 'exit', 'active')
138+
const [node] = this.resolveArguments(maybeNode);
139+
this.addClass(node, 'exit', 'active');
138140

139141
if (this.props.onExiting) {
140-
this.props.onExiting(maybeNode)
142+
this.props.onExiting(maybeNode);
141143
}
142-
}
144+
};
143145

144146
onExited = (maybeNode) => {
145-
const [node] = this.resolveArguments(maybeNode)
147+
const [node] = this.resolveArguments(maybeNode);
146148
this.removeClasses(node, 'exit');
147149
this.addClass(node, 'exit', 'done');
148150

149151
if (this.props.onExited) {
150-
this.props.onExited(maybeNode)
152+
this.props.onExited(maybeNode);
151153
}
152-
}
154+
};
153155

154156
// when prop `nodeRef` is provided `node` is excluded
155-
resolveArguments = (maybeNode, maybeAppearing) => this.props.nodeRef
156-
? [this.props.nodeRef.current, maybeNode] // here `maybeNode` is actually `appearing`
157-
: [maybeNode, maybeAppearing] // `findDOMNode` was used
157+
resolveArguments = (maybeNode, maybeAppearing) =>
158+
this.props.nodeRef
159+
? [this.props.nodeRef.current, maybeNode] // here `maybeNode` is actually `appearing`
160+
: [maybeNode, maybeAppearing]; // `findDOMNode` was used
158161

159162
getClassNames = (type) => {
160163
const { classNames } = this.props;
161164
const isStringClassNames = typeof classNames === 'string';
162-
const prefix = isStringClassNames && classNames
163-
? `${classNames}-`
164-
: '';
165+
const prefix = isStringClassNames && classNames ? `${classNames}-` : '';
165166

166167
let baseClassName = isStringClassNames
167168
? `${prefix}${type}`
168-
: classNames[type]
169+
: classNames[type];
169170

170171
let activeClassName = isStringClassNames
171172
? `${baseClassName}-active`
@@ -178,9 +179,9 @@ class CSSTransition extends React.Component {
178179
return {
179180
baseClassName,
180181
activeClassName,
181-
doneClassName
182+
doneClassName,
182183
};
183-
}
184+
};
184185

185186
addClass(node, type, phase) {
186187
let className = this.getClassNames(type)[`${phase}ClassName`];
@@ -198,17 +199,17 @@ class CSSTransition extends React.Component {
198199
}
199200

200201
if (className) {
201-
this.appliedClasses[type][phase] = className
202-
addClass(node, className)
202+
this.appliedClasses[type][phase] = className;
203+
addClass(node, className);
203204
}
204205
}
205206

206207
removeClasses(node, type) {
207208
const {
208209
base: baseClassName,
209210
active: activeClassName,
210-
done: doneClassName
211-
} = this.appliedClasses[type]
211+
done: doneClassName,
212+
} = this.appliedClasses[type];
212213

213214
this.appliedClasses[type] = {};
214215

@@ -373,4 +374,4 @@ CSSTransition.propTypes = {
373374
onExited: PropTypes.func,
374375
};
375376

376-
export default CSSTransition
377+
export default CSSTransition;

0 commit comments

Comments
 (0)