Skip to content

Commit 586b62d

Browse files
committed
use airbnb eslint config
1 parent 79f5181 commit 586b62d

File tree

5 files changed

+51
-58
lines changed

5 files changed

+51
-58
lines changed

.eslintrc

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
11
{
2-
"parser": "babel-eslint",
3-
"env": {
4-
"node": true,
5-
"browser": true
6-
},
7-
"rules": {
8-
"strict": false,
9-
"no-underscore-dangle": false,
10-
"quotes": [2, "single"],
11-
"no-use-before-define": false,
12-
"new-cap": false,
13-
"no-trailing-spaces": false
14-
}
2+
"extends": "eslint-config-airbnb"
153
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"babel-eslint": "^4.1.3",
2929
"babel-jest": "^5.3.0",
3030
"eslint": "^1.7.3",
31+
"eslint-config-airbnb": "^0.1.0",
32+
"eslint-plugin-react": "^3.6.3",
3133
"jest-cli": "^0.6.1",
3234
"react": "^0.14.0",
3335
"react-addons-test-utils": "^0.14.0",

src/SoundCloud.js

+27-22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class SoundCloud extends React.Component {
2727
this._internalWidget = null;
2828
}
2929

30+
componentDidMount() {
31+
this._createWidget();
32+
}
33+
3034
/**
3135
* @param {Object} nextProps
3236
* @returns {Boolean}
@@ -36,10 +40,6 @@ class SoundCloud extends React.Component {
3640
return nextProps.url !== this.props.url;
3741
}
3842

39-
componentDidMount() {
40-
this._createWidget();
41-
}
42-
4343
componentDidUpdate() {
4444
this._reloadWidget();
4545
}
@@ -48,22 +48,6 @@ class SoundCloud extends React.Component {
4848
this._unbindEvents();
4949
}
5050

51-
/**
52-
* @returns {Object}
53-
*/
54-
55-
render() {
56-
return (
57-
<iframe id={this.props.id}
58-
width='100%'
59-
height={this.props.height || (this.props.opts.visual ? '450' : '166')}
60-
scrolling='no'
61-
frameBorder='no'
62-
src='https://w.soundcloud.com/player/?url='
63-
/>
64-
);
65-
}
66-
6751
/**
6852
* Called on the initial render, this uses the rendered iframe
6953
* as a base for creating a new `_internalWidget`.
@@ -120,6 +104,22 @@ class SoundCloud extends React.Component {
120104
this._internalWidget.unbind(window.SC.Widget.Events.PAUSE);
121105
this._internalWidget.unbind(window.SC.Widget.Events.FINISH);
122106
}
107+
108+
/**
109+
* @returns {Object}
110+
*/
111+
112+
render() {
113+
return (
114+
<iframe id={this.props.id}
115+
width="100%"
116+
height={this.props.height || (this.props.opts.visual ? '450' : '166')}
117+
scrolling="no"
118+
frameBorder="no"
119+
src="https://w.soundcloud.com/player/?url="
120+
/>
121+
);
122+
}
123123
}
124124

125125
SoundCloud.propTypes = {
@@ -130,21 +130,26 @@ SoundCloud.propTypes = {
130130
// custom ID for widget iframe element
131131
id: React.PropTypes.string,
132132

133+
height: React.PropTypes.oneOfType([
134+
React.PropTypes.string,
135+
React.PropTypes.number,
136+
]),
137+
133138
// widget parameters for appearance and auto play.
134139
opts: React.PropTypes.objectOf(React.PropTypes.bool),
135140

136141
// event subscriptions
137142
onPlay: React.PropTypes.func,
138143
onPause: React.PropTypes.func,
139-
onEnd: React.PropTypes.func
144+
onEnd: React.PropTypes.func,
140145
};
141146

142147
SoundCloud.defaultProps = {
143148
id: 'react-sc-widget',
144149
opts: {},
145150
onPlay: () => {},
146151
onPause: () => {},
147-
onEnd: () => {}
152+
onEnd: () => {},
148153
};
149154

150155
/**

src/__tests__/SoundCloud-test.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ let widgetMock;
1010

1111
describe('SoundCloud Component', () => {
1212
beforeEach(() => {
13-
1413
/**
1514
* Mock out SoundCloud widget API
1615
*/
@@ -20,58 +19,58 @@ describe('SoundCloud Component', () => {
2019
Events: {
2120
PLAY: 'play',
2221
PAUSE: 'pause',
23-
FINISH: 'finish'
24-
}
25-
}
22+
FINISH: 'finish',
23+
},
24+
},
2625
};
2726

2827
widgetMock = {
2928
load: jest.genMockFunction(),
3029
bind: jest.genMockFunction(),
31-
unbind: jest.genMockFunction()
30+
unbind: jest.genMockFunction(),
3231
};
3332

3433
createWidget.mockImplementation((props, cb) => cb(widgetMock));
3534
});
3635

