diff --git a/.eslintignore b/.eslintignore index 0d6dcf459..25301d233 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,8 +1,4 @@ node_modules -lib/web/static -lib/web/ui/ -lib/web/static coverage/ - wiki/ static/ diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..344b94607 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,80 @@ +{ + "plugins": [ + "react", + "flowtype" + ], + "extends": [ + "eslint:recommended", + "google", + "plugin:react/recommended", + "plugin:flowtype/recommended" + ], + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 7, + "ecmaFeatures": { + "impliedStrict": true, + "jsx": true + } + }, + "env": { + "browser": true, + "node": true, + "es6": true + }, + "rules": { + "no-tabs": 0, + "keyword-spacing": 0, + "padded-blocks": 0, + "no-useless-escape": 0, + "handle-callback-err": 2, + "no-debugger": 2, + "no-fallthrough": 2, + "curly": 2, + "eol-last": 1, + "no-irregular-whitespace": 1, + "no-mixed-spaces-and-tabs": [ + 1, + "smart-tabs" + ], + "no-trailing-spaces": 1, + "no-new-require": 2, + "no-undef": 2, + "no-unreachable": 2, + "no-unused-vars": [ + 2, + { + "vars": "all", + "args": "none" + } + ], + "max-len": [ + 1, + 160 + ], + "semi": [ + 2, + "always" + ], + "camelcase": 0, + "require-jsdoc": 2, + "valid-jsdoc": 2, + "prefer-spread": 1, + "prefer-rest-params": 1, + "no-var": 2, + "no-constant-condition": 2, + "no-empty": 2, + "guard-for-in": 2, + "no-invalid-this": 2, + "new-cap": 2, + "one-var": 2, + "no-console": [ + 2, + { + "allow": [ + "warn" + ] + } + ] + } +} diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 71da3c774..000000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,99 +0,0 @@ -# vim: syntax=yaml - -# -# List of very light restrictions designed to prevent obvious errors, -# not impose our own code style upon other contributors. -# -# This is supposed to be used with `eslint --reset` -# -# Created to work with eslint@0.18.0 -# - -plugins: ["react"] - -extends: ["eslint:recommended", "google", "plugin:react/recommended"] - -env: - node: true - browser: true - es6: true - -parserOptions: - sourceType: "module" - ecmaVersion: 7 - ecmaFeatures: - jsx: true - - -rules: - - no-tabs: 0 - keyword-spacing: 0 - padded-blocks: 0 - - # useful to have in node.js, - # if you're sure you don't need to handle error, rename it to "_err" - handle-callback-err: 2 - - # just to make sure we don't forget to remove them when releasing - no-debugger: 2 - - # add "falls through" for those - no-fallthrough: 2 - - # enforce use curly always - # curly: 1 - - # just warnings about whitespace weirdness here - eol-last: 1 - no-irregular-whitespace: 1 - no-mixed-spaces-and-tabs: [1, smart-tabs] - no-trailing-spaces: 1 - - # probably always an error, tell me if it's not - no-new-require: 2 - - # single most important rule here, without it linting won't even - # make any sense - no-undef: 2 - - # in practice, those are always errors - no-unreachable: 2 - - # useful for code clean-up - no-unused-vars: [2, {"vars": "all", "args": "none"}] - - max-len: [1, 160] - - # camelcase is standard, but this should be 1 and then 2 soon - camelcase: 0 - - # jsdoc is mandatory - require-jsdoc: 2 - valid-jsdoc: 2 - - # this feature is cool but not supported by Node 4, disable via comments - prefer-spread: 1 - prefer-rest-params: 1 - - # encorage use es6 - no-var: 2 - - # configuration that should be upgraded progresivelly - no-constant-condition: 2 - no-empty: 2 - - # loop over objects http://eslint.org/docs/rules/guard-for-in - guard-for-in: 2 - - # this must be used within classes - no-invalid-this: 2 - - # All object must be uppercase - new-cap: 2 - - # readbility is important, no multiple inline declarations - one-var: 2 - - # console not allowed unless for testing - no-console: [2, {"allow": ["log", "warn"]}] diff --git a/package-lock.json b/package-lock.json index bb7aa56dd..304d78079 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index 48fc3146e..30b1fb3ed 100644 --- a/package.json +++ b/package.json @@ -48,59 +48,59 @@ "unix-crypt-td-js": "^1.0.0" }, "devDependencies": { - "axios": "^0.16.2", - "babel-cli": "^6.24.1", - "babel-core": "^6.25.0", - "babel-eslint": "^7.2.3", - "babel-loader": "^7.1.1", - "babel-plugin-flow-runtime": "^0.11.1", - "babel-plugin-transform-decorators-legacy": "^1.3.4", - "babel-plugin-transform-runtime": "^6.23.0", - "babel-preset-env": "^1.5.2", - "babel-preset-flow": "^6.23.0", - "babel-preset-react": "^6.24.1", - "babel-preset-stage-2": "^6.24.1", - "babel-preset-stage-3": "^6.24.1", - "babel-runtime": "^6.23.0", + "axios": "0.16.2", + "babel-cli": "6.24.1", + "babel-core": "6.25.0", + "babel-eslint": "7.2.3", + "babel-loader": "7.1.1", + "babel-plugin-flow-runtime": "0.11.1", + "babel-plugin-transform-decorators-legacy": "1.3.4", + "babel-plugin-transform-runtime": "6.23.0", + "babel-preset-env": "1.5.2", + "babel-preset-flow": "6.23.0", + "babel-preset-react": "6.24.1", + "babel-preset-stage-2": "6.24.1", + "babel-preset-stage-3": "6.24.1", + "babel-runtime": "6.23.0", "codacy-coverage": "2.0.2", "codecov": "2.2.0", - "coveralls": "^2.13.1", - "css-loader": "^0.28.4", - "element-react": "^1.0.16", - "element-theme-default": "^1.3.7", - "eslint": "^4.1.0", - "eslint-config-google": "^0.8.0", - "eslint-loader": "^1.8.0", - "eslint-plugin-babel": "^4.1.1", - "eslint-plugin-flowtype": "^2.34.1", - "eslint-plugin-import": "^2.6.1", - "eslint-plugin-react": "^7.1.0", - "extract-text-webpack-plugin": "^2.1.2", - "file-loader": "^0.11.2", - "flow-runtime": "^0.13.0", - "friendly-errors-webpack-plugin": "^1.6.1", - "html-webpack-plugin": "^2.29.0", + "coveralls": "2.13.1", + "css-loader": "0.28.4", + "element-react": "1.0.16", + "element-theme-default": "1.3.7", + "eslint": "4.2.0", + "eslint-config-google": "0.8.0", + "eslint-loader": "1.8.0", + "eslint-plugin-babel": "4.1.1", + "eslint-plugin-flowtype": "2.35.0", + "eslint-plugin-import": "2.6.1", + "eslint-plugin-react": "7.1.0", + "extract-text-webpack-plugin": "3.0.0", + "file-loader": "0.11.2", + "flow-runtime": "0.13.0", + "friendly-errors-webpack-plugin": "1.6.1", + "html-webpack-plugin": "2.29.0", "in-publish": "2.0.0", - "localstorage-memory": "^1.0.2", - "mocha": "^3.4.2", + "localstorage-memory": "1.0.2", + "mocha": "3.4.2", "mocha-lcov-reporter": "1.3.0", - "node-sass": "^4.5.3", - "normalize.css": "^7.0.0", - "nyc": "^11.0.3", - "ora": "^1.3.0", - "prop-types": "^15.5.10", - "react": "^15.6.1", - "react-dom": "^15.6.1", - "react-hot-loader": "^3.0.0-beta.7", - "react-router-dom": "^4.1.1", - "rimraf": "^2.6.1", - "sass-loader": "^6.0.6", - "source-map-loader": "^0.2.1", - "style-loader": "^0.18.2", - "styled-components": "^2.1.1", - "url-loader": "^0.5.8", - "webpack": "^3.0.0", - "webpack-dev-server": "^2.5.0" + "node-sass": "4.5.3", + "normalize.css": "7.0.0", + "nyc": "11.0.3", + "ora": "1.3.0", + "prop-types": "15.5.10", + "react": "15.6.1", + "react-dom": "15.6.1", + "react-hot-loader": "3.0.0-beta.7", + "react-router-dom": "4.1.1", + "rimraf": "2.6.1", + "sass-loader": "6.0.6", + "source-map-loader": "0.2.1", + "style-loader": "0.18.2", + "styled-components": "2.1.1", + "url-loader": "0.5.8", + "webpack": "3.2.0", + "webpack-dev-server": "2.5.0" }, "keywords": [ "private", diff --git a/src/api/.eslintrc b/src/api/.eslintrc index eb1396ee6..13384b11c 100644 --- a/src/api/.eslintrc +++ b/src/api/.eslintrc @@ -1,5 +1,5 @@ -# vim: syntax=yaml - - -rules: - no-useless-escape: 0 +{ + "rules": { + "no-useless-escape": 0 + } +} diff --git a/src/lib/.eslintrc b/src/lib/.eslintrc index eb1396ee6..13384b11c 100644 --- a/src/lib/.eslintrc +++ b/src/lib/.eslintrc @@ -1,5 +1,5 @@ -# vim: syntax=yaml - - -rules: - no-useless-escape: 0 +{ + "rules": { + "no-useless-escape": 0 + } +} diff --git a/src/webui/.eslintrc b/src/webui/.eslintrc new file mode 100644 index 000000000..40c11814b --- /dev/null +++ b/src/webui/.eslintrc @@ -0,0 +1,27 @@ +{ + "env": { + "browser": true, + "node": true, + "jest": true, + "es6": true + }, + "rules": { + "require-jsdoc": 0, + "no-console": [ + 1, + { + "allow": [ + "log" + ] + } + ], + "comma-dangle": 0, + "semi": 1, + "react/no-danger-with-children": 1, + "react/no-string-refs": 1, + "react/prefer-es6-class": [ + 2, + "always" + ] + } +} diff --git a/src/webui/.eslintrc.yml b/src/webui/.eslintrc.yml deleted file mode 100644 index 41cbe141d..000000000 --- a/src/webui/.eslintrc.yml +++ /dev/null @@ -1,28 +0,0 @@ -# vim: syntax=yaml - - -## rules for react components - -extends: - - google - - eslint:recommended - - plugin:react/recommended - - plugin:flowtype/recommended - -plugins: - - flowtype - -parser: babel-eslint - -env: - node: true - browser: true - jest: true - -rules: - # jsdoc is mandatory - require-jsdoc: 0 - # jsx rules - react/no-danger-with-children: 0 - react/no-string-refs: 0 - diff --git a/src/webui/scripts/dev.server.js b/src/webui/scripts/dev.server.js index 18b3b2ccf..7dd2bf7bb 100644 --- a/src/webui/scripts/dev.server.js +++ b/src/webui/scripts/dev.server.js @@ -2,15 +2,15 @@ import webpack from 'webpack'; import WebpackDevServer from 'webpack-dev-server'; import config from './webpack.dev.config.babel'; import ora from 'ora'; -import env from '../../config/env' +import env from '../../config/env'; const compiler = webpack(config); const spinner = ora('Compiler is running...').start(); compiler.plugin('done', () => { if (!global.rebuild) { spinner.stop(); - console.log('Dev Server Listening at http://localhost:4872/') - global.rebuild = true + console.log('Dev Server Listening at http://localhost:4872/'); + global.rebuild = true; } }); @@ -30,8 +30,8 @@ new WebpackDevServer(compiler, { chunks: true, chunkModules: false } -}).listen(4872, 'localhost', function (err) { +}).listen(4872, 'localhost', function(err) { if (err) { return console.log(err); } -}) +}); diff --git a/src/webui/scripts/webpack.config.js b/src/webui/scripts/webpack.config.js index 80b07a902..823213b7d 100644 --- a/src/webui/scripts/webpack.config.js +++ b/src/webui/scripts/webpack.config.js @@ -1,11 +1,11 @@ -import env from '../../config/env' +import env from '../../config/env'; -const isDev = process.env.NODE_ENV === 'development' +const isDev = process.env.NODE_ENV === 'development'; export default { - entry: `${env.SRC_ROOT}/webui/src/index.jsx`, + entry: `${env.SRC_ROOT}/webui/src/index.js`, - output: { + output: { path: `${env.APP_ROOT}/static/`, filename: '[name].[hash].js' }, @@ -58,7 +58,7 @@ export default { } }, { - loader: "sass-loader" + loader: 'sass-loader' } ] }, diff --git a/src/webui/scripts/webpack.dev.config.babel.js b/src/webui/scripts/webpack.dev.config.babel.js index 05ca22c0c..c9869f873 100644 --- a/src/webui/scripts/webpack.dev.config.babel.js +++ b/src/webui/scripts/webpack.dev.config.babel.js @@ -1,8 +1,8 @@ import webpack from 'webpack'; import HTMLWebpackPlugin from 'html-webpack-plugin'; import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin'; -import baseConfig from './webpack.config' -import env from '../../config/env' +import baseConfig from './webpack.config'; +import env from '../../config/env'; export default { ...baseConfig, @@ -11,7 +11,7 @@ export default { 'react-hot-loader/patch', 'webpack-dev-server/client?http://localhost:4872', 'webpack/hot/only-dev-server', - `${env.SRC_ROOT}/webui/src/index.jsx` + `${env.SRC_ROOT}/webui/src/index.jss` ] }, @@ -22,7 +22,7 @@ export default { plugins: [ new webpack.DefinePlugin({ - __DEBUG__: true, + '__DEBUG__': true, 'process.env.NODE_ENV': '"development"' }), new HTMLWebpackPlugin({ @@ -37,4 +37,4 @@ export default { new webpack.NoEmitOnErrorsPlugin(), new FriendlyErrorsPlugin() ] -} +}; diff --git a/src/webui/scripts/webpack.prod.config.babel.js b/src/webui/scripts/webpack.prod.config.babel.js index 22eba2a2d..625ce0f69 100644 --- a/src/webui/scripts/webpack.prod.config.babel.js +++ b/src/webui/scripts/webpack.prod.config.babel.js @@ -1,24 +1,24 @@ import webpack from 'webpack'; import HTMLWebpackPlugin from 'html-webpack-plugin'; import ExtractTextPlugin from 'extract-text-webpack-plugin'; -import baseConfig from './webpack.config' -import env from '../../config/env' -import _ from 'lodash' +import baseConfig from './webpack.config'; +import env from '../../config/env'; +import _ from 'lodash'; baseConfig.module.rules - .filter(loader => - Array.isArray(loader.use) && loader.use.find(v => /css/.test(v.loader.split('-')[0])) - ).forEach(loader => { + .filter((loader) => + Array.isArray(loader.use) && loader.use.find((v) => /css/.test(v.loader.split('-')[0])) + ).forEach((loader) => { loader.use = ExtractTextPlugin.extract({ fallback: 'style-loader', use: _.tail(loader.use) - }) -}) + }); +}); export default { ...baseConfig, entry: { - main: `${env.SRC_ROOT}/webui/src/index.jsx` + main: `${env.SRC_ROOT}/webui/src/index.js` }, output: { @@ -27,7 +27,7 @@ export default { plugins: [ new webpack.DefinePlugin({ - __DEBUG__: false, + '__DEBUG__': false, 'process.env.NODE_ENV': '"production"' }), new webpack.optimize.UglifyJsPlugin({ @@ -47,4 +47,4 @@ export default { }), new webpack.NoEmitOnErrorsPlugin() ] -} +}; diff --git a/src/webui/src/App.jsx b/src/webui/src/app.js similarity index 65% rename from src/webui/src/App.jsx rename to src/webui/src/app.js index 44efc19ce..3c076c5b5 100644 --- a/src/webui/src/App.jsx +++ b/src/webui/src/app.js @@ -1,18 +1,18 @@ import React from 'react'; -import { HashRouter as Router, Route, Switch } from 'react-router-dom'; +import {HashRouter as Router, Route, Switch} from 'react-router-dom'; -import 'normalize.css' +import 'normalize.css'; -import 'element-theme-default' -import { i18n } from 'element-react' -import locale from 'element-react/src/locale/lang/en' +import 'element-theme-default'; +import {i18n} from 'element-react'; +import locale from 'element-react/src/locale/lang/en'; i18n.use(locale); -import Header from './components/Header' +import Header from './components/Header'; import Home from './modules/home'; import Detail from './modules/detail'; -import './styles/global.scss' +import './styles/global.scss'; export default class App extends React.Component { render() { diff --git a/src/webui/src/components/Header/index.js b/src/webui/src/components/Header/index.js index 6c5ef8d6d..cd004ad53 100644 --- a/src/webui/src/components/Header/index.js +++ b/src/webui/src/components/Header/index.js @@ -1,10 +1,10 @@ import React from 'react'; -import { Button, Dialog, Input, MessageBox } from 'element-react'; +import {Button, Dialog, Input, MessageBox} from 'element-react'; import styled from 'styled-components'; import API from '../../../utils/api'; import storage from '../../../utils/storage'; import _ from 'lodash'; -import { Link } from 'react-router-dom'; +import {Link} from 'react-router-dom'; import classes from './header.scss'; @@ -16,7 +16,7 @@ const SetupGuide = styled.figure` line-height: 18px; padding: 8px 0; color: #f9f2f4; -` +`; export default class Header extends React.Component { state = { @@ -25,25 +25,25 @@ export default class Header extends React.Component { password: '' } - constructor (props) { + constructor(props) { super(props); this.toggleLoginModal = this.toggleLoginModal.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } - toggleLoginModal () { + toggleLoginModal() { this.setState({ showLogin: !this.state.showLogin - }) + }); } - handleInput (name, e) { + handleInput(name, e) { this.setState({ [name]: e - }) + }); } - async handleSubmit () { + async handleSubmit() { if (this.state.username === '' || this.state.password === '') { return MessageBox.alert('Username or password can\'t be empty!'); } @@ -68,7 +68,7 @@ export default class Header extends React.Component { } } - get isTokenExpire () { + get isTokenExpire() { let token = storage.getItem('token'); if (!_.isString(token)) return true; let payload = token.split('.')[1]; @@ -90,12 +90,12 @@ export default class Header extends React.Component { return expired; } - handleLogout () { + handleLogout() { storage.clear(); location.reload(); } - renderUserActionButton () { + renderUserActionButton() { if (!this.isTokenExpire) { // TODO: Check jwt token expire return (