diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..99f609a --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +./server.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8b7f197 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,12 @@ + +{ + 'parser': 'babel-eslint', + 'extends': 'airbnb', + 'globals': { + '__DEV__': true + }, + 'rules': { + 'react/jsx-quotes': 0, + 'jsx-quotes': [2, 'prefer-double'] + } +} diff --git a/package.json b/package.json index c0ccabb..6036c8c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "devDependencies": { "autoprefixer": "^6.0.2", "ava": "^0.11.0", + "babel-eslint": "^4.1.6", "babel-loader": "^6.2.1", "babel-plugin-transform-runtime": "^6.4.3", "babel-preset-es2015": "^6.3.13", @@ -39,6 +40,9 @@ "coveralls": "^2.11.2", "css-loader": "^0.18.0", "enzyme": "^1.4.0", + "eslint": "^1.10.3", + "eslint-config-airbnb": "^4.0.0", + "eslint-plugin-react": "^3.16.1", "extract-text-webpack-plugin": "^0.8.2", "nyc": "^5.3.0", "postcss-loader": "^0.6.0", diff --git a/server.js b/server.js index 77515c4..8d39154 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,4 @@ -var express = require('express'); +var express = require("express"); var app = express(); @@ -12,26 +12,26 @@ var app = express(); ************************************************************/ // Serve application file depending on environment -app.get('/app.js', function(req, res) { +app.get("/app.js", function(req, res) { if (process.env.PRODUCTION) { - res.sendFile(__dirname + '/build/app.js'); + res.sendFile(__dirname + "/build/app.js"); } else { - res.redirect('//localhost:9090/build/app.js'); + res.redirect("//localhost:9090/build/app.js"); } }); // Serve aggregate stylesheet depending on environment -app.get('/style.css', function(req, res) { +app.get("/style.css", function(req, res) { if (process.env.PRODUCTION) { - res.sendFile(__dirname + '/build/style.css'); + res.sendFile(__dirname + "/build/style.css"); } else { - res.redirect('//localhost:9090/build/style.css'); + res.redirect("//localhost:9090/build/style.css"); } }); // Serve index page -app.get('*', function(req, res) { - res.sendFile(__dirname + '/build/index.html'); +app.get("*", function(req, res) { + res.sendFile(__dirname + "/build/index.html"); }); @@ -44,16 +44,16 @@ app.get('*', function(req, res) { *************************************************************/ if (!process.env.PRODUCTION) { - var webpack = require('webpack'); - var WebpackDevServer = require('webpack-dev-server'); - var config = require('./webpack.local.config'); + var webpack = require("webpack"); + var WebpackDevServer = require("webpack-dev-server"); + var config = require("./webpack.local.config"); new WebpackDevServer(webpack(config), { publicPath: config.output.publicPath, hot: true, noInfo: true, historyApiFallback: true - }).listen(9090, 'localhost', function (err, result) { + }).listen(9090, "localhost", function (err, result) { if (err) { console.log(err); } @@ -72,5 +72,5 @@ var server = app.listen(port, function () { var host = server.address().address; var port = server.address().port; - console.log('Essential React listening at http://%s:%s', host, port); + console.log("Essential React listening at http://%s:%s", host, port); }); diff --git a/src/common/components/App.js b/src/common/components/App.js index 8e349f0..244da12 100644 --- a/src/common/components/App.js +++ b/src/common/components/App.js @@ -1,7 +1,10 @@ import React from 'react'; -export default class App extends React.Component { +class App extends React.Component { + static propTypes = { + children: React.PropTypes.element.isRequired, + }; render() { return (
@@ -10,3 +13,9 @@ export default class App extends React.Component { ); } } + +App.propTypes = { + title: React.PropTypes.string.isRequired, +}; + +export default App; diff --git a/src/main.js b/src/main.js index 1e7d4c9..b5afc86 100644 --- a/src/main.js +++ b/src/main.js @@ -3,25 +3,23 @@ */ // Polyfill -import "babel-polyfill"; +import 'babel-polyfill'; // Libraries -import React from "react"; -import ReactDOM from "react-dom"; -import { Router } from "react-router"; -import createBrowserHistory from 'history/lib/createBrowserHistory' +import React from 'react'; +import ReactDOM from 'react-dom'; +import { Router } from 'react-router'; +import createBrowserHistory from 'history/lib/createBrowserHistory'; // Routes import Routes from './common/components/Routes'; // Base styling -import "./common/base.css"; +import './common/base.css'; // ID of the DOM element to mount app on -const DOM_APP_EL_ID = "app"; - - +const DOM_APP_EL_ID = 'app'; // Render the router ReactDOM.render(( diff --git a/src/pages/home/page.js b/src/pages/home/page.js index 3324c69..c1129aa 100644 --- a/src/pages/home/page.js +++ b/src/pages/home/page.js @@ -1,5 +1,5 @@ -import React from "react"; -import styles from "./style.css"; +import React from 'react'; +import styles from './style.css'; export default class HomePage extends React.Component { diff --git a/src/pages/login/page.js b/src/pages/login/page.js index 598e48c..1175f6b 100644 --- a/src/pages/login/page.js +++ b/src/pages/login/page.js @@ -1,5 +1,5 @@ -import React from "react"; -import styles from "./style.css"; +import React from 'react'; +import styles from './style.css'; export default class LoginPage extends React.Component { diff --git a/webpack.local.config.js b/webpack.local.config.js index 3935b94..2fa28d0 100644 --- a/webpack.local.config.js +++ b/webpack.local.config.js @@ -14,21 +14,21 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin'); module.exports = { // Efficiently evaluate modules with source maps - devtool: "eval", + devtool: 'eval', // Set entry point to ./src/main and include necessary files for hot load entry: [ - "webpack-dev-server/client?http://localhost:9090", - "webpack/hot/only-dev-server", - "./src/main" + 'webpack-dev-server/client?http://localhost:9090', + 'webpack/hot/only-dev-server', + './src/main' ], // This will not actually create a bundle.js file in ./build. It is used // by the dev server for dynamic hot loading. output: { - path: __dirname + "/build/", - filename: "app.js", - publicPath: "http://localhost:9090/build/" + path: __dirname + '/build/', + filename: 'app.js', + publicPath: 'http://localhost:9090/build/' }, // Necessary plugins for hot load @@ -41,7 +41,7 @@ module.exports = { // Transform source code using Babel and React Hot Loader module: { loaders: [ - { test: /\.jsx?$/, exclude: /node_modules/, loaders: ["react-hot", "babel-loader?presets[]=es2015,presets[]=react,presets[]=stage-0,plugins[]=transform-runtime"] }, + { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['react-hot', 'babel-loader?presets[]=es2015,presets[]=react,presets[]=stage-0,plugins[]=transform-runtime'] }, { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader') } ] }, diff --git a/webpack.production.config.js b/webpack.production.config.js index 14d96f8..155c6eb 100644 --- a/webpack.production.config.js +++ b/webpack.production.config.js @@ -5,11 +5,11 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin'); * This is the Webpack configuration file for production. */ module.exports = { - entry: "./src/main", + entry: './src/main', output: { - path: __dirname + "/build/", - filename: "app.js" + path: __dirname + '/build/', + filename: 'app.js' }, plugins: [ @@ -18,7 +18,7 @@ module.exports = { module: { loaders: [ - { test: /\.jsx?$/, exclude: /node_modules/, loader: "babel-loader?presets[]=es2015,presets[]=react,presets[]=stage-0,plugins[]=transform-runtime" }, + { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015,presets[]=react,presets[]=stage-0,plugins[]=transform-runtime' }, { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader') } ] },