Skip to content

Commit a56fa2a

Browse files
authored
Merge pull request #3374 from plotly/new-eslint-rules
New eslint rules
2 parents 340ea44 + 771bd09 commit a56fa2a

File tree

225 files changed

+3533
-3501
lines changed

Some content is hidden

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

225 files changed

+3533
-3501
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"max-len": [0, 80],
3030
"brace-style": [0, "stroustrup", {"allowSingleLine": true}],
3131
"curly": [2, "multi-line"],
32-
"camelcase": [0, {"properties": "never"}],
32+
"camelcase": [2, {"properties": "never"}],
3333
"comma-spacing": [2, {"before": false, "after": true}],
3434
"comma-style": [2, "last"],
3535
"semi": [2],
@@ -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);

package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"deep-equal": "^1.0.1",
124124
"derequire": "^2.0.6",
125125
"ecstatic": "^3.3.0",
126-
"eslint": "^5.10.0",
126+
"eslint": "^5.11.0",
127127
"falafel": "^2.0.0",
128128
"fs-extra": "^2.0.0",
129129
"fuse.js": "^3.3.0",

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);

0 commit comments

Comments
 (0)