Skip to content

Commit 387f895

Browse files
committed
add bnb linting
1 parent 18af009 commit 387f895

File tree

8 files changed

+374
-237
lines changed

8 files changed

+374
-237
lines changed

.eslintrc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"browser": true,
5+
"es6": true
6+
},
7+
"parser": "babel-eslint",
8+
"extends": "airbnb",
9+
"rules": {
10+
"no-console": 0,
11+
"no-param-reassign": 0,
12+
"no-use-before-define": 0,
13+
"react/jsx-filename-extension": 0,
14+
"react/prop-types": 0,
15+
"react/destructuring-assignment": 0
16+
}
17+
}

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
"d3-time-format": "^2.1.1",
2929
"dotenv": "4.0.0",
3030
"dotenv-expand": "4.2.0",
31-
"eslint": "4.10.0",
31+
"eslint": "5.3.0",
32+
"eslint-config-airbnb": "^17.1.0",
3233
"eslint-config-react-app": "^2.1.0",
3334
"eslint-loader": "1.9.0",
3435
"eslint-plugin-flowtype": "2.39.1",
35-
"eslint-plugin-import": "2.8.0",
36-
"eslint-plugin-jsx-a11y": "5.1.1",
37-
"eslint-plugin-react": "7.4.0",
36+
"eslint-plugin-import": "2.14",
37+
"eslint-plugin-jsx-a11y": "6.1.1",
38+
"eslint-plugin-react": "7.11",
3839
"extract-text-webpack-plugin": "3.0.2",
3940
"file-loader": "1.1.5",
4041
"fs-extra": "3.0.1",

src/components/DonutChart.js

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
1+
/* eslint-disable react/destructuring-assignment */
2+
13
import React, { Component } from 'react';
24
import { Pie } from '@vx/shape';
35
import { Group } from '@vx/group';
46

