Skip to content

Commit cf2ade6

Browse files
committed
add eslint
Description: - add eslint-related packages, npm script and configs author used to - fix eslint issues
1 parent db40ae1 commit cf2ade6

File tree

4 files changed

+60
-19
lines changed

4 files changed

+60
-19
lines changed

.eslintrc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
'env': {
3+
'browser': true,
4+
'mocha': true,
5+
'node': true
6+
},
7+
'plugins': ['react'],
8+
'parser': 'babel-eslint',
9+
'rules': {
10+
'quotes': [1, 'single', 'avoid-escape'],
11+
'semi': [1, 'always'],
12+
'no-undef': 2,
13+
'no-unused-vars': 2,
14+
'no-underscore-dangle': 0,
15+
'no-use-before-define': 0,
16+
'jsx-quotes': [1, 'prefer-double'],
17+
'prefer-const': 2,
18+
'comma-dangle': [2, 'never'],
19+
20+
'react/jsx-first-prop-new-line': [2, 'multiline'],
21+
'react/prefer-stateless-function': 0,
22+
'react/jsx-space-before-closing': [2, 'always'],
23+
'react/prefer-es6-class': 0,
24+
'react/prop-types': 2,
25+
'react/self-closing-comp': 2,
26+
'react/jsx-no-undef': 1,
27+
'react/jsx-uses-react': 1,
28+
'react/jsx-uses-vars': 1,
29+
'react/jsx-boolean-value': [2, 'never'],
30+
'react/jsx-closing-bracket-location': [2, 'tag-aligned'],
31+
'react/jsx-equals-spacing': [1, 'never'],
32+
'react/jsx-indent-props': [1, 2],
33+
'react/jsx-indent': [1, 2],
34+
'react/jsx-no-duplicate-props': 2,
35+
}
36+
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"clear": "rimraf lib",
99
"rebuild": "npm run clear && npm run build",
1010
"test": "mocha --compilers js:babel-register --recursive --require ./test/setup.js",
11-
"test:watch": "npm test -- --watch"
11+
"test:watch": "npm test -- --watch",
12+
"lint": "eslint src test"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -30,10 +31,13 @@
3031
"devDependencies": {
3132
"babel-cli": "^6.16.0",
3233
"babel-core": "^6.16.0",
34+
"babel-eslint": "^7.0.0",
3335
"babel-preset-es2015": "^6.16.0",
3436
"babel-preset-react": "^6.16.0",
3537
"babel-preset-stage-1": "^6.16.0",
3638
"enzyme": "^2.4.1",
39+
"eslint": "^3.7.0",
40+
"eslint-plugin-react": "^6.3.0",
3741
"expect": "^1.20.2",
3842
"jsdom": "^9.5.0",
3943
"mocha": "^3.1.0",

test/components/Connection.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import expect from 'expect';
77
describe('<Connection />', function() {
88
class TestConnection extends Connection {
99
load() {
10-
return this.$load([1, 2, 3])
10+
return this.$load([1, 2, 3]);
1111
}
1212
render() {
13-
return <div className="connection" onClick={() => this.load()} />
13+
return <div className="connection" onClick={() => this.load()} />;
1414
}
1515
}
1616

1717
class TestConnector extends Connector {
1818
static $connection = TestConnection;
1919
static $state = []
20-
static $reducer = TestConnector.reduce('foo', (state) => ({
20+
static $reducer = TestConnector.reduce('foo', () => ({
2121
$receive: (items) => items
2222
}));
23-
$expose($state) { return { items: $state } }
24-
$load(items) { return this.$$receive(items) }
23+
$expose($state) { return { items: $state }; }
24+
$load(items) { return this.$$receive(items); }
2525
}
2626

2727
it('has event-handler methods (that start with $) provided by Connector', function() {

test/components/Connector.test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
1+
import React, { PropTypes } from 'react';
22
import { createStore } from 'redux';
33
import { Connector } from '../../src';
44
import storeShape from '../../src/utils/storeShape';
55
import { shallow, mount } from 'enzyme';
6-
import expect, { createSpy, spyOn } from 'expect';
6+
import expect, { spyOn } from 'expect';
77

88
describe('Connector', function() {
99
describe('.reduce', function() {
@@ -62,12 +62,13 @@ describe('Connector', function() {
6262
describe('<Connector />', function() {
6363
const store = createStore(state => state);
6464
const Provider = React.createClass({
65+
propTypes: { children: PropTypes.node },
6566
childContextTypes: { store: storeShape },
66-
getChildContext() { return { store } },
67-
render() { return this.props.children }
67+
getChildContext() { return { store }; },
68+
render() { return this.props.children; }
6869
});
6970
class Connection extends React.Component {
70-
render() { return <div className="connection" /> }
71+
render() { return <div className="connection" />; }
7172
}
7273

7374
describe('initialization', function() {
@@ -76,7 +77,7 @@ describe('<Connector />', function() {
7677
}
7778

7879
it('throws an error if store is undefined', function() {
79-
expect(function(){ shallow(<TestConnector />) })
80+
expect(function(){ shallow(<TestConnector />); })
8081
.toThrow('TestConnector instance expects store object in props or in context');
8182
});
8283

@@ -87,7 +88,7 @@ describe('<Connector />', function() {
8788

8889
it('accepts store from context', function() {
8990
let instance = null;
90-
const wrapper = mount(<Provider><TestConnector ref={(inst) => instance = inst} /></Provider>);
91+
mount(<Provider><TestConnector ref={(inst) => instance = inst} /></Provider>);
9192
expect(instance.store).toBe(store);
9293
});
9394
});
@@ -193,12 +194,12 @@ describe('<Connector />', function() {
193194
class TestConnector extends Connector {
194195
static $connection = Connection;
195196
static $state = [];
196-
static $reducer = TestConnector.reduce('foo', (state) => ({}));
197+
static $reducer = TestConnector.reduce('foo', () => ({}));
197198
}
198199

199200
it('throws an error', function() {
200201
const store = createStore(TestConnector.$reducer);
201-
expect(function() { mount(<TestConnector store={store} />) })
202+
expect(function() { mount(<TestConnector store={store} />); })
202203
.toThrow('TestConnector.$state should be a plain object' +
203204
'or there should be a $expose instance method defined that returns a plain object'
204205
);
@@ -209,13 +210,13 @@ describe('<Connector />', function() {
209210
class TestConnector extends Connector {
210211
static $connection = Connection;
211212
static $state = { items: [] };
212-
static $reducer = TestConnector.reduce('foo', (state) => ({}));
213-
$expose($state) { return $state.items }
213+
static $reducer = TestConnector.reduce('foo', () => ({}));
214+
$expose($state) { return $state.items; }
214215
}
215216

216217
it('throws an error', function() {
217218
const store = createStore(TestConnector.$reducer);
218-
expect(function() { mount(<TestConnector store={store} />) })
219+
expect(function() { mount(<TestConnector store={store} />); })
219220
.toThrow('TestConnector.$state should be a plain object' +
220221
'or there should be a $expose instance method defined that returns a plain object'
221222
);
@@ -310,7 +311,7 @@ describe('<Connector />', function() {
310311
it('throws an error when no connection is specified', function() {
311312
class BadConnector extends Connector {}
312313

313-
expect(function(){ mount(<BadConnector store={store} />) })
314+
expect(function(){ mount(<BadConnector store={store} />); })
314315
.toThrow('BadConnector should define a $connection class property');
315316
});
316317

0 commit comments

Comments
 (0)