Skip to content

Commit 771bd09

Browse files
committed
enforce "one-var": [2, {"initialized": "never"}] eslint rule
1 parent e3d23e9 commit 771bd09

File tree

219 files changed

+3435
-3400
lines changed

Some content is hidden

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

219 files changed

+3435
-3400
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"no-shadow": [0, {"builtinGlobals": true}],
6464
"block-scoped-var": [2],
6565
"no-unused-vars": [2],
66+
"one-var": [2, {"initialized": "never"}],
6667
"no-undef-init": [2],
6768
"no-use-before-define": [2, "nofunc"],
6869
"no-loop-func": [2],

devtools/image_viewer/viewer.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ var path = require('path');
33

44
var d3 = require('d3');
55

6-
var $plotlist = document.getElementById('plot-list'),
7-
$toggles = document.getElementById('plot-toggles'),
8-
$images = document.getElementById('plot-images'),
9-
$mock = document.getElementById('plot-mock'),
10-
$toggleBaseline = document.createElement('button'),
11-
$toggleTest = document.createElement('button'),
12-
$toggleDiff = document.createElement('button'),
13-
$imgBaseline = document.createElement('img'),
14-
$imgTest = document.createElement('img'),
15-
$imgDiff = document.createElement('img');
6+
var $plotlist = document.getElementById('plot-list');
7+
var $toggles = document.getElementById('plot-toggles');
8+
var $images = document.getElementById('plot-images');
9+
var $mock = document.getElementById('plot-mock');
10+
var $toggleBaseline = document.createElement('button');
11+
var $toggleTest = document.createElement('button');
12+
var $toggleDiff = document.createElement('button');
13+
var $imgBaseline = document.createElement('img');
14+
var $imgTest = document.createElement('img');
15+
var $imgDiff = document.createElement('img');
1616

1717
$toggles.style.display = 'none';
1818
$images.style.display = 'none';
@@ -21,13 +21,13 @@ setupToggle($toggleBaseline, $imgBaseline, 'Baseline');
2121
setupToggle($toggleTest, $imgTest, 'Test');
2222
setupToggle($toggleDiff, $imgDiff, 'Diff');
2323

24-
var pathToRoot = path.join(__dirname, '../../'),
25-
pathToImageTest = path.join(pathToRoot, 'test/image'),
26-
pathToBuild = path.join(pathToRoot, 'build/'),
27-
dirMocks = path.join(pathToImageTest, 'mocks/'),
28-
dirBaseline = path.join(pathToImageTest, 'baselines/'),
29-
dirTest = path.join(pathToBuild, 'test_images/'),
30-
dirDiff = path.join(pathToBuild, 'test_images_diff/');
24+
var pathToRoot = path.join(__dirname, '../../');
25+
var pathToImageTest = path.join(pathToRoot, 'test/image');
26+
var pathToBuild = path.join(pathToRoot, 'build/');
27+
var dirMocks = path.join(pathToImageTest, 'mocks/');
28+
var dirBaseline = path.join(pathToImageTest, 'baselines/');
29+
var dirTest = path.join(pathToBuild, 'test_images/');
30+
var dirDiff = path.join(pathToBuild, 'test_images_diff/');
3131

