Skip to content

Commit 3e505e2

Browse files
author
Brady Stilwell
committed
configure linter and add gulp task
1 parent eb82995 commit 3e505e2

File tree

12 files changed

+144
-60
lines changed

12 files changed

+144
-60
lines changed

.eslintrc.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"parser": "babel-eslint",
3+
"rules": {
4+
"indent": [
5+
2,
6+
2,
7+
{
8+
"SwitchCase": 1
9+
}
10+
],
11+
"quotes": [
12+
2,
13+
"single"
14+
],
15+
"linebreak-style": [
16+
2,
17+
"unix"
18+
],
19+
"prefer-const": 2,
20+
"semi": [
21+
2,
22+
"always"
23+
],
24+
"no-console": 0,
25+
"no-unused-vars": [
26+
2,
27+
{ "varsIgnorePattern": "React" }
28+
],
29+
"react/jsx-uses-vars": [2]
30+
},
31+
"globals": {
32+
"beforeEach": false,
33+
"beforeAll": false,
34+
"describe": false,
35+
"it": false,
36+
"xit": false,
37+
"afterEach": false,
38+
"afterAll": false,
39+
"expect": false,
40+
"spyOn": false,
41+
"done": false,
42+
"fail": false,
43+
"React":false,
44+
"ReactDOM":false,
45+
"TestUtils":false,
46+
"$": false,
47+
"browser": false,
48+
"jasmine": false
49+
},
50+
"env": {
51+
"es6": true,
52+
"node": true,
53+
"browser": true
54+
},
55+
"extends": "eslint:recommended",
56+
"ecmaFeatures": {
57+
"jsx": true,
58+
"experimentalObjectRestSpread": true,
59+
"modules": true
60+
},
61+
"plugins": [
62+
"react"
63+
]
64+
}

client/components/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react';
2-
import Hello from './hello';
3-
import World from './world';
2+
import Hello from './Hello';
3+
import World from './World';
44

55
export default class App extends React.Component {
66
render () {
7-
return (
7+
return (
88
<div>
99
<Hello/>
1010
<World/>
1111
</div>
12-
)
12+
);
1313
}
1414
}

client/components/hello.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import React from 'react';
22

33
export default class Hello extends React.Component {
44
render () {
5-
return <h1>Hello</h1>
5+
return <h1>Hello</h1>;
66
}
77
}

client/components/world.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import React from 'react';
22

33
export default class World extends React.Component {
44
render () {
5-
return <h1>World</h1>
5+
return <h1>World</h1>;
66
}
77
}

client/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import App from './components/app'
3+
import App from './components/App';
44

5-
ReactDOM.render(<App />, document.getElementById('container'));
5+
ReactDOM.render(<App />, document.getElementById('container'));

gulpfile.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,9 @@ const webpackTestConfig = require('./spec/webpack.test.config');
1111
const webpackConfig = require('./webpack.config');
1212
const plumber = require('gulp-plumber');
1313
const gutil = require('gulp-util');
14+
const eslint = require('gulp-eslint');
1415
const nodemon = require('nodemon');
1516

