Skip to content

Commit df35b38

Browse files
authored
Merge pull request #3757 from plotly/eslint-1tbs-fix-all-else
Eslint 1tbs help update else statement blocks
2 parents 5d051e7 + bf082cb commit df35b38

File tree

168 files changed

+820
-1419
lines changed

Some content is hidden

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

168 files changed

+820
-1419
lines changed

.eslintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"eslint:recommended"
55
],
66
"parserOptions": {
7-
"ecmaVersion": 5,
7+
"ecmaVersion": 5
88
},
99
"env": {
1010
"commonjs": true
@@ -27,7 +27,7 @@
2727
"indent": [0],
2828
"indent-legacy": [2, 4, {"SwitchCase": 1}],
2929
"max-len": [0, 80],
30-
"brace-style": [0, "stroustrup", {"allowSingleLine": true}],
30+
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
3131
"curly": [2, "multi-line"],
3232
"camelcase": [2, {"properties": "never"}],
3333
"comma-spacing": [2, {"before": false, "after": true}],

devtools/test_dashboard/perf.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ window.timeit = function(f, n, nchunk, arg) {
2525
for(var j = 0; j < nchunk; j++) { f(_arg); }
2626
t1 = performance.now();
2727
dt = (t1 - t0) / nchunk;
28-
}
29-
else {
28+
} else {
3029
t0 = performance.now();
3130
f(_arg);
3231
t1 = performance.now();

src/components/annotations/click.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ function getToggleSets(gd, hoverData) {
111111
if(anni.visible) {
112112
if(showMode === 'onout') toggleType = offSet;
113113
else toggleType = explicitOffSet;
114-
}
115-
else {
114+
} else {
116115
toggleType = onSet;
117116
}
118117
toggleType.push(i);

src/components/annotations/draw.js

+9-18
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,11 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
316316
}
317317
basePx = ax._offset + ax.r2p(options[axLetter]);
318318
autoAlignFraction = 0.5;
319-
}
320-
else {
319+
} else {
321320
if(axLetter === 'x') {
322321
alignPosition = options[axLetter];
323322
basePx = gs.l + gs.w * alignPosition;
324-
}
325-
else {
323+
} else {
326324
alignPosition = 1 - options[axLetter];
327325
basePx = gs.t + gs.h * alignPosition;
328326
}
@@ -344,8 +342,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
344342
posPx.tail = ax._offset + ax.r2p(arrowLength);
345343
// tail is data-referenced: autorange pads the text in px from the tail
346344
textPadShift = textShift;
347-
}
348-
else {
345+
} else {
349346
posPx.tail = basePx + arrowLength;
350347
// tail is specified in px from head, so autorange also pads vs head
351348
textPadShift = textShift + arrowLength;
@@ -365,17 +362,15 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
365362
if(shiftPlus > 0) {
366363
posPx.tail += shiftPlus;
367364
posPx.text += shiftPlus;
368-
}
369-
else if(shiftMinus > 0) {
365+
} else if(shiftMinus > 0) {
370366
posPx.tail -= shiftMinus;
371367
posPx.text -= shiftMinus;
372368
}
373369
}
374370

375371
posPx.tail += overallShift;
376372
posPx.head += overallShift;
377-
}
378-
else {
373+
} else {
379374
// with no arrow, the text rotates and *then* we put the anchor
380375
// relative to the new bounding box
381376
textShift = annSize * shiftFraction(autoAlignFraction, anchor);
@@ -419,8 +414,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
419414
y: borderfull + yShift
420415
})
421416
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);
422-
}
423-
else {
417+
} else {
424418
var texty = borderfull + yShift - anntextBB.top;
425419
var textx = borderfull + xShift - anntextBB.left;
426420

@@ -629,8 +623,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
629623
}
630624

631625
drawArrow(dx, dy);
632-
}
633-
else if(!subplotId) {
626+
} else if(!subplotId) {
634627
var xUpdate, yUpdate;
635628
if(xa) {
636629
xUpdate = xa.p2r(xa.r2p(options.x) + dx);
@@ -660,8 +653,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
660653
options.xanchor, options.yanchor
661654
);
662655
}
663-
}
664-
else return;
656+
} else return;
665657

666658
annTextGroup.attr({
667659
transform: 'translate(' + dx + ',' + dy + ')' + baseTextTransform
@@ -698,6 +690,5 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
698690

699691
Registry.call('_guiRelayout', gd, getUpdateObj());
700692
});
701-
}
702-
else annText.call(textLayout);
693+
} else annText.call(textLayout);
703694
}

