Skip to content

Eslint 1tbs help update else statement blocks #3757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 5,
"ecmaVersion": 5
},
"env": {
"commonjs": true
Expand All @@ -27,7 +27,7 @@
"indent": [0],
"indent-legacy": [2, 4, {"SwitchCase": 1}],
"max-len": [0, 80],
"brace-style": [0, "stroustrup", {"allowSingleLine": true}],
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"curly": [2, "multi-line"],
"camelcase": [2, {"properties": "never"}],
"comma-spacing": [2, {"before": false, "after": true}],
Expand Down
3 changes: 1 addition & 2 deletions devtools/test_dashboard/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ window.timeit = function(f, n, nchunk, arg) {
for(var j = 0; j < nchunk; j++) { f(_arg); }
t1 = performance.now();
dt = (t1 - t0) / nchunk;
}
else {
} else {
t0 = performance.now();
f(_arg);
t1 = performance.now();
Expand Down
3 changes: 1 addition & 2 deletions src/components/annotations/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ function getToggleSets(gd, hoverData) {
if(anni.visible) {
if(showMode === 'onout') toggleType = offSet;
else toggleType = explicitOffSet;
}
else {
} else {
toggleType = onSet;
}
toggleType.push(i);
Expand Down
27 changes: 9 additions & 18 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,11 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
}
basePx = ax._offset + ax.r2p(options[axLetter]);
autoAlignFraction = 0.5;
}
else {
} else {
if(axLetter === 'x') {
alignPosition = options[axLetter];
basePx = gs.l + gs.w * alignPosition;
}
else {
} else {
alignPosition = 1 - options[axLetter];
basePx = gs.t + gs.h * alignPosition;
}
Expand All @@ -344,8 +342,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
posPx.tail = ax._offset + ax.r2p(arrowLength);
// tail is data-referenced: autorange pads the text in px from the tail
textPadShift = textShift;
}
else {
} else {
posPx.tail = basePx + arrowLength;
// tail is specified in px from head, so autorange also pads vs head
textPadShift = textShift + arrowLength;
Expand All @@ -365,17 +362,15 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
if(shiftPlus > 0) {
posPx.tail += shiftPlus;
posPx.text += shiftPlus;
}
else if(shiftMinus > 0) {
} else if(shiftMinus > 0) {
posPx.tail -= shiftMinus;
posPx.text -= shiftMinus;
}
}

posPx.tail += overallShift;
posPx.head += overallShift;
}
else {
} else {
// with no arrow, the text rotates and *then* we put the anchor
// relative to the new bounding box
textShift = annSize * shiftFraction(autoAlignFraction, anchor);
Expand Down Expand Up @@ -419,8 +414,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
y: borderfull + yShift
})
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);
}
else {
} else {
var texty = borderfull + yShift - anntextBB.top;
var textx = borderfull + xShift - anntextBB.left;

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

drawArrow(dx, dy);
}
else if(!subplotId) {
} else if(!subplotId) {
var xUpdate, yUpdate;
if(xa) {
xUpdate = xa.p2r(xa.r2p(options.x) + dx);
Expand Down Expand Up @@ -660,8 +653,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
options.xanchor, options.yanchor
);
}
}
else return;
} else return;

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