16-
function filterStack (stack) {
17-
const jasmineCorePath = require.resolve('jasmine-core').split(path.sep).slice(0, -1).join(path.sep);
18-
const superTestPath = require.resolve('supertest').split(path.sep).slice(0, -1).join(path.sep);
19-
const superAgentPath = require.resolve('superagent').split(path.sep).slice(0, -1).join(path.sep);
20-
return stack.split('\n').filter(function (stackLine) {
21-
return stackLine.indexOf(jasmineCorePath) === -1 && stackLine.indexOf(superTestPath) === -1
22-
&& stackLine.indexOf(superAgentPath) === -1
23-
}).join('\n');
24-
}
2517
const terminalReporter = new TerminalReporter({
2618
showColors: true,
2719
includeStackTrace: true,
@@ -30,6 +22,25 @@ const terminalReporter = new TerminalReporter({
3022
}
3123
});
3224

25+
const filesToLint = [
26+
'client/**/*.js',
27+
'server/**/*.js',
28+
'spec/client/**/*.js',
29+
'spec/server/**/*.js'
30+
];
31+
32+
gulp.task('runDev', [
33+
'webpackWatch',
34+
'serverWatch'
35+
]);
36+
37+
gulp.task('lint', function () {
38+
return gulp.src(filesToLint)
39+
.pipe(eslint())
40+
.pipe(eslint.format())
41+
.pipe(eslint.failAfterError());
42+
});
43+
3344
gulp.task('serverWatch', function () {
3445
nodemon({
3546
script: './server/utilities/runServer.js',
@@ -43,10 +54,6 @@ gulp.task('webpackWatch', function () {
4354
.pipe(gulp.dest('public/'));
4455
});
4556

46-
gulp.task('runDev', [
47-
'webpackWatch',
48-
'serverWatch'
49-
]);
5057

5158
gulp.task('jasmine', function () {
5259
process.env.NODE_ENV = 'test';
@@ -69,7 +76,7 @@ gulp.task('serverSpecs', function () {
6976
});
7077

7178
gulp.task('specs', function () {
72-
runSequence('unitSpecs', 'serverSpecs', function (err) {
79+
runSequence('unitSpecs', 'serverSpecs', 'lint', function (err) {
7380
// avoids the cluttering error runSequence throws
7481
if (err) {
7582
process.exit(1)
@@ -98,4 +105,14 @@ function bundleAssets(config, options) {
98105
.on('error', function (err) {
99106
gutil.log(gutil.colors.red('Bundling test assets failed'), gutil.colors.red(err));
100107
});
108+
}
109+
110+
function filterStack (stack) {
111+
const jasmineCorePath = require.resolve('jasmine-core').split(path.sep).slice(0, -1).join(path.sep);
112+
const superTestPath = require.resolve('supertest').split(path.sep).slice(0, -1).join(path.sep);
113+
const superAgentPath = require.resolve('superagent').split(path.sep).slice(0, -1).join(path.sep);
114+
return stack.split('\n').filter(function (stackLine) {
115+
return stackLine.indexOf(jasmineCorePath) === -1 && stackLine.indexOf(superTestPath) === -1
116+
&& stackLine.indexOf(superAgentPath) === -1
117+
}).join('\n');
101118
}

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
},
2323
"devDependencies": {
2424
"babel-core": "^6.13.2",
25+
"babel-eslint": "^7.1.0",
2526
"babel-loader": "^6.2.5",
2627
"babel-preset-es2015": "^6.13.2",
2728
"babel-preset-react": "^6.11.1",
2829
"babel-register": "^6.14.0",
2930
"body-parser": "^1.15.2",
31+
"eslint": "^3.9.1",
32+
"eslint-config-standard": "^6.2.1",
33+
"eslint-plugin-react": "^6.6.0",
34+
"eslint-plugin-standard": "^2.0.1",
3035
"gulp": "^3.9.1",
36+
"gulp-eslint": "^3.0.1",
3137
"gulp-jasmine": "^2.4.0",
3238
"gulp-jasmine-browser": "^1.6.0",
3339
"gulp-plumber": "^1.1.0",

server/controllers/zipCodeController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const request = require('request-promise');
33
module.exports = (req, res) => {
44
return getDelegates()
55
.then(legislators => {
6-
res.status(200).json(legislators)
6+
res.status(200).json(legislators);
77
})
88
.catch(() => {
99
res.status(200).send('Sunlight Labs is hosed');
@@ -22,7 +22,7 @@ function getDelegates () {
2222
reject(new Error(`Status code: ${response.statusCode}`));
2323
}
2424
else {
25-
resolve(response.body)
25+
resolve(response.body);
2626
}
2727
}).catch(err => {
2828
reject(err);

server/server.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
const path = require('path');
21
const express = require('express');
32
const bodyParser = require('body-parser');
43
const getLogger = require('./utilities/logger');
5-
const logger = getLogger();
64
const webpack = require('webpack');
75
const config = require('../webpack.config.js');
86
const zipCodeController = require('./controllers/zipCodeController');
@@ -34,12 +32,11 @@ module.exports = {
3432
});
3533
});
3634

37-
return app
35+
return app;
3836
},
3937

4038
start: function (port) {
4139
const logger = getLogger();
42-
4340
const app = this.getApp();
4441
return new Promise((resolve) => server = app.listen(port, () => {
4542
logger.info('Server has started on port: ' + port);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import Hello from '../../../client/components/hello'
1+
import Hello from '../../../client/components/Hello';
22

33
describe('Hello', function () {
44
it('should render an h1', function () {
55
this.render(<Hello/>);
6-
expect(this.$container.find('h1').text()).toEqual('Hello')
6+
expect(this.$container.find('h1').text()).toEqual('Hello');
77
});
88
});
99

0 commit comments

Comments
 (0)