src/components/annotations/draw_arrow_head.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ module.exports = function drawArrowHead(el3, ends, options) {
8989
start.y -= startbackOffY;
9090
el3.attr({x1: start.x, y1: start.y});
9191
}
92-
}
93-
else if(el.nodeName === 'path') {
92+
} else if(el.nodeName === 'path') {
9493
var pathlen = el.getTotalLength();
9594
// using dash to hide the backOff region of the path.
9695
// if we ever allow dash for the arrow we'll have to

src/components/calendars/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,15 @@ function worldCalFmt(fmt, x, calendar) {
137137
directiveLen = 3;
138138
directive = fmt.charAt(i + 2);
139139
if(modifier === '_') modifier = '-';
140-
}
141-
else {
140+
} else {
142141
directive = modifier;
143142
modifier = '0';
144143
directiveLen = 2;
145144
}
146145
directiveObj = d3ToWorldCalendars[directive];
147146
if(!directiveObj) {
148147
i += directiveLen;
149-
}
150-
else {
148+
} else {
151149
// code is recognized as a date part but world-calendars doesn't support it
152150
if(directiveObj === UNKNOWN) replacementPart = UNKNOWN;
153151

src/components/color/index.js

+21-15
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,26 @@ color.clean = function(container) {
106106
key = keys[i];
107107
val = container[key];
108108

109-
// only sanitize keys that end in "color" or "colorscale"
110109
if(key.substr(key.length - 5) === 'color') {
110+
// only sanitize keys that end in "color" or "colorscale"
111+
111112
if(Array.isArray(val)) {
112113
for(j = 0; j < val.length; j++) val[j] = cleanOne(val[j]);
113-
}
114-
else container[key] = cleanOne(val);
115-
}
116-
else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
114+
} else container[key] = cleanOne(val);
115+
} else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
117116
// colorscales have the format [[0, color1], [frac, color2], ... [1, colorN]]
117+
118118
for(j = 0; j < val.length; j++) {
119119
if(Array.isArray(val[j])) val[j][1] = cleanOne(val[j][1]);
120120
}
121-
}
122-
// recurse into arrays of objects, and plain objects
123-
else if(Array.isArray(val)) {
121+
} else if(Array.isArray(val)) {
122+
// recurse into arrays of objects, and plain objects
123+
124124
var el0 = val[0];
125125
if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
126126
for(j = 0; j < val.length; j++) color.clean(val[j]);
127127
}
128-
}
129-
else if(val && typeof val === 'object') color.clean(val);
128+
} else if(val && typeof val === 'object') color.clean(val);
130129
}
131130
};
132131

@@ -147,14 +146,21 @@ function cleanOne(val) {
147146
if(!parts[i].length) return val;
148147
parts[i] = Number(parts[i]);
149148

150-
// all parts must be non-negative numbers
151-
if(!(parts[i] >= 0)) return val;
152-
// alpha>1 gets clipped to 1
149+
if(!(parts[i] >= 0)) {
150+
// all parts must be non-negative numbers
151+
152+
return val;
153+
}
154+
153155
if(i === 3) {
156+
// alpha>1 gets clipped to 1
157+
154158
if(parts[i] > 1) parts[i] = 1;
159+
} else if(parts[i] >= 1) {
160+
// r, g, b must be < 1 (ie 1 itself is not allowed)
161+
162+
return val;
155163
}
156-
// r, g, b must be < 1 (ie 1 itself is not allowed)
157-
else if(parts[i] >= 1) return val;
158164
}
159165

160166
var rgbStr = Math.round(parts[0] * 255) + ', ' +

src/components/colorbar/draw.js