Registry.call('_guiRelayout', gd, getUpdateObj());
});
}
else annText.call(textLayout);
} else annText.call(textLayout);
}
3 changes: 1 addition & 2 deletions src/components/annotations/draw_arrow_head.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ module.exports = function drawArrowHead(el3, ends, options) {
start.y -= startbackOffY;
el3.attr({x1: start.x, y1: start.y});
}
}
else if(el.nodeName === 'path') {
} else if(el.nodeName === 'path') {
var pathlen = el.getTotalLength();
// using dash to hide the backOff region of the path.
// if we ever allow dash for the arrow we'll have to
Expand Down
6 changes: 2 additions & 4 deletions src/components/calendars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,15 @@ function worldCalFmt(fmt, x, calendar) {
directiveLen = 3;
directive = fmt.charAt(i + 2);
if(modifier === '_') modifier = '-';
}
else {
} else {
directive = modifier;
modifier = '0';
directiveLen = 2;
}
directiveObj = d3ToWorldCalendars[directive];
if(!directiveObj) {
i += directiveLen;
}
else {
} else {
// code is recognized as a date part but world-calendars doesn't support it
if(directiveObj === UNKNOWN) replacementPart = UNKNOWN;

Expand Down
36 changes: 21 additions & 15 deletions src/components/color/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,26 @@ color.clean = function(container) {
key = keys[i];
val = container[key];

// only sanitize keys that end in "color" or "colorscale"
if(key.substr(key.length - 5) === 'color') {
// only sanitize keys that end in "color" or "colorscale"

if(Array.isArray(val)) {
for(j = 0; j < val.length; j++) val[j] = cleanOne(val[j]);
}
else container[key] = cleanOne(val);
}
else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
} else container[key] = cleanOne(val);
} else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
// colorscales have the format [[0, color1], [frac, color2], ... [1, colorN]]

for(j = 0; j < val.length; j++) {
if(Array.isArray(val[j])) val[j][1] = cleanOne(val[j][1]);
}
}
// recurse into arrays of objects, and plain objects
else if(Array.isArray(val)) {
} else if(Array.isArray(val)) {
// recurse into arrays of objects, and plain objects

var el0 = val[0];
if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
for(j = 0; j < val.length; j++) color.clean(val[j]);
}
}
else if(val && typeof val === 'object') color.clean(val);
} else if(val && typeof val === 'object') color.clean(val);
}
};

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

// all parts must be non-negative numbers
if(!(parts[i] >= 0)) return val;
// alpha>1 gets clipped to 1
if(!(parts[i] >= 0)) {
// all parts must be non-negative numbers

return val;
}

if(i === 3) {
// alpha>1 gets clipped to 1

if(parts[i] > 1) parts[i] = 1;
} else if(parts[i] >= 1) {
// r, g, b must be < 1 (ie 1 itself is not allowed)

return val;
}
// r, g, b must be < 1 (ie 1 itself is not allowed)
else if(parts[i] >= 1) return val;
}

