Skip to content

Commit e39244d

Browse files
committed
Merge pull request #294 from plotly/linter-enforcers
Linter enforcers
2 parents 3e9288c + fa7afed commit e39244d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+826
-799
lines changed

.eslintrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"rules": {
1010
"no-trailing-spaces": [2],
11-
"no-multiple-empty-lines": [2, {"max": 3, "maxEOF": 1}],
11+
"no-multiple-empty-lines": [2, {"max": 2, "maxEOF": 1}],
1212
"linebreak-style": [2, "unix"],
1313
"indent": [2, 4, {"SwitchCase": 1}],
1414
"max-len": [0, 80],
@@ -19,10 +19,18 @@
1919
"comma-style": [2, "last"],
2020
"semi": [2],
2121
"semi-spacing": [2, {"before": false, "after": true}],
22-
"key-spacing": [0, {"beforeColon": false, "afterColon": true}],
22+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
23+
"keyword-spacing": [2, {"overrides": {
24+
"if": {"after": false},
25+
"for": {"after": false},
26+
"while": {"after": false},
27+
"switch": {"after": false},
28+
"catch": {"after": false}
29+
}}],
2330
"no-spaced-func": [2],
2431
"space-in-parens": [2, "never"],
2532
"space-before-function-paren": [2, "never"],
33+
"space-before-blocks": [2],
2634
"no-multi-spaces": [2],
2735
"space-infix-ops": [0, {"int32Hint": false}],
2836
"quotes": [2, "single"],

devtools/test_dashboard/buttons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ function plotButtons(plots, figDir) {
6565
/*
6666
* Grab the currently loaded plot and make an image - replacing the plot.
6767
*/
68-
if (!gd) return;
68+
if(!gd) return;
6969

7070
var layout = gd.layout;
7171
var data = gd.data;
7272

73-
if (!layout || !data) return;
73+
if(!layout || !data) return;
7474

7575
Plotly.Plots.getSubplotIds(gd._fullLayout, 'gl3d').forEach(function(key) {
7676
var scene = gd._fullLayout[key]._scene;

src/components/annotations/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ annotations.draw = function(gd, index, opt, value) {
186186
Plotly.Lib.extendFlat({}, value) :
187187
{text: 'New text'};
188188

189-
if (layout.annotations) {
189+
if(layout.annotations) {
190190
layout.annotations.splice(index, 0, rule);
191191
} else {
192192
layout.annotations = [rule];
@@ -363,7 +363,7 @@ annotations.draw = function(gd, index, opt, value) {
363363
.attr('data-unformatted', options.text)
364364
.text(options.text);
365365

366-
function textLayout(s){
366+
function textLayout(s) {
367367
s.call(Plotly.Drawing.font, font)
368368
.attr({
369369
'text-anchor': {
@@ -375,7 +375,7 @@ annotations.draw = function(gd, index, opt, value) {
375375
return s;
376376
}
377377

378-
function drawGraphicalElements(){
378+
function drawGraphicalElements() {
379379

380380
// make sure lines are aligned the way they will be
381381
// at the end, even if their position changes
@@ -395,8 +395,8 @@ annotations.draw = function(gd, index, opt, value) {
395395
options._w = annwidth;
396396
options._h = annheight;
397397

398-
function shiftFraction(v, anchor){
399-
if(anchor==='auto'){
398+
function shiftFraction(v, anchor) {
399+
if(anchor==='auto') {
400400
if(v < 1/3) anchor = 'left';
401401
else if(v > 2/3) anchor = 'right';
402402
else anchor = 'center';
@@ -469,7 +469,7 @@ annotations.draw = function(gd, index, opt, value) {
469469

470470
// make sure the arrowhead (if there is one)
471471
// and the annotation center are visible
472-
if(options.showarrow){
472+
if(options.showarrow) {
473473
arrowX = Plotly.Lib.constrain(annPosPx.x - options.ax, 1, fullLayout.width - 1);
474474
arrowY = Plotly.Lib.constrain(annPosPx.y - options.ay, 1, fullLayout.height - 1);
475475
}
@@ -498,7 +498,7 @@ annotations.draw = function(gd, index, opt, value) {
498498

499499
// add the arrow
500500
// uses options[arrowwidth,arrowcolor,arrowhead] for styling
501-
var drawArrow = function(dx, dy){
501+
var drawArrow = function(dx, dy) {
502502
d3.select(gd)
503503
.selectAll('.annotation-arrow-g[data-index="' + index + '"]')
504504
.remove();
@@ -541,7 +541,7 @@ annotations.draw = function(gd, index, opt, value) {
541541
return;
542542
}
543543

544-
edges.forEach(function(x){
544+
edges.forEach(function(x) {
545545
var p = lineIntersect(arrowX0, arrowY0, arrowX, arrowY,
546546
x[0], x[1], x[2], x[3]);
547547
if(p) {
@@ -572,7 +572,7 @@ annotations.draw = function(gd, index, opt, value) {
572572
.attr({
573573
'data-index': String(index),
574574
d: 'M3,3H-3V-3H3ZM0,0L' + (arrowX0-arrowX) + ',' + (arrowY0-arrowY),
575-
transform:'translate('+arrowX+','+arrowY+')'
575+
transform: 'translate('+arrowX+','+arrowY+')'
576576
})
577577
.style('stroke-width', (strokewidth+6)+'px')
578578
.call(Plotly.Color.stroke, 'rgba(0,0,0,0)')
@@ -711,7 +711,7 @@ annotations.draw = function(gd, index, opt, value) {
711711
if(gd._context.editable) {
712712
anntext.call(Plotly.util.makeEditable, ann)
713713
.call(textLayout)
714-
.on('edit', function(_text){
714+
.on('edit', function(_text) {
715715
options.text = _text;
716716
this.attr({'data-unformatted': options.text});
717717
this.call(textLayout);
@@ -839,7 +839,7 @@ annotations.calcAutorange = function(gd) {
839839
if(!annotationList.length || !gd._fullData.length) return;
840840

841841
var annotationAxes = {};
842-
annotationList.forEach(function(ann){
842+
annotationList.forEach(function(ann) {
843843
annotationAxes[ann.xref] = true;
844844
annotationAxes[ann.yref] = true;
845845
});
@@ -863,7 +863,7 @@ function annAutorange(gd) {
863863
// relative to their anchor points
864864
// use the arrow and the text bg rectangle,
865865
// as the whole anno may include hidden text in its bbox
866-
fullLayout.annotations.forEach(function(ann){
866+
fullLayout.annotations.forEach(function(ann) {
867867
var xa = Plotly.Axes.getFromId(gd, ann.xref),
868868
ya = Plotly.Axes.getFromId(gd, ann.yref);
869869
if(!(xa || ya)) return;

src/components/color/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ color.addOpacity = function(cstr, op) {
3939
// combine two colors into one apparent color
4040
// if back has transparency or is missing,
4141
// color.background is assumed behind it
42-
color.combine = function(front, back){
42+
color.combine = function(front, back) {
4343
var fc = tinycolor(front).toRgb();
4444
if(fc.a===1) return tinycolor(front).toRgbString();
4545

4646
var bc = tinycolor(back||color.background).toRgb(),
4747
bcflat = bc.a===1 ? bc : {
48-
r:255*(1-bc.a) + bc.r*bc.a,
49-
g:255*(1-bc.a) + bc.g*bc.a,
50-
b:255*(1-bc.a) + bc.b*bc.a
48+
r: 255 * (1-bc.a) + bc.r*bc.a,
49+
g: 255 * (1-bc.a) + bc.g*bc.a,
50+
b: 255 * (1-bc.a) + bc.b*bc.a
5151
},
5252
fcflat = {
53-
r:bcflat.r*(1-fc.a) + fc.r*fc.a,
54-
g:bcflat.g*(1-fc.a) + fc.g*fc.a,
55-
b:bcflat.b*(1-fc.a) + fc.b*fc.a
53+
r: bcflat.r*(1-fc.a) + fc.r*fc.a,
54+
g: bcflat.g*(1-fc.a) + fc.g*fc.a,
55+
b: bcflat.b*(1-fc.a) + fc.b*fc.a
5656
};
5757
return tinycolor(fcflat).toRgbString();
5858
};

src/components/colorbar/draw.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = function draw(gd, id) {
5050
// evaluated halfway between levels
5151
opts.filllevels = null;
5252

53-
function component(){
53+
function component() {
5454
var fullLayout = gd._fullLayout;
5555
if((typeof opts.fillcolor !== 'function') &&
5656
(typeof opts.line.color !== 'function')) {
@@ -63,9 +63,9 @@ module.exports = function draw(gd, id) {
6363
filllevels = [],
6464
l,
6565
linecolormap = typeof opts.line.color === 'function' ?
66-
opts.line.color : function(){ return opts.line.color; },
66+
opts.line.color : function() { return opts.line.color; },
6767
fillcolormap = typeof opts.fillcolor === 'function' ?
68-
opts.fillcolor : function(){ return opts.fillcolor; };
68+
opts.fillcolor : function() { return opts.fillcolor; };
6969

7070
var l0 = opts.levels.end + opts.levels.size/100,
7171
ls = opts.levels.size,
@@ -84,7 +84,7 @@ module.exports = function draw(gd, id) {
8484
}
8585
}
8686
else {
87-
filllevels = linelevels.map(function(v){
87+
filllevels = linelevels.map(function(v) {
8888
return v-opts.levels.size / 2;
8989
});
9090
filllevels.push(filllevels[filllevels.length - 1] +
@@ -132,7 +132,7 @@ module.exports = function draw(gd, id) {
132132

133133
// y positioning we can do correctly from the start
134134
yBottomFrac = opts.y + lenFrac *
135-
(({top:-0.5, bottom:0.5}[opts.yanchor]||0)-0.5),
135+
(({top: -0.5, bottom: 0.5}[opts.yanchor] || 0) - 0.5),
136136
yBottomPx = Math.round(fullLayout._size.h * (1-yBottomFrac)),
137137
yTopPx = yBottomPx-lenPx,
138138
titleEl,
@@ -233,7 +233,7 @@ module.exports = function draw(gd, id) {
233233
// now draw the elements
234234
var container = fullLayout._infolayer.selectAll('g.'+id).data([0]);
235235
container.enter().append('g').classed(id,true)
236-
.each(function(){
236+
.each(function() {
237237
var s = d3.select(this);
238238
s.append('rect').classed('cbbg',true);
239239
s.append('g').classed('cbfills',true);
@@ -260,7 +260,7 @@ module.exports = function draw(gd, id) {
260260
Titles.draw(gd, cbAxisOut._id + 'title');
261261
}
262262

263-
function drawAxis(){
263+
function drawAxis() {
264264
if(['top','bottom'].indexOf(opts.titleside)!==-1) {
265265
// squish the axis top to make room for the title
266266
var titleGroup = container.select('.cbtitle'),
@@ -373,7 +373,7 @@ module.exports = function draw(gd, id) {
373373
return Axes.doTicks(gd, cbAxisOut);
374374
}
375375

376-
function positionCB(){
376+
function positionCB() {
377377
// wait for the axis & title to finish rendering before
378378
// continuing positioning
379379
// TODO: why are we redrawing multiple times now with this?
@@ -431,7 +431,7 @@ module.exports = function draw(gd, id) {
431431
});
432432

433433
// fix positioning for xanchor!='left'
434-
var xoffset = ({center:0.5, right:1}[opts.xanchor]||0) *
434+
var xoffset = ({center: 0.5, right: 1}[opts.xanchor] || 0) *
435435
outerwidth;
436436
container.attr('transform',
437437
'translate('+(fullLayout._size.l-xoffset)+','+fullLayout._size.t+')');
@@ -440,10 +440,10 @@ module.exports = function draw(gd, id) {
440440
Plots.autoMargin(gd, id,{
441441
x: opts.x,
442442
y: opts.y,
443-
l: outerwidth*({right:1, center:0.5}[opts.xanchor]||0),
444-
r: outerwidth*({left:1, center:0.5}[opts.xanchor]||0),
445-
t: outerheight*({bottom:1, middle:0.5}[opts.yanchor]||0),
446-
b: outerheight*({top:1, middle:0.5}[opts.yanchor]||0)
443+
l: outerwidth * ({right: 1, center: 0.5}[opts.xanchor] || 0),
444+
r: outerwidth * ({left: 1, center: 0.5}[opts.xanchor] || 0),
445+
t: outerheight * ({bottom: 1, middle: 0.5}[opts.yanchor] || 0),
446+
b: outerheight * ({top: 1, middle: 0.5}[opts.yanchor] || 0)
447447
});
448448
}
449449

src/components/colorscale/is_valid_scale_array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function isValidScaleArray(scl) {
2020
if(!Array.isArray(scl)) return false;
2121
else {
2222
if(+scl[0][0]!==0 || +scl[scl.length-1][0]!==1) return false;
23-
for (var i = 0; i < scl.length; i++) {
23+
for(var i = 0; i < scl.length; i++) {
2424
si = scl[i];
2525
if(si.length!==2 || +si[0]<highestVal || !tinycolor(si[1]).isValid()) {
2626
isValid = false;

src/components/colorscale/scales.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010

1111

1212
module.exports = {
13-
'Greys':[[0,'rgb(0,0,0)'],[1,'rgb(255,255,255)']],
13+
'Greys': [[0,'rgb(0,0,0)'],[1,'rgb(255,255,255)']],
1414

15-
'YIGnBu':[[0,'rgb(8, 29, 88)'],[0.125,'rgb(37, 52, 148)'],
15+
'YIGnBu': [[0,'rgb(8, 29, 88)'],[0.125,'rgb(37, 52, 148)'],
1616
[0.25,'rgb(34, 94, 168)'],[0.375,'rgb(29, 145, 192)'],
1717
[0.5,'rgb(65, 182, 196)'],[0.625,'rgb(127, 205, 187)'],
1818
[0.75,'rgb(199, 233, 180)'],[0.875,'rgb(237, 248, 217)'],
1919
[1,'rgb(255, 255, 217)']],
2020

21-
'Greens':[[0,'rgb(0, 68, 27)'],[0.125,'rgb(0, 109, 44)'],
21+
'Greens': [[0,'rgb(0, 68, 27)'],[0.125,'rgb(0, 109, 44)'],
2222
[0.25,'rgb(35, 139, 69)'],[0.375,'rgb(65, 171, 93)'],
2323
[0.5,'rgb(116, 196, 118)'],[0.625,'rgb(161, 217, 155)'],
2424
[0.75,'rgb(199, 233, 192)'],[0.875,'rgb(229, 245, 224)'],
2525
[1,'rgb(247, 252, 245)']],
2626

27-
'YIOrRd':[[0,'rgb(128, 0, 38)'],[0.125,'rgb(189, 0, 38)'],
27+
'YIOrRd': [[0,'rgb(128, 0, 38)'],[0.125,'rgb(189, 0, 38)'],
2828
[0.25,'rgb(227, 26, 28)'],[0.375,'rgb(252, 78, 42)'],
2929
[0.5,'rgb(253, 141, 60)'],[0.625,'rgb(254, 178, 76)'],
3030
[0.75,'rgb(254, 217, 118)'],[0.875,'rgb(255, 237, 160)'],
3131
[1,'rgb(255, 255, 204)']],
3232

33-
'Bluered':[[0,'rgb(0,0,255)'],[1,'rgb(255,0,0)']],
33+
'Bluered': [[0,'rgb(0,0,255)'],[1,'rgb(255,0,0)']],
3434

3535
// modified RdBu based on
3636
// www.sandia.gov/~kmorel/documents/ColorMaps/ColorMapsExpanded.pdf
37-
'RdBu':[[0,'rgb(5, 10, 172)'],[0.35,'rgb(106, 137, 247)'],
37+
'RdBu': [[0,'rgb(5, 10, 172)'],[0.35,'rgb(106, 137, 247)'],
3838
[0.5,'rgb(190,190,190)'],[0.6,'rgb(220, 170, 132)'],
3939
[0.7,'rgb(230, 145, 90)'],[1,'rgb(178, 10, 28)']],
4040
// Scale for non-negative numeric values
@@ -45,39 +45,39 @@ module.exports = {
4545
[0.5, 'rgb(70, 100, 245)'], [0.6, 'rgb(90, 120, 245)'],
4646
[0.7, 'rgb(106, 137, 247)'], [1, 'rgb(220, 220, 220)']],
4747

48-
'Picnic':[[0,'rgb(0,0,255)'],[0.1,'rgb(51,153,255)'],
48+
'Picnic': [[0,'rgb(0,0,255)'],[0.1,'rgb(51,153,255)'],
4949
[0.2,'rgb(102,204,255)'],[0.3,'rgb(153,204,255)'],
5050
[0.4,'rgb(204,204,255)'],[0.5,'rgb(255,255,255)'],
5151
[0.6,'rgb(255,204,255)'],[0.7,'rgb(255,153,255)'],
5252
[0.8,'rgb(255,102,204)'],[0.9,'rgb(255,102,102)'],
5353
[1,'rgb(255,0,0)']],
5454

55-
'Rainbow':[[0,'rgb(150,0,90)'],[0.125,'rgb(0, 0, 200)'],
55+
'Rainbow': [[0,'rgb(150,0,90)'],[0.125,'rgb(0, 0, 200)'],
5656
[0.25,'rgb(0, 25, 255)'],[0.375,'rgb(0, 152, 255)'],
5757
[0.5,'rgb(44, 255, 150)'],[0.625,'rgb(151, 255, 0)'],
5858
[0.75,'rgb(255, 234, 0)'],[0.875,'rgb(255, 111, 0)'],
5959
[1,'rgb(255, 0, 0)']],
6060

61-
'Portland':[[0,'rgb(12,51,131)'],[0.25,'rgb(10,136,186)'],
61+
'Portland': [[0,'rgb(12,51,131)'],[0.25,'rgb(10,136,186)'],
6262
[0.5,'rgb(242,211,56)'],[0.75,'rgb(242,143,56)'],
6363
[1,'rgb(217,30,30)']],
6464

65-
'Jet':[[0,'rgb(0,0,131)'],[0.125,'rgb(0,60,170)'],
65+
'Jet': [[0,'rgb(0,0,131)'],[0.125,'rgb(0,60,170)'],
6666
[0.375,'rgb(5,255,255)'],[0.625,'rgb(255,255,0)'],
6767
[0.875,'rgb(250,0,0)'],[1,'rgb(128,0,0)']],
6868

69-
'Hot':[[0,'rgb(0,0,0)'],[0.3,'rgb(230,0,0)'],
69+
'Hot': [[0,'rgb(0,0,0)'],[0.3,'rgb(230,0,0)'],
7070
[0.6,'rgb(255,210,0)'],[1,'rgb(255,255,255)']],
7171

72-
'Blackbody':[[0,'rgb(0,0,0)'],[0.2,'rgb(230,0,0)'],
72+
'Blackbody': [[0,'rgb(0,0,0)'],[0.2,'rgb(230,0,0)'],
7373
[0.4,'rgb(230,210,0)'],[0.7,'rgb(255,255,255)'],
7474
[1,'rgb(160,200,255)']],
7575

76-
'Earth':[[0,'rgb(0,0,130)'],[0.1,'rgb(0,180,180)'],
76+
'Earth': [[0,'rgb(0,0,130)'],[0.1,'rgb(0,180,180)'],
7777
[0.2,'rgb(40,210,40)'],[0.4,'rgb(230,230,50)'],
7878
[0.6,'rgb(120,70,20)'],[1,'rgb(255,255,255)']],
7979

80-
'Electric':[[0,'rgb(0,0,0)'],[0.15,'rgb(30,0,100)'],
80+
'Electric': [[0,'rgb(0,0,0)'],[0.15,'rgb(30,0,100)'],
8181
[0.4,'rgb(120,0,100)'],[0.6,'rgb(160,90,0)'],
8282
[0.8,'rgb(230,200,0)'],[1,'rgb(255,250,220)']],
8383

0 commit comments

Comments
 (0)