Skip to content

Commit 3e9343e

Browse files
authored
Merge pull request #10 from jsdrupal/prettier
Prettier
2 parents 48c7a4c + de74c79 commit 3e9343e

File tree

13 files changed

+444
-123
lines changed

13 files changed

+444
-123
lines changed

.circleci/config.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@ jobs:
3232
- node_modules
3333
key: build-v1-{{ .Branch }}-{{ .Revision }}
3434

35-
test:
35+
lint:
3636
<<: *defaults
3737
steps:
3838
- checkout
3939
- *restore-build
40-
- run: yarn test
40+
- run: yarn test:lint:ci
41+
- store_test_results:
42+
path: reports
43+
44+
unit:
45+
<<: *defaults
46+
steps:
47+
- checkout
48+
- *restore-build
49+
- run: yarn test:unit:ci
50+
- store_test_results:
51+
path: reports
4152

4253
dist:
4354
<<: *defaults
@@ -64,12 +75,16 @@ workflows:
6475
package:
6576
jobs:
6677
- build
67-
- test:
78+
- lint:
79+
requires:
80+
- build
81+
- unit:
6882
requires:
6983
- build
7084
- dist:
7185
requires:
72-
- test
86+
- lint
87+
- unit
7388
- build
7489
filters:
7590
branches:

.eslintrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": [
3+
"airbnb",
4+
"plugin:prettier/recommended"
5+
],
6+
"parser": "babel-eslint",
7+
"env": {
8+
"browser": true,
9+
"es6": true,
10+
"jest": true,
11+
"serviceworker": true
12+
},
13+
"rules": {
14+
"react/jsx-filename-extension": [1, { "extensions": [".js"] }],
15+
"jsx-a11y/anchor-is-valid": [ "error", {
16+
"aspects": [ "noHref" ]
17+
}],
18+
"no-param-reassign": [2, { "props": false }]
19+
}
20+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# testing
77
/coverage
8+
/reports
89

910
# production
1011
/build

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 80,
3+
"semi": true,
4+
"singleQuote": true,
5+
"trailingComma": "all"
6+
}

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,33 @@
44
"private": true,
55
"dependencies": {
66
"emotion": "^9.0.2",
7+
"prop-types": "^15.6.1",
78
"react": "^16.2.0",
89
"react-dom": "^16.2.0",
910
"react-router-dom": "^4.2.2"
1011
},
1112
"devDependencies": {
13+
"babel-eslint": "^8.2.2",
14+
"eslint": "^4.9.0",
15+
"eslint-config-airbnb": "^16.1.0",
16+
"eslint-config-prettier": "^2.9.0",
17+
"eslint-plugin-import": "^2.7.0",
18+
"eslint-plugin-jsx-a11y": "^6.0.2",
19+
"eslint-plugin-prettier": "^2.6.0",
20+
"eslint-plugin-react": "^7.4.0",
21+
"jest-junit": "^3.6.0",
22+
"prettier": "^1.11.1",
1223
"react-scripts": "1.1.1"
1324
},
1425
"scripts": {
26+
"prettier": "prettier --write 'src/**/*.js'",
1527
"start": "react-scripts start",
1628
"build": "react-scripts build",
17-
"test": "react-scripts test --env=jsdom",
29+
"test": "yarn test:lint && yarn test:unit",
30+
"test:unit": "react-scripts test --env=jsdom",
31+
"test:unit:ci": "CI=true JEST_JUNIT_OUTPUT=reports/jest-junit.xml react-scripts test --testResultsProcessor ./node_modules/jest-junit --env=jsdom",
32+
"test:lint": "eslint ./src --max-warnings=0",
33+
"test:lint:ci": "eslint ./src --max-warnings=0 --format junit -o reports/eslint-junit.xml",
1834
"eject": "react-scripts eject"
1935
}
2036
}

src/App.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { Component } from 'react';
2+
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
3+
4+
import routes from './routes';
5+
6+
import Home from './components/05_pages/Home/Home';
7+
import NoMatch from './NoMatch';
8+
9+
import normalize from './styles/normalize'; // eslint-disable-line no-unused-vars
10+
import base from './styles/base'; // eslint-disable-line no-unused-vars
11+
12+
class App extends Component {
13+
componentDidMount() {
14+
window.history.replaceState(null, null, '/');
15+
}
16+
render() {
17+
return (
18+
<Router>
19+
<div>
20+
<ul>
21+
<li>
22+
<Link to="/">Home</Link>
23+
</li>
24+
<li>
25+
<Link to="/admin/people/permissions">Permissions</Link>
26+
</li>
27+
<li>
28+
<Link to="/admin/appearance">Appearance</Link>
29+
</li>
30+
<li>
31+
<Link to="/node/add">Content</Link>
32+
</li>
33+
</ul>
34+
35+
<hr />
36+
37+
<Route exact path="/" component={Home} />
38+
{Object.keys(routes).map(route => (
39+
<Route path={route} component={routes[route]} key={route} />
40+
))}
41+
<Route component={NoMatch} />
42+
</div>
43+
</Router>
44+
);
45+
}
46+
}
47+
48+
export default App;