var rgbStr = Math.round(parts[0] * 255) + ', ' +
Expand Down
30 changes: 10 additions & 20 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ module.exports = function draw(gd, id) {

if(opts.fillgradient) {
filllevels = [0];
}
else if(typeof opts.fillcolor === 'function') {
} else if(typeof opts.fillcolor === 'function') {
if(opts.filllevels) {
l0 = opts.filllevels.end + opts.filllevels.size / 100;
ls = opts.filllevels.size;
Expand All @@ -105,16 +104,14 @@ module.exports = function draw(gd, id) {
if(ls > 0 ? (l >= l0) : (l <= l0)) break;
if(l > zrange[0] && l < zrange[1]) filllevels.push(l);
}
}
else {
} else {
filllevels = linelevels.map(function(v) {
return v - opts.levels.size / 2;
});
filllevels.push(filllevels[filllevels.length - 1] +
opts.levels.size);
}
}
else if(opts.fillcolor && typeof opts.fillcolor === 'string') {
} else if(opts.fillcolor && typeof opts.fillcolor === 'string') {
// doesn't matter what this value is, with a single value
// we'll make a single fill rect covering the whole bar
filllevels = [0];
Expand Down Expand Up @@ -292,8 +289,7 @@ module.exports = function draw(gd, id) {
if(opts.title.side === 'top') {
y = (1 - (yBottomFrac + lenFrac - ypadFrac)) * gs.h +
gs.t + 3 + fontSize * 0.75;
}
else {
} else {
y = (1 - (yBottomFrac + ypadFrac)) * gs.h +
gs.t - 3 - fontSize * 0.25;
}
Expand Down Expand Up @@ -323,8 +319,7 @@ module.exports = function draw(gd, id) {
// vertical alignment, but this seems to work.
titleTrans[1] -= (titleHeight - lineSize) / 2;
}
}
else if(titleText.node() &&
} else if(titleText.node() &&
!titleText.classed(cn.jsPlaceholder)) {
titleHeight = Drawing.bBox(titleText.node()).height;
}
Expand All @@ -336,8 +331,7 @@ module.exports = function draw(gd, id) {
if(opts.title.side === 'top') {
cbAxisOut.domain[1] -= titleHeight / gs.h;
titleTrans[1] *= -1;
}
else {
} else {
cbAxisOut.domain[0] += titleHeight / gs.h;
var nlines = svgTextUtils.lineCount(titleText);
titleTrans[1] += (1 - nlines) * lineSize;
Expand Down Expand Up @@ -395,8 +389,7 @@ module.exports = function draw(gd, id) {
if(opts.fillgradient) {
Drawing.gradient(fillEl, gd, id, 'vertical',
opts.fillgradient, 'fill');
}
else {
} else {
// Tinycolor can't handle exponents and
// at this scale, removing it makes no difference.
var colorString = fillcolormap(d).replace('e-', '');
Expand Down Expand Up @@ -514,8 +507,7 @@ module.exports = function draw(gd, id) {
if(mathJaxNode &&
['top', 'bottom'].indexOf(opts.title.side) !== -1) {
titleWidth = Drawing.bBox(mathJaxNode).width;
}
else {
} else {
// note: the formula below works for all title sides,
// (except for top/bottom mathjax, above)
// but the weird gs.l is because the titleunshift
Expand Down Expand Up @@ -569,8 +561,7 @@ module.exports = function draw(gd, id) {
marginOpts.y = opts.y;
marginOpts.t = outerheight * tFrac;
marginOpts.b = outerheight * bFrac;
}
else {
} else {
marginOpts.t = marginOpts.b = 0;
marginOpts.yt = opts.y + opts.len * tFrac;
marginOpts.yb = opts.y - opts.len * bFrac;
Expand All @@ -582,8 +573,7 @@ module.exports = function draw(gd, id) {
marginOpts.x = opts.x;
marginOpts.l = outerwidth * lFrac;
marginOpts.r = outerwidth * rFrac;
}
else {
} else {
var extraThickness = outerwidth - thickPx;
marginOpts.l = extraThickness * lFrac;
marginOpts.r = extraThickness * rFrac;
Expand Down
3 changes: 1 addition & 2 deletions src/components/colorscale/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ module.exports = function calc(gd, trace, opts) {
if(auto !== false && mid !== undefined) {
if(max - mid > mid - min) {
min = mid - (max - mid);
}
else if(max - mid < mid - min) {
} else if(max - mid < mid - min) {
max = mid + (mid - min);
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/components/colorscale/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,17 @@ function makeColorScaleFunc(specs, opts) {

if(noNumericCheck && returnArray) {
sclFunc = _sclFunc;
}
else if(noNumericCheck) {
} else if(noNumericCheck) {
sclFunc = function(v) {
return colorArray2rbga(_sclFunc(v));
};
}
else if(returnArray) {
} else if(returnArray) {
sclFunc = function(v) {
if(isNumeric(v)) return _sclFunc(v);
else if(tinycolor(v).isValid()) return v;
else return Color.defaultLine;
};
}
else {
} else {
sclFunc = function(v) {
if(isNumeric(v)) return colorArray2rbga(_sclFunc(v));
else if(tinycolor(v).isValid()) return v;
Expand Down
3 changes: 1 addition & 2 deletions src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ dragElement.init = function init(options) {

try {
e2 = new MouseEvent('click', e);
}
catch(err) {
} catch(err) {
var offset = pointerOffset(e);
e2 = document.createEvent('MouseEvents');
e2.initMouseEvent('click',
Expand Down
Loading