5-
class DonutChart extends Component {
7+
class DonutChart extends Component { // eslint-disable-line
68
render() {
7-
const selectName = this.props.selectName;
9+
const { selectName } = this.props;
810
const dataStatementTotal = this.props.data ? this.props.data.total[selectName] : { pct: 0 };
911
const remainder = 100 - dataStatementTotal.pct;
10-
const pctData = [{pct: dataStatementTotal.pct, rem: remainder}];
11-
const chartData = Object.keys(pctData[0])
12-
.map(k => ({usage: pctData[0][k] }));
13-
const width = parseInt((document.documentElement.offsetWidth/4-10).toFixed(0), 10);
14-
const height = parseInt((width/1.4).toFixed(0), 10);
12+
const pctData = [
13+
{
14+
pct: dataStatementTotal.pct,
15+
rem: remainder,
16+
},
17+
];
18+
const chartData = Object.keys(pctData[0]).map(k => ({ usage: pctData[0][k] }));
19+
const width = parseInt((document.documentElement.offsetWidth / 4 - 10).toFixed(0), 10);
20+
const height = parseInt((width / 1.4).toFixed(0), 10);
1521
if (width < 10) return null;
1622
const fills = ['#55CA01', '#F0FFE4'];
17-
const radius = Math.min(width, height)/2;
23+
const radius = Math.min(width, height) / 2;
1824
return (
1925
<svg width={width} height={height}>
20-
<Group top={height/2.5} left={width/2}>
26+
<Group top={height / 2.5} left={width / 2}>
2127
<Pie
2228
data={chartData}
2329
pieValue={d => d.usage}
24-
outerRadius={radius - (radius/3)}
25-
innerRadius={radius - (radius/2)}
30+
outerRadius={radius - (radius / 3)}
31+
innerRadius={radius - (radius / 2)}
2632
fill={d => fills[d.index]}
2733
padAngle={0}
2834
pieSort={(a, b) => a.index - b.index}
2935
/>
3036
<text
31-
dy={".33em"}
37+
dy=".33em"
3238
fontSize={52}
3339
fontWeight={800}
34-
textAnchor={"middle"}
35-
style={{ pointerEvents: "none" }}
40+
textAnchor="middle"
41+
style={{
42+
pointerEvents: 'none',
43+
}}
3644
fill="#fff"
3745
>
3846
{dataStatementTotal.pct.toFixed(0)}
3947
</text>
4048
<text
41-
dy={width/2.8}
49+
dy={width / 2.8}
4250
fontSize={24}
4351
fontWeight={200}
44-
textAnchor={"middle"}
45-
style={{ pointerEvents: "none" }}
46-
fill={"#80CCFF"}
52+
textAnchor="middle"
53+
style={{
54+
pointerEvents: 'none',
55+
}}
56+
fill="#80CCFF"
4757
>
4858
{selectName.toUpperCase()}
4959
</text>

src/components/LineChart.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ const ySelector = d => d.value;
1111

1212
class LineChart extends Component {
1313
state = {
14-
position: null
14+
position: null,
1515
};
16+
1617
render() {
1718
let statementTotals;
18-
if (this.props.data) {
19-
statementTotals = `${this.props.data.total.statements.total} TOTAL STATEMENTS`;
19+
const { data } = this.props;
20+
if (data) {
21+
statementTotals = `${this.props.data.total.statements.total} TOTAL STATEMENTS`; // eslint-disable-line react/destructuring-assignment
2022
}
2123
const { position } = this.state;
2224
// calculate graph width based on window minus padding
23-
const width = document.documentElement.offsetWidth-40;
25+
const width = document.documentElement.offsetWidth - 40;
2426
const height = 270;
2527
const margin = {
2628
top: 60,
27-
bottom: 30
29+
bottom: 30,
2830
};
2931
const yMax = height - margin.top - margin.bottom;
3032

@@ -86,12 +88,12 @@ class LineChart extends Component {
8688
data={sTotal}
8789
/>
8890
<text
89-
dy={"1.5em"}
90-
dx={".5em"}
91+
dy="1.5em"
92+
dx=".5em"
9193
fontSize={14}
9294
fontWeight={200}
93-
textAnchor={"left"}
94-
style={{ pointerEvents: "none" }}
95+
textAnchor="left"
96+
style={{ pointerEvents: 'none' }}
9597
fill="#60BFFF"
9698
>
9799
{statementTotals}
@@ -101,10 +103,10 @@ class LineChart extends Component {
101103
top={yMax + margin.top}
102104
stroke="#094c9b"
103105
tickStroke="transparent"
104-
tickLabelProps={(value, index) => ({
106+
tickLabelProps={(value, index) => ({ // eslint-disable-line no-unused-vars
105107
fill: '#9A9A9A',
106108
fontSize: 11,
107-
textAnchor: 'middle'
109+
textAnchor: 'middle',
108110
})}
109111
/>
110112
</svg>

src/components/StackChart.js

+33-34
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,53 @@
11
import React, { Component } from 'react';
2-
import {BarStackHorizontal} from '@vx/shape';
3-
import {Group} from '@vx/group';
4-
import {scaleBand, scaleLinear, scaleOrdinal} from '@vx/scale';
2+
import { BarStackHorizontal } from '@vx/shape';
3+
import { Group } from '@vx/group';
4+
import { scaleBand, scaleLinear, scaleOrdinal } from '@vx/scale';
55

66
class StackChart extends Component {
77
render() {
8-
// const dataTotals = require('../data/coverage-summary.json');
9-
const fileSet = this.props.fileSet;
8+
const { fileSet } = this.props;
109
// If props exist for data reurn them, otherwise return defaults
1110
const totalData = () => {
12-
if (this.props.data) {
13-
return this.props.data;
11+
if (this.props.data) { // eslint-disable-line react/destructuring-assignment
12+
return this.props.data; // eslint-disable-line react/destructuring-assignment
1413
}
15-
let dataObj = {};
16-
dataObj[fileSet] = {statements: {total: 1, covered: 0, skipped: 0, pct: 0}};
14+
const dataObj = {};
15+
dataObj[fileSet] = {
16+
statements: {
17+
total: 1, covered: 0, skipped: 0, pct: 0,
18+
},
19+
};
1720
return dataObj;
1821
};
19-
let dataTotals = totalData();
22+
const dataTotals = totalData();
2023
// Filter the target file groups and return 'statements' for our metric
2124
const dataSet = Object.keys(dataTotals)
22-
.filter((d) => {
23-
return d.includes(fileSet);
24-
})
25-
.map((d) => {
26-
return dataTotals[d]['statements'];
27-
});
25+
.filter(d => d.includes(fileSet))
26+
.map(d => dataTotals[d].statements);
2827
// Sum the statement values for one or many items
2928
const sumValues = (obj, key) => Object.values(obj).reduce((a, b) => {
3029
if (!b) {
3130
return a[key];
3231
}
3332
return typeof a === 'object' ? a[key] + b[key] : a + b[key];
3433
});
35-
let sTotal = dataSet.length >= 2 ? sumValues(dataSet, 'total') : dataSet[0].total;
36-
let sCovered = dataSet.length >= 2 ? sumValues(dataSet, 'covered') : dataSet[0].covered;
34+
const sTotal = dataSet.length >= 2 ? sumValues(dataSet, 'total') : dataSet[0].total;
35+
const sCovered = dataSet.length >= 2 ? sumValues(dataSet, 'covered') : dataSet[0].covered;
3736
// Work out precentage from totaled values
38-
let sPct = sCovered/sTotal*100;
37+
const sPct = sCovered / sTotal * 100;
3938
// Set the data
4039
const data = [{
4140
pct: sPct,
42-
diff: 100 - sPct
41+
diff: 100 - sPct,
4342
}];
4443
const keys = Object.keys(data[0]).map(d => d);
45-
const width = parseInt((document.documentElement.offsetWidth/8-5).toFixed(0), 10);
44+
const width = parseInt((document.documentElement.offsetWidth / 8 - 5).toFixed(0), 10);
4645
const height = 80;
4746
const margin = {
4847
top: 40,
4948
left: 0,
5049
right: 20,
51-
bottom: 20
50+
bottom: 20,
5251
};
5352
if (width < 10) return null;
5453

@@ -60,16 +59,16 @@ class StackChart extends Component {
6059
const xScale = scaleLinear({
6160
rangeRound: [0, xMax],
6261
domain: [0, 100],
63-
nice: true
62+
nice: true,
6463
});
6564
const yScale = scaleBand({
6665
rangeRound: [40, 0],
6766
domain: 1,
68-
padding: 0.4
67+
padding: 0.4,
6968
});
7069
const zScale = scaleOrdinal({
7170
domain: keys,
72-
range: ['#55CA01', '#F0FFE4']
71+
range: ['#55CA01', '#F0FFE4'],
7372
});
7473

7574
return (
@@ -87,23 +86,23 @@ class StackChart extends Component {
8786
zScale={zScale}
8887
/>
8988
<text
90-
dy={"-.7em"}
89+
dy="-.7em"
9190
fontSize={16}
9291
fontWeight={200}
93-
textAnchor={"left"}
94-
style={{ pointerEvents: "none" }}
95-
fill={"#F2F2F2"}
92+
textAnchor="left"
93+
style={{ pointerEvents: 'none' }}
94+
fill="#F2F2F2"
9695
>
9796
{fileSet}
9897
</text>
9998
<text
100-
dy={"1.1em"}
101-
dx={".3em"}
99+
dy="1.1em"
100+
dx=".3em"
102101
fontSize={16}
103102
fontWeight={200}
104-
textAnchor={"left"}
105-
style={{ pointerEvents: "none" }}
106-
fill={"#001E40"}
103+
textAnchor="left"
104+
style={{ pointerEvents: 'none' }}
105+
fill="#001E40"
107106
>
108107
{sPct.toFixed()}
109108
</text>

src/registerServiceWorker.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
// This link also includes instructions on opting out of this behavior.
1010

1111
const isLocalhost = Boolean(
12-
window.location.hostname === 'localhost' ||
12+
window.location.hostname === 'localhost'
1313
// [::1] is the IPv6 localhost address.
14-
window.location.hostname === '[::1]' ||
14+
|| window.location.hostname === '[::1]'
1515
// 127.0.0.1/8 is considered localhost for IPv4.
16-
window.location.hostname.match(
17-
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
18-
)
16+
|| window.location.hostname.match(
17+
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
18+
),
1919
);
2020

2121
export default function register() {
@@ -40,8 +40,8 @@ export default function register() {
4040
// service worker/PWA documentation.
4141
navigator.serviceWorker.ready.then(() => {
4242
console.log(
43-
'This web app is being served cache-first by a service ' +
44-
'worker. To learn more, visit https://goo.gl/SC7cgQ'
43+
'This web app is being served cache-first by a service '
44+
+ 'worker. To learn more, visit https://goo.gl/SC7cgQ',
4545
);
4646
});
4747
} else {
@@ -55,7 +55,7 @@ export default function register() {
5555
function registerValidSW(swUrl) {
5656
navigator.serviceWorker
5757
.register(swUrl)
58-
.then(registration => {
58+
.then((registration) => {
5959
registration.onupdatefound = () => {
6060
const installingWorker = registration.installing;
6161
installingWorker.onstatechange = () => {
@@ -76,22 +76,22 @@ function registerValidSW(swUrl) {
7676
};
7777
};
7878
})
79-
.catch(error => {
79+
.catch((error) => {
8080
console.error('Error during service worker registration:', error);
8181
});
8282
}
8383

8484
function checkValidServiceWorker(swUrl) {
8585
// Check if the service worker can be found. If it can't reload the page.
8686
fetch(swUrl)
87-
.then(response => {
87+
.then((response) => {
8888
// Ensure service worker exists, and that we really are getting a JS file.
8989
if (
90-
response.status === 404 ||
91-
response.headers.get('content-type').indexOf('javascript') === -1
90+
response.status === 404
91+
|| response.headers.get('content-type').indexOf('javascript') === -1
9292
) {
9393
// No service worker found. Probably a different app. Reload the page.
94-
navigator.serviceWorker.ready.then(registration => {
94+
navigator.serviceWorker.ready.then((registration) => {
9595
registration.unregister().then(() => {
9696
window.location.reload();
9797
});
@@ -103,14 +103,14 @@ function checkValidServiceWorker(swUrl) {
103103
})
104104
.catch(() => {
105105
console.log(
106-
'No internet connection found. App is running in offline mode.'
106+
'No internet connection found. App is running in offline mode.',
107107
);
108108
});
109109
}
110110

111111
export function unregister() {
112112
if ('serviceWorker' in navigator) {
113-
navigator.serviceWorker.ready.then(registration => {
113+
navigator.serviceWorker.ready.then((registration) => {
114114
registration.unregister();
115115
});
116116
}

0 commit comments

Comments
 (0)