Skip to content

Commit 40e1aa9

Browse files
jfmengelsleo
authored andcommitted
Migrate linting from standard to XO (#53)
1 parent c5f21df commit 40e1aa9

File tree

9 files changed

+194
-202
lines changed

9 files changed

+194
-202
lines changed

.eslintrc.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# React Keyframes [![Build Status](https://travis-ci.org/zeit/react-keyframes.svg?branch=master)](https://travis-ci.org/zeit/react-keyframes)
1+
# React Keyframes
2+
3+
[![Build Status](https://travis-ci.org/zeit/react-keyframes.svg?branch=master)](https://travis-ci.org/zeit/react-keyframes)
4+
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
25

36
A React component for creating frame-based animations.
47

gulpfile.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
1-
const gulp = require('gulp');
2-
const del = require('del');
3-
const babel = require('gulp-babel');
4-
const eslint = require('gulp-eslint');
5-
const help = require('gulp-task-listing');
1+
const gulp = require('gulp')
2+
const del = require('del')
3+
const babel = require('gulp-babel')
4+
const help = require('gulp-task-listing')
65

7-
gulp.task('help', help);
6+
gulp.task('help', help)
87

9-
gulp.task('compile', function () {
8+
gulp.task('compile', () => {
109
return gulp.src('lib/**/*.js')
1110
.pipe(babel())
12-
.pipe(gulp.dest('build/lib'));
13-
});
11+
.pipe(gulp.dest('build/lib'))
12+
})
1413

15-
gulp.task('lint', function () {
16-
return gulp.src([
17-
'gulpfile.js',
18-
'test/*.js',
19-
'lib/**/*.js'
20-
])
21-
.pipe(eslint())
22-
.pipe(eslint.format())
23-
.pipe(eslint.failAfterError());
24-
});
14+
gulp.task('clean', () => {
15+
return del(['build'])
16+
})
2517

26-
gulp.task('clean', function () {
27-
return del(['build']);
28-
});
29-
30-
gulp.task('default', ['lint', 'compile']);
18+
gulp.task('default', ['compile'])

lib/frame.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { PropTypes } from 'react';
1+
import React, {PropTypes} from 'react'
22

33
export default class Frame extends React.Component {
44
static propTypes = {
55
children: PropTypes.any,
66
component: PropTypes.any,
7-
duration: PropTypes.number,
7+
duration: PropTypes.number, // eslint-disable-line react/no-unused-prop-types
88
onRender: PropTypes.func
99
};
1010

@@ -13,21 +13,23 @@ export default class Frame extends React.Component {
1313
onRender: () => {}
1414
};
1515

16-
componentDidMount () {
17-
this.props.onRender();
16+
componentDidMount() {
17+
this.props.onRender()
1818
}
1919

20-
componentDidUpdate () {
21-
this.props.onRender();
20+
componentDidUpdate() {
21+
this.props.onRender()
2222
}
2323

24-
render () {
25-
const { component } = this.props;
26-
const props = {};
27-
Object.keys(this.props).forEach((k) => {
28-
if (Frame.propTypes[k]) return;
29-
props[k] = this.props[k];
30-
});
31-
return React.createElement(component, props, this.props.children);
24+
render() {
25+
const {component} = this.props
26+
const props = {}
27+
Object.keys(this.props).forEach(k => {
28+
if (Frame.propTypes[k]) {
29+
return
30+
}
31+
props[k] = this.props[k]
32+
})
33+
return React.createElement(component, props, this.props.children)
3234
}
3335
}

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { default as Keyframes } from './keyframes';
2-
export { default as Frame } from './frame';
1+
export {default as Keyframes} from './keyframes'
2+
export {default as Frame} from './frame'

lib/keyframes.js

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { PropTypes } from 'react';
2-
import Frame from './frame';
1+
import React, {PropTypes} from 'react'
2+
import Frame from './frame'
33

4-
const noop = () => {};
4+
const noop = () => {}
55

66
export default class Keyframes extends React.Component {
77
static propTypes = {
88
children: PropTypes.arrayOf(PropTypes.element).isRequired,
9-
component: PropTypes.any,
9+
component: PropTypes.any, // eslint-disable-line react/no-unused-prop-types
1010
delay: PropTypes.number,
1111
loop: PropTypes.oneOfType([
1212
React.PropTypes.string,
@@ -25,92 +25,95 @@ export default class Keyframes extends React.Component {
2525
onEnd: noop
2626
};
2727

28-
constructor (props) {
29-
super(props);
28+
constructor(props) {
29+
super(props)
3030
this.state = {
3131
frameNum: this.props.delay ? -1 : 0,
3232
loopNum: 0
33-
};
34-
this.timer = null;
33+
}
34+
this.timer = null
3535
}
3636

37-
shouldComponentUpdate (nextProps, nextState) {
38-
const { frameNum } = nextState;
39-
if (this.state.frameNum === frameNum) return false;
40-
return 0 <= frameNum && frameNum < this.props.children.length;
37+
shouldComponentUpdate(nextProps, nextState) {
38+
const {frameNum} = nextState
39+
if (this.state.frameNum === frameNum) {
40+
return false
41+
}
42+
return frameNum >= 0 && frameNum < this.props.children.length
4143
}
4244

43-
componentWillMount () {
44-
if (0 === this.state.frameNum) {
45-
this.props.onStart();
45+
componentWillMount() {
46+
if (this.state.frameNum === 0) {
47+
this.props.onStart()
4648
}
4749
}
4850

49-
componentWillUpdate () {
50-
if (0 === this.state.frameNum) {
51-
this.props.onStart();
51+
componentWillUpdate() {
52+
if (this.state.frameNum === 0) {
53+
this.props.onStart()
5254
}
5355
}
5456

55-
componentDidMount () {
56-
this.requestNextFrame();
57+
componentDidMount() {
58+
this.requestNextFrame()
5759
}
5860

59-
componentDidUpdate () {
60-
this.requestNextFrame();
61+
componentDidUpdate() {
62+
this.requestNextFrame()
6163
}
6264

63-
componentWillUnmount () {
64-
clearTimeout(this.timer);
65+
componentWillUnmount() {
66+
clearTimeout(this.timer)
6567
}
6668

67-
render () {
68-
const frame = this.getFrame();
69-
if (!frame) return null;
69+
render() {
70+
const frame = this.getFrame()
71+
if (!frame) {
72+
return null
73+
}
7074

71-
const props = {};
72-
Object.keys(this.props).forEach((k) => {
75+
const props = {}
76+
Object.keys(this.props).forEach(k => {
7377
// don't pass props which exist only on Keyframes
7478
if (Keyframes.propTypes[k] && !Frame.propTypes[k]) {
75-
return;
79+
return
7680
}
7781

78-
props[k] = this.props[k];
79-
});
82+
props[k] = this.props[k]
83+
})
8084

81-
return React.cloneElement(frame, { ...props, ...frame.props });
85+
return React.cloneElement(frame, {...props, ...frame.props})
8286
}
8387

84-
requestNextFrame () {
88+
requestNextFrame() {
8589
this.waitForDelay(() => {
86-
const frameNum = this.state.frameNum + 1;
87-
const loopNum = this.state.loopNum + 1;
90+
const frameNum = this.state.frameNum + 1
91+
const loopNum = this.state.loopNum + 1
8892
if (this.props.children.length <= frameNum) {
8993
if (this.props.loop === true || this.props.loop === 'infinite' || loopNum < this.props.loop) {
9094
this.setState({
9195
frameNum: 0,
9296
loopNum
93-
});
94-
this.requestNextFrame();
95-
return;
96-
} else {
97-
this.props.onEnd();
98-
return;
97+
})
98+
this.requestNextFrame()
99+
return
99100
}
101+
this.props.onEnd()
102+
return
100103
}
101104

102-
this.setState({ frameNum });
103-
});
105+
this.setState({frameNum})
106+
})
104107
}
105108

106-
waitForDelay (fn) {
107-
const currentFrame = this.getFrame();
108-
const delay = currentFrame ? currentFrame.props.duration : this.props.delay;
109-
clearTimeout(this.timer);
110-
this.timer = setTimeout(fn, delay);
109+
waitForDelay(fn) {
110+
const currentFrame = this.getFrame()
111+
const delay = currentFrame ? currentFrame.props.duration : this.props.delay
112+
clearTimeout(this.timer)
113+
this.timer = setTimeout(fn, delay)
111114
}
112115

113-
getFrame () {
114-
return this.props.children[this.state.frameNum];
116+
getFrame() {
117+
return this.props.children[this.state.frameNum]
115118
}
116119
}

package.json

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"ava": "0.15.2",
14-
"babel-eslint": "6.1.2",
14+
"babel-eslint": "^7.0.0",
1515
"babel-plugin-transform-async-to-generator": "6.8.0",
1616
"babel-plugin-transform-class-properties": "6.11.5",
1717
"babel-plugin-transform-object-rest-spread": "6.8.0",
@@ -23,24 +23,20 @@
2323
"babel-register": "6.14.0",
2424
"babel-runtime": "6.11.6",
2525
"del": "2.2.2",
26-
"eslint-config-standard": "6.0.1",
27-
"eslint-config-standard-jsx": "3.0.1",
28-
"eslint-config-standard-react": "4.0.2",
29-
"eslint-plugin-promise": "2.0.1",
30-
"eslint-plugin-react": "6.2.2",
31-
"eslint-plugin-standard": "2.0.0",
26+
"eslint-config-xo-react": "^0.10.0",
27+
"eslint-plugin-react": "^6.4.1",
3228
"gulp": "3.9.1",
3329
"gulp-babel": "6.1.2",
34-
"gulp-eslint": "3.0.1",
3530
"gulp-task-listing": "1.0.1",
3631
"jsdom": "9.5.0",
3732
"lolex": "1.5.1",
3833
"react": "15.3.2",
39-
"react-dom": "15.3.1"
34+
"react-dom": "15.3.1",
35+
"xo": "^0.17.0"
4036
},
4137
"scripts": {
4238
"gulp": "gulp",
43-
"test": "ava"
39+
"test": "xo && ava"
4440
},
4541
"babel": {
4642
"presets": [
@@ -74,5 +70,16 @@
7470
"transform-runtime"
7571
]
7672
}
73+
},
74+
"xo": {
75+
"esnext": true,
76+
"space": true,
77+
"semicolon": false,
78+
"extends": "xo-react/space",
79+
"parser": "babel-eslint",
80+
"envs": [
81+
"browser",
82+
"jsx"
83+
]
7784
}
7885
}

test/helpers/setup-browser-env.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import jsdom from 'jsdom';
1+
import jsdom from 'jsdom'
22

3-
global.document = jsdom.jsdom('<body></body>');
4-
global.window = document.defaultView;
5-
global.navigator = window.navigator;
3+
global.document = jsdom.jsdom('<body></body>')
4+
global.window = document.defaultView
5+
global.navigator = window.navigator

0 commit comments

Comments
 (0)