+10-20
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ module.exports = function draw(gd, id) {
9595

9696
if(opts.fillgradient) {
9797
filllevels = [0];
98-
}
99-
else if(typeof opts.fillcolor === 'function') {
98+
} else if(typeof opts.fillcolor === 'function') {
10099
if(opts.filllevels) {
101100
l0 = opts.filllevels.end + opts.filllevels.size / 100;
102101
ls = opts.filllevels.size;
@@ -105,16 +104,14 @@ module.exports = function draw(gd, id) {
105104
if(ls > 0 ? (l >= l0) : (l <= l0)) break;
106105
if(l > zrange[0] && l < zrange[1]) filllevels.push(l);
107106
}
108-
}
109-
else {
107+
} else {
110108
filllevels = linelevels.map(function(v) {
111109
return v - opts.levels.size / 2;
112110
});
113111
filllevels.push(filllevels[filllevels.length - 1] +
114112
opts.levels.size);
115113
}
116-
}
117-
else if(opts.fillcolor && typeof opts.fillcolor === 'string') {
114+
} else if(opts.fillcolor && typeof opts.fillcolor === 'string') {
118115
// doesn't matter what this value is, with a single value
119116
// we'll make a single fill rect covering the whole bar
120117
filllevels = [0];
@@ -292,8 +289,7 @@ module.exports = function draw(gd, id) {
292289
if(opts.title.side === 'top') {
293290
y = (1 - (yBottomFrac + lenFrac - ypadFrac)) * gs.h +
294291
gs.t + 3 + fontSize * 0.75;
295-
}
296-
else {
292+
} else {
297293
y = (1 - (yBottomFrac + ypadFrac)) * gs.h +
298294
gs.t - 3 - fontSize * 0.25;
299295
}
@@ -323,8 +319,7 @@ module.exports = function draw(gd, id) {
323319
// vertical alignment, but this seems to work.
324320
titleTrans[1] -= (titleHeight - lineSize) / 2;
325321
}
326-
}
327-
else if(titleText.node() &&
322+
} else if(titleText.node() &&
328323
!titleText.classed(cn.jsPlaceholder)) {
329324
titleHeight = Drawing.bBox(titleText.node()).height;
330325
}
@@ -336,8 +331,7 @@ module.exports = function draw(gd, id) {
336331
if(opts.title.side === 'top') {
337332
cbAxisOut.domain[1] -= titleHeight / gs.h;
338333
titleTrans[1] *= -1;
339-
}
340-
else {
334+
} else {
341335
cbAxisOut.domain[0] += titleHeight / gs.h;
342336
var nlines = svgTextUtils.lineCount(titleText);
343337
titleTrans[1] += (1 - nlines) * lineSize;
@@ -395,8 +389,7 @@ module.exports = function draw(gd, id) {
395389
if(opts.fillgradient) {
396390
Drawing.gradient(fillEl, gd, id, 'vertical',
397391
opts.fillgradient, 'fill');
398-
}
399-
else {
392+
} else {
400393
// Tinycolor can't handle exponents and
401394
// at this scale, removing it makes no difference.
402395
var colorString = fillcolormap(d).replace('e-', '');
@@ -514,8 +507,7 @@ module.exports = function draw(gd, id) {
514507
if(mathJaxNode &&
515508
['top', 'bottom'].indexOf(opts.title.side) !== -1) {
516509
titleWidth = Drawing.bBox(mathJaxNode).width;
517-
}
518-
else {
510+
} else {
519511
// note: the formula below works for all title sides,
520512
// (except for top/bottom mathjax, above)
521513
// but the weird gs.l is because the titleunshift
@@ -569,8 +561,7 @@ module.exports = function draw(gd, id) {
569561
marginOpts.y = opts.y;
570562
marginOpts.t = outerheight * tFrac;
571563
marginOpts.b = outerheight * bFrac;
572-
}
573-
else {
564+
} else {
574565
marginOpts.t = marginOpts.b = 0;
575566
marginOpts.yt = opts.y + opts.len * tFrac;
576567
marginOpts.yb = opts.y - opts.len * bFrac;
@@ -582,8 +573,7 @@ module.exports = function draw(gd, id) {
582573
marginOpts.x = opts.x;
583574
marginOpts.l = outerwidth * lFrac;
584575
marginOpts.r = outerwidth * rFrac;
585-
}
586-
else {
576+
} else {
587577
var extraThickness = outerwidth - thickPx;
588578
marginOpts.l = extraThickness * lFrac;
589579
marginOpts.r = extraThickness * rFrac;

src/components/colorscale/calc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ module.exports = function calc(gd, trace, opts) {
4141
if(auto !== false && mid !== undefined) {
4242
if(max - mid > mid - min) {
4343
min = mid - (max - mid);
44-
}
45-
else if(max - mid < mid - min) {
44+
} else if(max - mid < mid - min) {
4645
max = mid + (mid - min);
4746
}
4847
}

src/components/colorscale/helpers.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,17 @@ function makeColorScaleFunc(specs, opts) {
135135

136136
if(noNumericCheck && returnArray) {
137137
sclFunc = _sclFunc;
138-
}
139-
else if(noNumericCheck) {
138+
} else if(noNumericCheck) {
140139
sclFunc = function(v) {
141140
return colorArray2rbga(_sclFunc(v));
142141
};
143-
}
144-
else if(returnArray) {
142+
} else if(returnArray) {
145143
sclFunc = function(v) {
146144
if(isNumeric(v)) return _sclFunc(v);
147145
else if(tinycolor(v).isValid()) return v;
148146
else return Color.defaultLine;
149147
};
150-
}
151-
else {
148+
} else {
152149
sclFunc = function(v) {
153150
if(isNumeric(v)) return colorArray2rbga(_sclFunc(v));
154151
else if(tinycolor(v).isValid()) return v;

src/components/dragelement/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ dragElement.init = function init(options) {
241241

242242
try {
243243
e2 = new MouseEvent('click', e);
244-
}
245-
catch(err) {
244+
} catch(err) {
246245
var offset = pointerOffset(e);
247246
e2 = document.createEvent('MouseEvents');
248247
e2.initMouseEvent('click',

0 commit comments

Comments
 (0)