Skip to content

Commit 78083e6

Browse files
committed
add eslint integration and clean up most files
1 parent dc5bdca commit 78083e6

15 files changed

+129
-96
lines changed

.eslintrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"ecmaFeatures": {
3+
"jsx": true,
4+
"modules": true
5+
},
6+
"env": {
7+
"browser": true,
8+
"node": true
9+
},
10+
"parser": "babel-eslint",
11+
"rules": {
12+
"no-undef": 2,
13+
"semi": [2, "always"],
14+
"quotes": [2, "double"],
15+
"strict": [2, "never"],
16+
"react/jsx-uses-react": 2,
17+
"react/jsx-uses-vars": 2
18+
},
19+
"plugins": [
20+
"react"
21+
],
22+
"globals": {
23+
"expect": true
24+
}
25+
}
26+

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
},
99
"scripts": {
1010
"start": "cd demo && webpack-dev-server --progress",
11+
"lint": "eslint 'src/**/*.js'",
1112
"test": "mocha --compilers js:babel-core/register __tests__",
13+
"validate": "npm run lint && npm run test",
1214
"test:watch": "mocha --compilers js:babel-core/register --watch __tests__",
1315
"compile": "webpack",
1416
"prepublish": "npm run compile",
@@ -36,6 +38,7 @@
3638
"devDependencies": {
3739
"babel": "^6.5.2",
3840
"babel-core": "^6.8.0",
41+
"babel-eslint": "^7.2.3",
3942
"babel-loader": "^6.2.4",
4043
"babel-plugin-transform-object-assign": "^6.8.0",
4144
"babel-preset-es2015": "^6.6.0",
@@ -44,6 +47,8 @@
4447
"babel-runtime": "^6.6.1",
4548
"chai": "^3.5.0",
4649
"enzyme": "^2.2.0",
50+
"eslint": "^3.19.0",
51+
"eslint-plugin-react": "^7.0.1",
4752
"hiff": "^0.3.0",
4853
"line-by-line": "^0.1.4",
4954
"mocha": "^3.2.0",

src/Sparklines.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import React from 'react';
2-
import SparklinesText from './SparklinesText';
3-
import SparklinesLine from './SparklinesLine';
4-
import SparklinesCurve from './SparklinesCurve';
5-
import SparklinesBars from './SparklinesBars';
6-
import SparklinesSpots from './SparklinesSpots';
7-
import SparklinesReferenceLine from './SparklinesReferenceLine';
8-
import SparklinesNormalBand from './SparklinesNormalBand';
9-
import dataToPoints from './dataProcessing/dataToPoints';
10-
import shallowCompare from 'react-addons-shallow-compare';
1+
import React from "react";
2+
import SparklinesText from "./SparklinesText";
3+
import SparklinesLine from "./SparklinesLine";
4+
import SparklinesCurve from "./SparklinesCurve";
5+
import SparklinesBars from "./SparklinesBars";
6+
import SparklinesSpots from "./SparklinesSpots";
7+
import SparklinesReferenceLine from "./SparklinesReferenceLine";
8+
import SparklinesNormalBand from "./SparklinesNormalBand";
9+
import dataToPoints from "./dataProcessing/dataToPoints";
10+
import shallowCompare from "react-addons-shallow-compare";
1111

1212
class Sparklines extends React.Component {
1313

@@ -30,8 +30,8 @@ class Sparklines extends React.Component {
3030
data: [],
3131
width: 240,
3232
height: 60,
33-
//Scale the graphic content of the given element non-uniformly if necessary such that the element's bounding box exactly matches the viewport rectangle.
34-
preserveAspectRatio: 'none', //https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
33+
//Scale the graphic content of the given element non-uniformly if necessary such that the element"s bounding box exactly matches the viewport rectangle.
34+
preserveAspectRatio: "none", //https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
3535
margin: 2
3636
};
3737

@@ -66,4 +66,4 @@ class Sparklines extends React.Component {
6666
}
6767
}
6868

69-
export { Sparklines, SparklinesLine, SparklinesCurve, SparklinesBars, SparklinesSpots, SparklinesReferenceLine, SparklinesNormalBand, SparklinesText }
69+
export { Sparklines, SparklinesLine, SparklinesCurve, SparklinesBars, SparklinesSpots, SparklinesReferenceLine, SparklinesNormalBand, SparklinesText };

src/SparklinesBars.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React from "react";
22

33
export default class SparklinesBars extends React.Component {
44

@@ -12,12 +12,12 @@ export default class SparklinesBars extends React.Component {
1212
};
1313

1414
static defaultProps = {
15-
style: { fill: 'slategray' }
15+
style: { fill: "slategray" }
1616
};
1717

1818
render() {
1919

20-
const { points, height, style, barWidth, onMouseMove } = this.props;
20+
const { points, height, margin, style, barWidth, onMouseMove } = this.props;
2121
const strokeWidth = 1 * ((style && style.strokeWidth) || 0);
2222
const marginWidth = margin ? 2*margin : 0;
2323
const width = barWidth || (points && points.length >= 2 ? Math.max(0, points[1].x - points[0].x - strokeWidth - marginWidth) : 0);
@@ -35,6 +35,6 @@ export default class SparklinesBars extends React.Component {
3535
onMouseMove={onMouseMove.bind(this, p)}/>
3636
)}
3737
</g>
38-
)
38+
);
3939
}
4040
}