src/App.jsx

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/NoMatch.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Component } from 'react';
2+
import { shape, string } from 'prop-types';
3+
4+
import routes from './routes';
5+
6+
const NoMatch = class NoMatch extends Component {
7+
static propTypes = {
8+
location: shape({
9+
pathname: string.isRequired,
10+
}).isRequired,
11+
};
12+
componentWillReceiveProps(nextProps) {
13+
if (!Object.keys(routes).includes(nextProps.location.pathname)) {
14+
window.location = window.location.href;
15+
}
16+
}
17+
render() {
18+
return null;
19+
}
20+
};
21+
22+
export default NoMatch;
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import React from 'react';
22
import { css } from 'emotion';
33

4+
const styles = {
5+
title: css`
6+
text-decoration: underline;
7+
`,
8+
};
9+
410
const Permissions = () => (
511
<div>
612
<h1 className={styles.title}>Permissions</h1>
713
<p>This will be the permissions page.</p>
814
</div>
915
);
1016

11-
const styles = {
12-
title: css`
13-
text-decoration: underline;
14-
`,
15-
};
16-
1717
export default Permissions;
18-

src/registerServiceWorker.js

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,10 @@ const isLocalhost = Boolean(
1414
window.location.hostname === '[::1]' ||
1515
// 127.0.0.1/8 is considered localhost for IPv4.
1616
window.location.hostname.match(
17-
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
18-
)
17+
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
18+
),
1919
);
2020

21-
export default function register() {
22-
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
23-
// The URL constructor is available in all browsers that support SW.
24-
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
25-
if (publicUrl.origin !== window.location.origin) {
26-
// Our service worker won't work if PUBLIC_URL is on a different origin
27-
// from what our page is served on. This might happen if a CDN is used to
28-
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
29-
return;
30-
}
31-
32-
window.addEventListener('load', () => {
33-
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
34-
35-
if (isLocalhost) {
36-
// This is running on localhost. Lets check if a service worker still exists or not.
37-
checkValidServiceWorker(swUrl);
38-
39-
// Add some additional logging to localhost, pointing developers to the
40-
// service worker/PWA documentation.
41-
navigator.serviceWorker.ready.then(() => {
42-
console.log(
43-
'This web app is being served cache-first by a service ' +
44-
'worker. To learn more, visit https://goo.gl/SC7cgQ'
45-
);
46-
});
47-
} else {
48-
// Is not local host. Just register service worker
49-
registerValidSW(swUrl);
50-
}
51-
});
52-
}
53-
}
54-
5521
function registerValidSW(swUrl) {
5622
navigator.serviceWorker
5723
.register(swUrl)
@@ -65,20 +31,16 @@ function registerValidSW(swUrl) {
6531
// the fresh content will have been added to the cache.
6632
// It's the perfect time to display a "New content is
6733
// available; please refresh." message in your web app.
68-
console.log('New content is available; please refresh.');
6934
} else {
7035
// At this point, everything has been precached.
7136
// It's the perfect time to display a
7237
// "Content is cached for offline use." message.
73-
console.log('Content is cached for offline use.');
7438
}
7539
}
7640
};
7741
};
7842
})
79-
.catch(error => {
80-
console.error('Error during service worker registration:', error);
81-
});
43+
.catch(() => {});
8244
}
8345

8446
function checkValidServiceWorker(swUrl) {
@@ -101,11 +63,36 @@ function checkValidServiceWorker(swUrl) {
10163
registerValidSW(swUrl);
10264
}
10365
})
104-
.catch(() => {
105-
console.log(
106-
'No internet connection found. App is running in offline mode.'
107-
);
66+
.catch(() => {});
67+
}
68+
69+
export default function register() {
70+
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
71+
// The URL constructor is available in all browsers that support SW.
72+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
73+
if (publicUrl.origin !== window.location.origin) {
74+
// Our service worker won't work if PUBLIC_URL is on a different origin
75+
// from what our page is served on. This might happen if a CDN is used to
76+
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
77+
return;
78+
}
79+
80+
window.addEventListener('load', () => {
81+
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
82+
83+
if (isLocalhost) {
84+
// This is running on localhost. Lets check if a service worker still exists or not.
85+
checkValidServiceWorker(swUrl);
86+
87+
// Add some additional logging to localhost, pointing developers to the
88+
// service worker/PWA documentation.
89+
navigator.serviceWorker.ready.then(() => {});
90+
} else {
91+
// Is not local host. Just register service worker
92+
registerValidSW(swUrl);
93+
}
10894
});
95+
}
10996
}
11097

11198
export function unregister() {

src/routes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Permissions from './components/05_pages/Permissions/Permissions';
2+
3+
// @todo Share this with Drupal
4+
const routes = {
5+
'/admin/people/permissions': Permissions,
6+
};
7+
8+
export default routes;

0 commit comments

Comments
 (0)