3232
// N.B. brfs only understand hard-coded paths
3333
var imageNames = fs.readFileSync(

devtools/test_dashboard/devtools.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ searchBar.addEventListener('keyup', debounce(searchMocks, 250));
179179
function debounce(func, wait, immediate) {
180180
var timeout;
181181
return function() {
182-
var context = this, args = arguments;
182+
var context = this;
183+
var args = arguments;
183184
var later = function() {
184185
timeout = null;
185186
if(!immediate) func.apply(context, args);

src/components/annotations/click.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ function onClick(gd, hoverData) {
8282
* }
8383
*/
8484
function getToggleSets(gd, hoverData) {
85-
var annotations = gd._fullLayout.annotations,
86-
onSet = [],
87-
offSet = [],
88-
explicitOffSet = [],
89-
hoverLen = (hoverData || []).length;
85+
var annotations = gd._fullLayout.annotations;
86+
var onSet = [];
87+
var offSet = [];
88+
var explicitOffSet = [];
89+
var hoverLen = (hoverData || []).length;
9090

9191
var i, j, anni, showMode, pointj, xa, ya, toggleType;
9292

src/components/annotations/convert_coords.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ var toLogRange = require('../../lib/to_log_range');
2828
module.exports = function convertCoords(gd, ax, newType, doExtra) {
2929
ax = ax || {};
3030

31-
var toLog = (newType === 'log') && (ax.type === 'linear'),
32-
fromLog = (newType === 'linear') && (ax.type === 'log');
31+
var toLog = (newType === 'log') && (ax.type === 'linear');
32+
var fromLog = (newType === 'linear') && (ax.type === 'log');
3333

3434
if(!(toLog || fromLog)) return;
3535

36-
var annotations = gd._fullLayout.annotations,
37-
axLetter = ax._id.charAt(0),
38-
ann,
39-
attrPrefix;
36+
var annotations = gd._fullLayout.annotations;
37+
var axLetter = ax._id.charAt(0);
38+
var ann;
39+
var attrPrefix;
4040

4141
function convert(attr) {
42-
var currentVal = ann[attr],
43-
newVal = null;
42+
var currentVal = ann[attr];
43+
var newVal = null;
4444

4545
if(toLog) newVal = toLogRange(currentVal, ax.range);
4646
else newVal = Math.pow(10, currentVal);

src/components/annotations/defaults.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ function handleAnnotationDefaults(annIn, annOut, fullLayout) {
3939
var showArrow = annOut.showarrow;
4040

4141
// positioning
42-
var axLetters = ['x', 'y'],
43-
arrowPosDflt = [-10, -30],
44-
gdMock = {_fullLayout: fullLayout};
42+
var axLetters = ['x', 'y'];
43+
var arrowPosDflt = [-10, -30];
44+
var gdMock = {_fullLayout: fullLayout};
45+
4546
for(var i = 0; i < 2; i++) {
4647
var axLetter = axLetters[i];
4748

@@ -57,9 +58,9 @@ function handleAnnotationDefaults(annIn, annOut, fullLayout) {
5758
Axes.coercePosition(annOut, gdMock, coerce, axRef, axLetter, 0.5);
5859

5960
if(showArrow) {
60-
var arrowPosAttr = 'a' + axLetter,
61-
// axref, ayref
62-
aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel');
61+
var arrowPosAttr = 'a' + axLetter;
62+
// axref, ayref
63+
var aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel');
6364

6465
// for now the arrow can only be on the same axis or specified as pixels
6566
// TODO: sometime it might be interesting to allow it to be on *any* axis

src/components/annotations/draw.js

+61-63
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
117117

118118
// calculated pixel positions
119119
// x & y each will get text, head, and tail as appropriate
120-
var annPosPx = {x: {}, y: {}},
121-
textangle = +options.textangle || 0;
120+
var annPosPx = {x: {}, y: {}};
121+
var textangle = +options.textangle || 0;
122122

123123
// create the components
124124
// made a single group to contain all, so opacity can work right
@@ -185,9 +185,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
185185
});
186186
}
187187

188-
var borderwidth = options.borderwidth,
189-
borderpad = options.borderpad,
190-
borderfull = borderwidth + borderpad;
188+
var borderwidth = options.borderwidth;
189+
var borderpad = options.borderpad;
190+
var borderfull = borderwidth + borderpad;
191191

192192
var annTextBG = annTextGroupInner.append('rect')
193193
.attr('class', 'bg')
@@ -270,24 +270,24 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
270270
var letters = ['x', 'y'];
271271

272272
for(var i = 0; i < letters.length; i++) {
273-
var axLetter = letters[i],
274-
axRef = options[axLetter + 'ref'] || axLetter,
275-
tailRef = options['a' + axLetter + 'ref'],
276-
ax = {x: xa, y: ya}[axLetter],
277-
dimAngle = (textangle + (axLetter === 'x' ? 0 : -90)) * Math.PI / 180,
278-
// note that these two can be either positive or negative
279-
annSizeFromWidth = outerWidth * Math.cos(dimAngle),
280-
annSizeFromHeight = outerHeight * Math.sin(dimAngle),
281-
// but this one is the positive total size
282-
annSize = Math.abs(annSizeFromWidth) + Math.abs(annSizeFromHeight),
283-
anchor = options[axLetter + 'anchor'],
284-
overallShift = options[axLetter + 'shift'] * (axLetter === 'x' ? 1 : -1),
285-
posPx = annPosPx[axLetter],
286-
basePx,
287-
textPadShift,
288-
alignPosition,
289-
autoAlignFraction,
290-
textShift;
273+
var axLetter = letters[i];
274+
var axRef = options[axLetter + 'ref'] || axLetter;
275+
var tailRef = options['a' + axLetter + 'ref'];
276+
var ax = {x: xa, y: ya}[axLetter];
277+
var dimAngle = (textangle + (axLetter === 'x' ? 0 : -90)) * Math.PI / 180;
278+
// note that these two can be either positive or negative
279+
var annSizeFromWidth = outerWidth * Math.cos(dimAngle);
280+
var annSizeFromHeight = outerHeight * Math.sin(dimAngle);
281+
// but this one is the positive total size
282+
var annSize = Math.abs(annSizeFromWidth) + Math.abs(annSizeFromHeight);
283+
var anchor = options[axLetter + 'anchor'];
284+
var overallShift = options[axLetter + 'shift'] * (axLetter === 'x' ? 1 : -1);
285+
var posPx = annPosPx[axLetter];
286+
var basePx;
287+
var textPadShift;
288+
var alignPosition;
289+
var autoAlignFraction;
290+
var textShift;
291291

292292
/*
293293
* calculate the *primary* pixel position
@@ -353,8 +353,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
353353
posPx.head = Lib.constrain(posPx.head, 1, maxPx - 1);
354354
}
355355
if(tailRef === 'pixel') {
356-
var shiftPlus = -Math.max(posPx.tail - 3, posPx.text),
357-
shiftMinus = Math.min(posPx.tail + 3, posPx.text) - maxPx;
356+
var shiftPlus = -Math.max(posPx.tail - 3, posPx.text);
357+
var shiftMinus = Math.min(posPx.tail + 3, posPx.text) - maxPx;
358358
if(shiftPlus > 0) {
359359
posPx.tail += shiftPlus;
360360
posPx.text += shiftPlus;
@@ -451,32 +451,32 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
451451
.selectAll('.annotation-arrow-g')
452452
.remove();
453453

454-
var headX = annPosPx.x.head,
455-
headY = annPosPx.y.head,
456-
tailX = annPosPx.x.tail + dx,
457-
tailY = annPosPx.y.tail + dy,
458-
textX = annPosPx.x.text + dx,
459-
textY = annPosPx.y.text + dy,
460-
461-
// find the edge of the text box, where we'll start the arrow:
462-
// create transform matrix to rotate the text box corners
463-
transform = Lib.rotationXYMatrix(textangle, textX, textY),
464-
applyTransform = Lib.apply2DTransform(transform),
465-
applyTransform2 = Lib.apply2DTransform2(transform),
466-
467-
// calculate and transform bounding box
468-
width = +annTextBG.attr('width'),
469-
height = +annTextBG.attr('height'),
470-
xLeft = textX - 0.5 * width,
471-
xRight = xLeft + width,
472-
yTop = textY - 0.5 * height,
473-
yBottom = yTop + height,
474-
edges = [
475-
[xLeft, yTop, xLeft, yBottom],
476-
[xLeft, yBottom, xRight, yBottom],
477-
[xRight, yBottom, xRight, yTop],
478-
[xRight, yTop, xLeft, yTop]
479-
].map(applyTransform2);
454+
var headX = annPosPx.x.head;
455+
var headY = annPosPx.y.head;
456+
var tailX = annPosPx.x.tail + dx;
457+
var tailY = annPosPx.y.tail + dy;
458+
var textX = annPosPx.x.text + dx;
459+
var textY = annPosPx.y.text + dy;
460+
461+
// find the edge of the text box, where we'll start the arrow:
462+
// create transform matrix to rotate the text box corners
463+
var transform = Lib.rotationXYMatrix(textangle, textX, textY);
464+
var applyTransform = Lib.apply2DTransform(transform);
465+
var applyTransform2 = Lib.apply2DTransform2(transform);
466+
467+
// calculate and transform bounding box
468+
var width = +annTextBG.attr('width');
469+
var height = +annTextBG.attr('height');
470+
var xLeft = textX - 0.5 * width;
471+
var xRight = xLeft + width;
472+
var yTop = textY - 0.5 * height;
473+
var yBottom = yTop + height;
474+
var edges = [
475+
[xLeft, yTop, xLeft, yBottom],
476+
[xLeft, yBottom, xRight, yBottom],
477+
[xRight, yBottom, xRight, yTop],
478+
[xRight, yTop, xLeft, yTop]
479+
].map(applyTransform2);
480480

481481
// Remove the line if it ends inside the box. Use ray
482482
// casting for rotated boxes: see which edges intersect a
@@ -500,9 +500,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
500500
}
501501
});
502502

503-
var strokewidth = options.arrowwidth,
504-
arrowColor = options.arrowcolor,
505-
arrowSide = options.arrowside;
503+
var strokewidth = options.arrowwidth;
504+
var arrowColor = options.arrowcolor;
505+
var arrowSide = options.arrowside;
506506

507507
var arrowGroup = annGroup.append('g')
508508
.style({opacity: Color.opacity(arrowColor)})
@@ -557,9 +557,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
557557
}
558558
},
559559
moveFn: function(dx, dy) {
560-
var annxy0 = applyTransform(annx0, anny0),
561-
xcenter = annxy0[0] + dx,
562-
ycenter = annxy0[1] + dy;
560+
var annxy0 = applyTransform(annx0, anny0);
561+
var xcenter = annxy0[0] + dx;
562+
var ycenter = annxy0[1] + dy;
563563
annTextGroupInner.call(Drawing.setTranslate, xcenter, ycenter);
564564

565565
modifyItem('x', xa ?
@@ -629,9 +629,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
629629
xUpdate = xa.p2r(xa.r2p(options.x) + dx);
630630

631631
} else {
632-
var widthFraction = options._xsize / gs.w,
633-
xLeft = options.x + (options._xshift - options.xshift) / gs.w -
634-
widthFraction / 2;
632+
var widthFraction = options._xsize / gs.w;
633+
var xLeft = options.x + (options._xshift - options.xshift) / gs.w - widthFraction / 2;
635634

636635
xUpdate = dragElement.align(xLeft + dx / gs.w,
637636
widthFraction, 0, 1, options.xanchor);
@@ -640,9 +639,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
640639
if(ya) {
641640
yUpdate = ya.p2r(ya.r2p(options.y) + dy);
642641
} else {
643-
var heightFraction = options._ysize / gs.h,
644-
yBottom = options.y - (options._yshift + options.yshift) / gs.h -
645-
heightFraction / 2;
642+
var heightFraction = options._ysize / gs.h;
643+
var yBottom = options.y - (options._yshift + options.yshift) / gs.h - heightFraction / 2;
646644

647645
yUpdate = dragElement.align(yBottom - dy / gs.h,
648646
heightFraction, 0, 1, options.yanchor);

src/components/annotations/draw_arrow_head.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ module.exports = function drawArrowHead(el3, ends, options) {
6969
hideLine();
7070
return;
7171
}
72-
var backOffX = backOff * Math.cos(startRot),
73-
backOffY = backOff * Math.sin(startRot);
72+
var backOffX = backOff * Math.cos(startRot);
73+
var backOffY = backOff * Math.sin(startRot);
7474

7575
end.x += backOffX;
7676
end.y += backOffY;
@@ -83,8 +83,8 @@ module.exports = function drawArrowHead(el3, ends, options) {
8383
hideLine();
8484
return;
8585
}
86-
var startBackOffX = startBackOff * Math.cos(startRot),
87-
startbackOffY = startBackOff * Math.sin(startRot);
86+
var startBackOffX = startBackOff * Math.cos(startRot);
87+
var startbackOffY = startBackOff * Math.sin(startRot);
8888

8989
start.x -= startBackOffX;
9090
start.y -= startbackOffY;
@@ -93,12 +93,12 @@ module.exports = function drawArrowHead(el3, ends, options) {
9393
}
9494
}
9595
else if(el.nodeName === 'path') {
96-
var pathlen = el.getTotalLength(),
97-
// using dash to hide the backOff region of the path.
98-
// if we ever allow dash for the arrow we'll have to
99-
// do better than this hack... maybe just manually
100-
// combine the two
101-
dashArray = '';
96+
var pathlen = el.getTotalLength();
97+
// using dash to hide the backOff region of the path.
98+
// if we ever allow dash for the arrow we'll have to
99+
// do better than this hack... maybe just manually
100+
// combine the two
101+
var dashArray = '';
102102

103103
if(pathlen < backOff + startBackOff) {
104104
hideLine();

src/components/calendars/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ var d3ToWorldCalendars = {
126126
};
127127

128128
function worldCalFmt(fmt, x, calendar) {
129-
var dateJD = Math.floor((x + 0.05) / ONEDAY) + EPOCHJD,
130-
cDate = getCal(calendar).fromJD(dateJD),
131-
i = 0,
132-
modifier, directive, directiveLen, directiveObj, replacementPart;
129+
var dateJD = Math.floor((x + 0.05) / ONEDAY) + EPOCHJD;
130+
var cDate = getCal(calendar).fromJD(dateJD);
131+
var i = 0;
132+
var modifier, directive, directiveLen, directiveObj, replacementPart;
133+
133134
while((i = fmt.indexOf('%', i)) !== -1) {
134135
modifier = fmt.charAt(i + 1);
135136
if(modifier === '0' || modifier === '-' || modifier === '_') {

0 commit comments

Comments
 (0)