src/SparklinesCurve.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React from "react";
22

33
export default class SparklinesCurve extends React.Component {
44

@@ -17,7 +17,7 @@ export default class SparklinesCurve extends React.Component {
1717
const curve = (p) => {
1818
let res;
1919
if (!prev) {
20-
res = [p.x, p.y]
20+
res = [p.x, p.y];
2121
} else {
2222
const len = (p.x - prev.x) * divisor;
2323
res = [ "C",
@@ -37,11 +37,12 @@ export default class SparklinesCurve extends React.Component {
3737
}
3838
prev = p;
3939
return res;
40-
41-
}
40+
};
41+
4242
const linePoints = points
4343
.map((p) => curve(p))
4444
.reduce((a, b) => a.concat(b));
45+
4546
const closePolyPoints = [
4647
"L" + points[points.length - 1].x, height - margin,
4748
margin, height - margin,
@@ -50,24 +51,24 @@ export default class SparklinesCurve extends React.Component {
5051
const fillPoints = linePoints.concat(closePolyPoints);
5152

5253
const lineStyle = {
53-
stroke: color || style.stroke || 'slategray',
54-
strokeWidth: style.strokeWidth || '1',
55-
strokeLinejoin: style.strokeLinejoin || 'round',
56-
strokeLinecap: style.strokeLinecap || 'round',
57-
fill: 'none'
54+
stroke: color || style.stroke || "slategray",
55+
strokeWidth: style.strokeWidth || "1",
56+
strokeLinejoin: style.strokeLinejoin || "round",
57+
strokeLinecap: style.strokeLinecap || "round",
58+
fill: "none"
5859
};
5960
const fillStyle = {
60-
stroke: style.stroke || 'none',
61-
strokeWidth: '0',
62-
fillOpacity: style.fillOpacity || '.1',
63-
fill: style.fill || color || 'slategray'
61+
stroke: style.stroke || "none",
62+
strokeWidth: "0",
63+
fillOpacity: style.fillOpacity || ".1",
64+
fill: style.fill || color || "slategray"
6465
};
6566

6667
return (
6768
<g>
68-
<path d={"M"+fillPoints.join(' ')} style={fillStyle} />
69-
<path d={"M"+linePoints.join(' ')} style={lineStyle} />
69+
<path d={"M"+fillPoints.join(" ")} style={fillStyle} />
70+
<path d={"M"+linePoints.join(" ")} style={lineStyle} />
7071
</g>
71-
)
72+
);
7273
}
73-
}
74+
};

src/SparklinesLine.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React from "react";
22

33
export default class SparklinesLine extends React.Component {
44

@@ -27,18 +27,18 @@ export default class SparklinesLine extends React.Component {
2727
const fillPoints = linePoints.concat(closePolyPoints);
2828

2929
const lineStyle = {
30-
stroke: color || style.stroke || 'slategray',
31-
strokeWidth: style.strokeWidth || '1',
32-
strokeLinejoin: style.strokeLinejoin || 'round',
33-
strokeLinecap: style.strokeLinecap || 'round',
34-
fill: 'none'
30+
stroke: color || style.stroke || "slategray",
31+
strokeWidth: style.strokeWidth || "1",
32+
strokeLinejoin: style.strokeLinejoin || "round",
33+
strokeLinecap: style.strokeLinecap || "round",
34+
fill: "none"
3535
};
3636
const fillStyle = {
37-
stroke: style.stroke || 'none',
38-
strokeWidth: '0',
39-
fillOpacity: style.fillOpacity || '.1',
40-
fill: style.fill || color || 'slategray',
41-
pointerEvents: 'auto'
37+
stroke: style.stroke || "none",
38+
strokeWidth: "0",
39+
fillOpacity: style.fillOpacity || ".1",
40+
fill: style.fill || color || "slategray",
41+
pointerEvents: "auto"
4242
};
4343

4444
const tooltips = points.map((p, i) => {
@@ -47,17 +47,17 @@ export default class SparklinesLine extends React.Component {
4747
cy={p.y}
4848
r={2}
4949
style={fillStyle}
50-
onMouseEnter={(e) => onMouseMove('enter', data[i], p)}
51-
onClick={(e) => onMouseMove('click', data[i], p)}
52-
/>)
50+
onMouseEnter={(e) => onMouseMove("enter", data[i], p)}
51+
onClick={(e) => onMouseMove("click", data[i], p)}
52+
/>);
5353
});
5454

5555
return (
5656
<g>
5757
{tooltips}
58-
<polyline points={fillPoints.join(' ')} style={fillStyle}/>
59-
<polyline points={linePoints.join(' ')} style={lineStyle}/>
58+
<polyline points={fillPoints.join(" ")} style={fillStyle}/>
59+
<polyline points={linePoints.join(" ")} style={lineStyle}/>
6060
</g>
61-
)
61+
);
6262
}
63-
}
63+
};

