Skip to content

Commit de6ef31

Browse files
pronebirdjschr
authored andcommitted
Add prettier (#58)
* Add prettier * Add formatting check to travis * Add re-formatted source code * Update eslint config * Update babel-eslint
1 parent 36acc11 commit de6ef31

File tree

17 files changed

+177
-142
lines changed

17 files changed

+177
-142
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.{js,json,css,html}]
12+
indent_style = space
13+
indent_size = 2

.eslintrc

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": [
3-
"eslint:recommended",
4-
"plugin:react/recommended"
3+
"eslint:recommended",
4+
"plugin:react/recommended",
5+
"prettier"
56
],
67
"parser": "babel-eslint",
78
"parserOptions": {
@@ -10,22 +11,17 @@
1011
"modules": true
1112
}
1213
},
13-
"plugins": [ "react" ],
14+
"plugins": [ "react" ],
1415
"rules": {
15-
"indent": [ 2, 2 ],
16-
"quotes": [ 2, "single" ],
17-
"linebreak-style": [ 2, "unix" ],
18-
"semi": [ 2, "always" ],
19-
"no-console": [ 0 ],
20-
"no-loop-func": [ 0 ],
21-
"new-cap": [ 0 ],
22-
"no-trailing-spaces": [ 0 ],
23-
"no-param-reassign": [ 0 ],
24-
"func-names": [ 0 ],
25-
"comma-dangle": [ 0 ],
26-
"no-unused-expressions" : [ 0 ], // until fixed https://github.com/babel/babel-eslint/issues/158
27-
"block-scoped-var": [ 0 ], // until fixed https://github.com/eslint/eslint/issues/2253
28-
"react/prop-types": [ 0 ]
16+
"prefer-const": "warn",
17+
"no-console": "off",
18+
"no-loop-func": "warn",
19+
"new-cap": "off",
20+
"no-param-reassign": "warn",
21+
"func-names": "off",
22+
"no-unused-expressions" : "error",
23+
"block-scoped-var": "error",
24+
"react/prop-types": "off"
2925
},
3026
"env": {
3127
"es6": true,

.prettierrc.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# .prettierrc.yml
2+
# see: https://prettier.io/docs/en/options.html
3+
printWidth: 100
4+
semi: true
5+
singleQuote: true
6+
trailingComma: all
7+
bracketSpacing: true
8+
jsxBracketSameLine: true
9+
arrowParens: always
10+
proseWrap: always

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ install:
1212
- npm install
1313

1414
script:
15+
- npm run check-format
1516
- npm run lint
1617
- npm test

app/actions/user.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { createAction } from 'redux-actions';
22

33
export default {
44
login: createAction('USER_LOGIN'),
5-
logout: createAction('USER_LOGOUT')
5+
logout: createAction('USER_LOGOUT'),
66
};

app/app.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import configureStore from './store';
88

99
const syncHistoryWithStore = (store, history) => {
1010
const { routing } = store.getState();
11-
if(routing && routing.location) {
11+
if (routing && routing.location) {
1212
history.replace(routing.location);
1313
}
1414
};
@@ -22,9 +22,7 @@ const rootElement = document.querySelector(document.currentScript.getAttribute('
2222

2323
ReactDOM.render(
2424
<Provider store={store}>
25-
<ConnectedRouter history={routerHistory}>
26-
{routes}
27-
</ConnectedRouter>
25+
<ConnectedRouter history={routerHistory}>{routes}</ConnectedRouter>
2826
</Provider>,
29-
rootElement
27+
rootElement,
3028
);

app/components/LoggedIn.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import PropTypes from 'prop-types';
33

44
export default class LoggedIn extends Component {
55
static propTypes = {
6-
onLogout: PropTypes.func.isRequired
6+
onLogout: PropTypes.func.isRequired,
77
};
88

99
handleLogout = () => {
1010
this.props.onLogout({
1111
username: '',
12-
loggedIn: false
12+
loggedIn: false,
1313
});
1414
};
1515

app/components/Login.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ import PropTypes from 'prop-types';
33

44
export default class Login extends Component {
55
static propTypes = {
6-
onLogin: PropTypes.func.isRequired
6+
onLogin: PropTypes.func.isRequired,
77
};
88

99
state = {
10-
username: ''
10+
username: '',
1111
};
1212

1313
handleLogin = () => {
1414
this.props.onLogin({
1515
username: this.state.username,
16-
loggedIn: true
16+
loggedIn: true,
1717
});
18-
}
18+
};
1919

2020
handleChange = (e) => {
2121
this.setState({
22-
username: e.target.value
22+
username: e.target.value,
2323
});
24-
}
24+
};
2525

2626
render() {
2727
return (

app/containers/LoggedInPage.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ const mapDispatchToProps = (dispatch) => {
1414
onLogout: (data) => {
1515
user.logout(data);
1616
dispatch(push('/'));
17-
}
17+
},
1818
};
1919
};
2020

21-
export default connect(mapStateToProps, mapDispatchToProps)(LoggedIn);
21+
export default connect(
22+
mapStateToProps,
23+
mapDispatchToProps,
24+
)(LoggedIn);

app/containers/LoginPage.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ const mapDispatchToProps = (dispatch) => {
1414
onLogin: (data) => {
1515
user.login(data);
1616
dispatch(push('/loggedin'));
17-
}
17+
},
1818
};
1919
};
2020

21-
export default connect(mapStateToProps, mapDispatchToProps)(Login);
21+
export default connect(
22+
mapStateToProps,
23+
mapDispatchToProps,
24+
)(Login);

app/main.js

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import path from 'path';
22
import url from 'url';
3-
import {app, crashReporter, BrowserWindow, Menu} from 'electron';
3+
import { app, crashReporter, BrowserWindow, Menu } from 'electron';
44

5-
const isDevelopment = (process.env.NODE_ENV === 'development');
5+
const isDevelopment = process.env.NODE_ENV === 'development';
66

77
let mainWindow = null;
88
let forceQuit = false;
99

1010
const installExtensions = async () => {
1111
const installer = require('electron-devtools-installer');
12-
const extensions = [
13-
'REACT_DEVELOPER_TOOLS',
14-
'REDUX_DEVTOOLS'
15-
];
12+
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];
1613
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
1714
for (const name of extensions) {
1815
try {
@@ -27,7 +24,7 @@ crashReporter.start({
2724
productName: 'YourName',
2825
companyName: 'YourCompany',
2926
submitURL: 'https://your-domain.com/url-to-submit',
30-
uploadToServer: false
27+
uploadToServer: false,
3128
});
3229

3330
app.on('window-all-closed', () => {
@@ -43,19 +40,21 @@ app.on('ready', async () => {
4340
await installExtensions();
4441
}
4542

46-
mainWindow = new BrowserWindow({
47-
width: 1000,
43+
mainWindow = new BrowserWindow({
44+
width: 1000,
4845
height: 800,
4946
minWidth: 640,
5047
minHeight: 480,
51-
show: false
48+
show: false,
5249
});
5350

54-
mainWindow.loadURL(url.format({
55-
pathname: path.join(__dirname, 'index.html'),
56-
protocol: 'file:',
57-
slashes: true
58-
}));
51+
mainWindow.loadURL(
52+
url.format({
53+
pathname: path.join(__dirname, 'index.html'),
54+
protocol: 'file:',
55+
slashes: true,
56+
}),
57+
);
5958

6059
// show window once on first load
6160
mainWindow.webContents.once('did-finish-load', () => {
@@ -68,7 +67,7 @@ app.on('ready', async () => {
6867
// 2. Click on icon in dock should re-open the window
6968
// 3. ⌘+Q should close the window and quit the app
7069
if (process.platform === 'darwin') {
71-
mainWindow.on('close', function (e) {
70+
mainWindow.on('close', function(e) {
7271
if (!forceQuit) {
7372
e.preventDefault();
7473
mainWindow.hide();
@@ -78,7 +77,7 @@ app.on('ready', async () => {
7877
app.on('activate', () => {
7978
mainWindow.show();
8079
});
81-
80+
8281
app.on('before-quit', () => {
8382
forceQuit = true;
8483
});
@@ -95,12 +94,14 @@ app.on('ready', async () => {
9594

9695
// add inspect element on right click menu
9796
mainWindow.webContents.on('context-menu', (e, props) => {
98-
Menu.buildFromTemplate([{
99-
label: 'Inspect element',
100-
click() {
101-
mainWindow.inspectElement(props.x, props.y);
102-
}
103-
}]).popup(mainWindow);
97+
Menu.buildFromTemplate([
98+
{
99+
label: 'Inspect element',
100+
click() {
101+
mainWindow.inspectElement(props.x, props.y);
102+
},
103+
},
104+
]).popup(mainWindow);
104105
});
105106
}
106107
});

app/reducers/user.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { handleActions } from 'redux-actions';
22
import actions from '../actions/user';
33

4-
export default handleActions({
5-
[actions.login]: (state, action) => {
6-
return { ...state, ...action.payload };
4+
export default handleActions(
5+
{
6+
[actions.login]: (state, action) => {
7+
return { ...state, ...action.payload };
8+
},
9+
[actions.logout]: (state, action) => {
10+
return { ...state, ...action.payload };
11+
},
712
},
8-
[actions.logout]: (state, action) => {
9-
return { ...state, ...action.payload };
10-
}
11-
}, {});
13+
{},
14+
);

app/store.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ export default function configureStore(initialState, routerHistory) {
1111

1212
const actionCreators = {
1313
...userActions,
14-
push
14+
push,
1515
};
1616

1717
const reducers = {
1818
user,
19-
routing
19+
routing,
2020
};
2121

22-
const middlewares = [ thunk, router ];
22+
const middlewares = [thunk, router];
2323

2424
const composeEnhancers = (() => {
2525
const compose_ = window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
26-
if(process.env.NODE_ENV === 'development' && compose_) {
26+
if (process.env.NODE_ENV === 'development' && compose_) {
2727
return compose_({ actionCreators });
2828
}
2929
return compose;

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"babel-runtime": "^6.22.0",
1414
"history": "^4.6.3",
15+
"prettier": "1.13.7",
1516
"prop-types": "^15.5.10",
1617
"react": "^16.2.0",
1718
"react-dom": "^16.2.0",
@@ -26,7 +27,7 @@
2627
"devDependencies": {
2728
"babel-cli": "^6.22.2",
2829
"babel-core": "^6.2.1",
29-
"babel-eslint": "^8.2.2",
30+
"babel-eslint": "^8.2.6",
3031
"babel-plugin-transform-decorators-legacy": "^1.3.4",
3132
"babel-plugin-transform-runtime": "^6.22.0",
3233
"babel-preset-es2015": "^6.1.18",
@@ -39,6 +40,7 @@
3940
"electron-devtools-installer": "^2.1.0",
4041
"electron-mocha": "^6.0.1",
4142
"eslint": "^4.3.0",
43+
"eslint-config-prettier": "^2.9.0",
4244
"eslint-plugin-react": "^7.1.0",
4345
"npm-run-all": "^4.0.1",
4446
"redux-mock-store": "^1.2.2",
@@ -49,6 +51,8 @@
4951
"develop": "npm run private:compile -- --source-maps true && run-p -r private:watch private:serve",
5052
"test": "electron-mocha --renderer -R spec --require babel-core/register test/**/*.spec.js",
5153
"lint": "eslint --no-ignore scripts app test *.js",
54+
"format": "npm run private:format -- --write",
55+
"check-format": "npm run private:format -- --list-different",
5256
"pack": "run-s private:clean private:compile private:build:all",
5357
"pack:mac": "run-s private:clean private:compile private:build:mac",
5458
"pack:win": "run-s private:clean private:compile private:build:win",
@@ -60,6 +64,7 @@
6064
"private:watch": "npm run private:compile -- --source-maps true --watch --skip-initial-build",
6165
"private:serve": "babel-node scripts/serve.js",
6266
"private:compile": "babel app/ --copy-files --out-dir build",
63-
"private:clean": "rimraf build"
67+
"private:clean": "rimraf build",
68+
"private:format": "prettier \"scripts/*.js\" \"app/**/*.js\" \"test/**/*.js\""
6469
}
6570
}

0 commit comments

Comments
 (0)