3736
describe('instantiation', () => {
3837
it('should render a SoundCloud API ready iframe', () => {
39-
const soundcloud = TestUtils.renderIntoDocument(<SoundCloud url='' />);
38+
const soundcloud = TestUtils.renderIntoDocument(<SoundCloud url="" />);
4039
const iframe = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(soundcloud, 'iframe'));
4140

4241
expect(iframe.getAttribute('id')).toBe('react-sc-widget');
4342
expect(iframe.getAttribute('src')).toBe('https://w.soundcloud.com/player/?url=');
4443
});
4544

4645
it('should accept a custom iframe id', () => {
47-
const soundcloud = TestUtils.renderIntoDocument(<SoundCloud url='' id='custom-id' />);
46+
const soundcloud = TestUtils.renderIntoDocument(<SoundCloud url="" id="custom-id" />);
4847
const iframe = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(soundcloud, 'iframe'));
4948

5049
expect(iframe.getAttribute('id')).toBe('custom-id');
5150
});
5251

5352
it('should create a new SoundCloud widget', () => {
54-
TestUtils.renderIntoDocument(<SoundCloud url='' />);
53+
TestUtils.renderIntoDocument(<SoundCloud url="" />);
5554
expect(createWidget.mock.calls[0][0]).toBe('react-sc-widget');
5655
});
5756
});
5857

5958
describe('appearance', () => {
6059
it('should pass a set of `opts` into the widget', () => {
6160
const opts = {
62-
buying: false
61+
buying: false,
6362
};
6463

65-
TestUtils.renderIntoDocument(<SoundCloud url='' opts={opts} />);
64+
TestUtils.renderIntoDocument(<SoundCloud url="" opts={opts} />);
6665
expect(widgetMock.load.mock.calls[0][1]).toEqual(opts);
6766
});
6867

6968
it('should readjust height if visual mode is enabled', () => {
7069
const opts = {
71-
visual: true
70+
visual: true,
7271
};
7372

74-
const soundcloud = TestUtils.renderIntoDocument(<SoundCloud url='' opts={opts} />);
73+
const soundcloud = TestUtils.renderIntoDocument(<SoundCloud url="" opts={opts} />);
7574
const iframe = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(soundcloud, 'iframe'));
7675
expect(iframe.getAttribute('height')).toBe('450');
7776
});
@@ -81,12 +80,18 @@ describe('SoundCloud Component', () => {
8180
class Container extends React.Component {
8281
constructor() {
8382
this.state = {
84-
url: 'https://soundcloud.com/sylvanesso/coffee'
83+
url: 'https://soundcloud.com/sylvanesso/coffee',
8584
};
8685

8786
this._changeUrl = this._changeUrl.bind(this);
8887
}
8988

89+
_changeUrl() {
90+
this.setState({
91+
url: 'https://soundcloud.com/hudsonmohawke/chimes',
92+
});
93+
}
94+
9095
render() {
9196
return (
9297
<div>
@@ -95,12 +100,6 @@ describe('SoundCloud Component', () => {
95100
</div>
96101
);
97102
}
98-
99-
_changeUrl() {
100-
this.setState({
101-
url: 'https://soundcloud.com/hudsonmohawke/chimes'
102-
});
103-
}
104103
}
105104

106105
it('should load a `url`', () => {
@@ -137,22 +136,21 @@ describe('SoundCloud Component', () => {
137136
describe('events', () => {
138137
it('should bind event handler props to playback events', () => {
139138
const playFn = () => {};
140-
TestUtils.renderIntoDocument(<SoundCloud url='' onPlay={playFn} />);
139+
TestUtils.renderIntoDocument(<SoundCloud url="" onPlay={playFn} />);
141140

142141
expect(widgetMock.bind.mock.calls.length).toBe(3);
143142
expect(widgetMock.bind.mock.calls[0]).toContain(playFn);
144143
});
145144

146145
it('should remove event bindings when unmounted', () => {
147-
148146
/**
149147
* `TestUtils.renderIntoDocument` renders the component into
150148
* a detached DOM node, which makes it difficult to unmount.
151149
*
152150
* Instead, we'll just render it the old fashioned way.
153151
*/
154152

155-
ReactDOM.render(<SoundCloud url=''/>, document.body);
153+
ReactDOM.render(<SoundCloud url=""/>, document.body);
156154
ReactDOM.unmountComponentAtNode(document.body);
157155

158156
expect(widgetMock.unbind.mock.calls.length).toBe(3);

src/lib/createWidget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import load from 'load-script';
1414
const createWidget = (id, cb) => {
1515
// load the API, it's namespaced as `window.SC`
1616
return load('https://w.soundcloud.com/player/api.js', () => {
17-
return cb(window.SC.Widget(id));
17+
return cb(window.SC.Widget(id)); // eslint-disable-line new-cap
1818
});
1919
};
2020

0 commit comments

Comments
 (0)