src/SparklinesNormalBand.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react';
2-
import mean from './dataProcessing/mean';
3-
import stdev from './dataProcessing/stdev';
1+
import React from "react";
2+
import mean from "./dataProcessing/mean";
3+
import stdev from "./dataProcessing/stdev";
44

55
export default class SparklinesNormalBand extends React.Component {
66

@@ -9,7 +9,7 @@ export default class SparklinesNormalBand extends React.Component {
99
};
1010

1111
static defaultProps = {
12-
style: { fill: 'red', fillOpacity: .1 }
12+
style: { fill: "red", fillOpacity: .1 }
1313
};
1414

1515
render() {
@@ -24,6 +24,6 @@ export default class SparklinesNormalBand extends React.Component {
2424
<rect x={points[0].x} y={dataMean - dataStdev + margin}
2525
width={points[points.length - 1].x - points[0].x} height={stdev * 2}
2626
style={style} />
27-
)
27+
);
2828
}
29-
}
29+
};

src/SparklinesReferenceLine.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
import React from 'react';
2-
import * as dataProcessing from './dataProcessing';
1+
import PropTypes from "prop-types";
2+
import React from "react";
3+
import * as dataProcessing from "./dataProcessing";
34

45
export default class SparklinesReferenceLine extends React.Component {
56

67
static propTypes = {
7-
type: React.PropTypes.oneOf(['max', 'min', 'mean', 'avg', 'median', 'custom']),
8-
value: React.PropTypes.number,
9-
style: React.PropTypes.object
8+
type: PropTypes.oneOf(["max", "min", "mean", "avg", "median", "custom"]),
9+
value: PropTypes.number,
10+
style: PropTypes.object
1011
};
1112

1213
static defaultProps = {
13-
type: 'mean',
14-
style: { stroke: 'red', strokeOpacity: .75, strokeDasharray: '2, 2' }
14+
type: "mean",
15+
style: { stroke: "red", strokeOpacity: .75, strokeDasharray: "2, 2" }
1516
};
1617

1718
render() {
1819

1920
const { points, margin, type, style, value } = this.props;
2021

2122
const ypoints = points.map(p => p.y);
22-
const y = type == 'custom' ? value : dataProcessing[type](ypoints);
23+
const y = type == "custom" ? value : dataProcessing[type](ypoints);
2324

2425
return (
2526
<line
2627
x1={points[0].x} y1={y + margin}
2728
x2={points[points.length - 1].x} y2={y + margin}
2829
style={style} />
29-
)
30+
);
3031
}
31-
}
32+
};

src/SparklinesSpots.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React from "react";
22

33
export default class SparklinesSpots extends React.Component {
44

@@ -11,15 +11,15 @@ export default class SparklinesSpots extends React.Component {
1111
static defaultProps = {
1212
size: 2,
1313
spotColors: {
14-
'-1': 'red',
15-
'0': 'black',
16-
'1': 'green'
14+
"-1": "red",
15+
"0": "black",
16+
"1": "green"
1717
}
1818
};
1919

2020
lastDirection(points) {
2121

22-
Math.sign = Math.sign || function(x) { return x > 0 ? 1 : -1; }
22+
Math.sign = Math.sign || function(x) { return x > 0 ? 1 : -1; };
2323

2424
return points.length < 2
2525
? 0
@@ -34,19 +34,19 @@ export default class SparklinesSpots extends React.Component {
3434
cx={points[0].x}
3535
cy={points[0].y}
3636
r={size}
37-
style={style} />
37+
style={style} />;
3838

3939
const endSpot = <circle
4040
cx={points[points.length - 1].x}
4141
cy={points[points.length - 1].y}
4242
r={size}
43-
style={style || { fill: spotColors[this.lastDirection(points)] }} />
43+
style={style || { fill: spotColors[this.lastDirection(points)] }} />;
4444

4545
return (
4646
<g>
4747
{style && startSpot}
4848
{endSpot}
4949
</g>
50-
)
50+
);
5151
}
52-
}
52+
};

0 commit comments

Comments
 (0)