Skip to content

Commit 4b34eaa

Browse files
authored
Merge pull request #925 from plotly/eslint-new-rules
New eslint rules
2 parents c04fbb3 + e5a4194 commit 4b34eaa

36 files changed

+101
-92
lines changed

.eslintrc

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"extends": [
44
"eslint:recommended"
55
],
6+
"parserOptions": {
7+
"ecmaVersion": 5,
8+
},
69
"env": {
710
"commonjs": true
811
},
@@ -14,7 +17,7 @@
1417
"indent": [2, 4, {"SwitchCase": 1}],
1518
"max-len": [0, 80],
1619
"brace-style": [0, "stroustrup", {"allowSingleLine": true}],
17-
"curly": [0, "multi"],
20+
"curly": [2, "multi-line"],
1821
"camelcase": [0, {"properties": "never"}],
1922
"comma-spacing": [2, {"before": false, "after": true}],
2023
"comma-style": [2, "last"],
@@ -32,20 +35,24 @@
3235
"space-in-parens": [2, "never"],
3336
"space-before-function-paren": [2, "never"],
3437
"space-before-blocks": [2],
38+
"spaced-comment": [2, "always"],
39+
"no-tabs": [2],
3540
"no-multi-spaces": [2],
3641
"no-whitespace-before-property": [2],
3742
"no-unexpected-multiline": [2],
3843
"no-floating-decimal": [2],
3944
"space-infix-ops": [2, {"int32Hint": true}],
4045
"quotes": [2, "single"],
4146
"dot-notation": [2],
47+
"dot-location": [2, "property"],
4248
"operator-linebreak": [2, "after"],
4349
"eqeqeq": [2],
44-
"new-cap": [0],
50+
"new-cap": [2, { "capIsNewExceptionPattern": "^MathJax\\.." }],
4551
"no-redeclare": [2, {"builtinGlobals": true}],
4652
"no-shadow": [0, {"builtinGlobals": true}],
4753
"block-scoped-var": [2],
4854
"no-unused-vars": [2],
55+
"no-undef-init": [2],
4956
"no-use-before-define": [2, "nofunc"],
5057
"no-loop-func": [2],
5158
"no-console": [0],

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"build": "npm run preprocess && npm run bundle && npm run header && npm run stats",
2929
"cibuild": "npm run preprocess && node tasks/cibundle.js",
3030
"watch": "node tasks/watch.js",
31-
"lint": "eslint . || true",
31+
"lint": "eslint --version && eslint . || true",
3232
"lint-fix": "eslint . --fix",
3333
"pretest": "node tasks/pretest.js",
3434
"test-jasmine": "karma start test/jasmine/karma.conf.js",
@@ -92,7 +92,7 @@
9292
"browserify": "^13.0.0",
9393
"browserify-transform-tools": "^1.5.1",
9494
"ecstatic": "^1.4.0",
95-
"eslint": "^3.0.0",
95+
"eslint": "^3.5.0",
9696
"falafel": "^1.2.0",
9797
"fs-extra": "^0.30.0",
9898
"fuse.js": "^2.2.0",

src/components/annotations/draw.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,16 @@ function drawOne(gd, index, opt, value) {
409409
// and the annotation center are visible
410410
if(options.showarrow) {
411411
if(options.axref === options.xref) {
412-
//we don't want to constrain if the tail is absolute
413-
//or the slope (which is meaningful) will change.
412+
// we don't want to constrain if the tail is absolute
413+
// or the slope (which is meaningful) will change.
414414
arrowX = annPosPx.x;
415415
} else {
416416
arrowX = Lib.constrain(annPosPx.x - options.ax, 1, fullLayout.width - 1);
417417
}
418418

419419
if(options.ayref === options.yref) {
420-
//we don't want to constrain if the tail is absolute
421-
//or the slope (which is meaningful) will change.
420+
// we don't want to constrain if the tail is absolute
421+
// or the slope (which is meaningful) will change.
422422
arrowY = annPosPx.y;
423423
} else {
424424
arrowY = Lib.constrain(annPosPx.y - options.ay, 1, fullLayout.height - 1);

src/components/colorbar/draw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ module.exports = function draw(gd, id) {
527527
container.attr('transform',
528528
'translate(' + (gs.l - xoffset) + ',' + gs.t + ')');
529529

530-
//auto margin adjustment
530+
// auto margin adjustment
531531
Plots.autoMargin(gd, id, {
532532
x: opts.x,
533533
y: opts.y,

src/components/drawing/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL
204204

205205
// handle multi-trace graph edit case
206206
if(d.ms === 'various' || marker.size === 'various') r = 3;
207-
else r = subTypes.isBubble(trace) ?
207+
else {
208+
r = subTypes.isBubble(trace) ?
208209
sizeFn(d.ms) : (marker.size || 6) / 2;
210+
}
209211

210212
// store the calculated size so hover can use it
211213
d.mrc = r;

src/components/legend/draw.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ function computeLegendDimensions(gd, groups, traces) {
590590
maxTraceWidth = 0,
591591
offsetX = 0;
592592

593-
//calculate largest width for traces and use for width of all legend items
593+
// calculate largest width for traces and use for width of all legend items
594594
traces.each(function(d) {
595595
maxTraceWidth = Math.max(40 + d[0].width, maxTraceWidth);
596596
});
@@ -604,7 +604,7 @@ function computeLegendDimensions(gd, groups, traces) {
604604
offsetX = 0;
605605
rowHeight = rowHeight + maxTraceHeight;
606606
opts.height = opts.height + maxTraceHeight;
607-
//reset for next row
607+
// reset for next row
608608
maxTraceHeight = 0;
609609
}
610610

@@ -615,7 +615,7 @@ function computeLegendDimensions(gd, groups, traces) {
615615
opts.width += traceGap + traceWidth;
616616
opts.height = Math.max(opts.height, legendItem.height);
617617

618-
//keep track of tallest trace in group
618+
// keep track of tallest trace in group
619619
offsetX += traceGap + traceWidth;
620620
maxTraceHeight = Math.max(legendItem.height, maxTraceHeight);
621621
});

src/lib/matrix.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ exports.apply2DTransform = function(transform) {
9393
var args = arguments;
9494
if(args.length === 3) {
9595
args = args[0];
96-
}//from map
96+
}// from map
9797
var xy = arguments.length === 1 ? args[0] : [args[0], args[1]];
9898
return exports.dot(transform, [xy[0], xy[1], 1]).slice(0, 2);
9999
};

src/plot_api/plot_api.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function setPlotContext(gd, config) {
355355
}
356356
}
357357

358-
//staticPlot forces a bunch of others:
358+
// staticPlot forces a bunch of others:
359359
if(context.staticPlot) {
360360
context.editable = false;
361361
context.autosizable = false;
@@ -418,8 +418,8 @@ function plotPolar(gd, data, layout) {
418418

419419
var titleLayout = function() {
420420
this.call(svgTextUtils.convertToTspans);
421-
//TODO: html/mathjax
422-
//TODO: center title
421+
// TODO: html/mathjax
422+
// TODO: center title
423423
};
424424

425425
var title = polarPlotSVG.select('.title-group text')
@@ -1490,7 +1490,7 @@ function _restyle(gd, aobj, _traces) {
14901490
} else if(Registry.traceIs(cont, 'cartesian')) {
14911491
Lib.nestedProperty(cont, 'marker.colors')
14921492
.set(Lib.nestedProperty(cont, 'marker.color').get());
1493-
//look for axes that are no longer in use and delete them
1493+
// look for axes that are no longer in use and delete them
14941494
flagAxForDelete[cont.xaxis || 'x'] = true;
14951495
flagAxForDelete[cont.yaxis || 'y'] = true;
14961496
}

src/plots/cartesian/axes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ axes.coerceRef = function(containerIn, containerOut, gd, axLetter, dflt) {
5555
return Lib.coerce(containerIn, containerOut, attrDef, refAttr);
5656
};
5757

58-
//todo: duplicated per github PR 610. Should be consolidated with axes.coerceRef.
58+
// todo: duplicated per github PR 610. Should be consolidated with axes.coerceRef.
5959
// find the list of possible axes to reference with an axref or ayref attribute
6060
// and coerce it to that list
6161
axes.coerceARef = function(containerIn, containerOut, gd, axLetter, dflt) {
@@ -689,15 +689,15 @@ axes.autoTicks = function(ax, roughDTick) {
689689
ax.dtick = roundDTick(roughDTick, 1000, roundBase60);
690690
}
691691
else {
692-
//milliseconds
692+
// milliseconds
693693
base = Math.pow(10, Math.floor(Math.log(roughDTick) / Math.LN10));
694694
ax.dtick = roundDTick(roughDTick, base, roundBase10);
695695
}
696696
}
697697
else if(ax.type === 'log') {
698698
ax.tick0 = 0;
699699

700-
//only show powers of 10
700+
// only show powers of 10
701701
if(roughDTick > 0.7) ax.dtick = Math.ceil(roughDTick);
702702
else if(Math.abs(ax.range[1] - ax.range[0]) < 1) {
703703
// span is less than one power of 10

src/plots/cartesian/graph_interact.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
12101210
p1 = g1[0];
12111211
topOverlap = p0.pos + p0.dp + p0.size - p1.pos - p1.dp + p1.size;
12121212

1213-
//Only group points that lie on the same axes
1213+
// Only group points that lie on the same axes
12141214
if(topOverlap > 0.01 && (p0.pmin === p1.pmin) && (p0.pmax === p1.pmax)) {
12151215
// push the new point(s) added to this group out of the way
12161216
for(j = g1.length - 1; j >= 0; j--) g1[j].dp += topOverlap;

src/plots/cartesian/layout_attributes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ module.exports = {
475475
valType: 'enumerated',
476476
values: [
477477
'trace', 'category ascending', 'category descending', 'array'
478-
/*, 'value ascending', 'value descending'*/ // value ascending / descending to be implemented later
478+
/* , 'value ascending', 'value descending'*/ // value ascending / descending to be implemented later
479479
],
480480
dflt: 'trace',
481481
role: 'info',
@@ -484,7 +484,7 @@ module.exports = {
484484
'By default, plotly uses *trace*, which specifies the order that is present in the data supplied.',
485485
'Set `categoryorder` to *category ascending* or *category descending* if order should be determined by',
486486
'the alphanumerical order of the category names.',
487-
/*'Set `categoryorder` to *value ascending* or *value descending* if order should be determined by the',
487+
/* 'Set `categoryorder` to *value ascending* or *value descending* if order should be determined by the',
488488
'numerical order of the values.',*/ // // value ascending / descending to be implemented later
489489
'Set `categoryorder` to *array* to derive the ordering from the attribute `categoryarray`. If a category',
490490
'is not found in the `categoryarray` array, the sorting behavior for that attribute will be identical to',

src/plots/gl3d/camera.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function createCamera(element, options) {
112112
var curCenter = view.computedCenter.slice();
113113
view.setMode(mode);
114114
if(mode === 'turntable') {
115-
//Hacky time warping stuff to generate smooth animation
115+
// Hacky time warping stuff to generate smooth animation
116116
var t0 = now();
117117
view._active.lookAt(t0, curEye, curCenter, curUp);
118118
view._active.lookAt(t0 + 500, curEye, curCenter, [0, 0, 1]);
@@ -204,17 +204,17 @@ function createCamera(element, options) {
204204
var drot = Math.PI * camera.rotateSpeed;
205205

206206
if((rotate && left && !ctrl && !alt && !shift) || (left && !ctrl && !alt && shift)) {
207-
//Rotate
207+
// Rotate
208208
view.rotate(t, flipX * drot * dx, -flipY * drot * dy, 0);
209209
}
210210

211211
if((pan && left && !ctrl && !alt && !shift) || right || (left && ctrl && !alt && !shift)) {
212-
//Pan
212+
// Pan
213213
view.pan(t, -camera.translateSpeed * dx * distance, camera.translateSpeed * dy * distance, 0);
214214
}
215215

216216
if((zoom && left && !ctrl && !alt && !shift) || middle || (left && !ctrl && alt && !shift)) {
217-
//Zoom
217+
// Zoom
218218
var kzoom = -camera.zoomSpeed * dy / window.innerHeight * (t - view.lastT()) * 100;
219219
view.pan(t, 0, 0, distance * (Math.exp(kzoom) - 1));
220220
}

src/plots/gl3d/layout/convert.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ proto.merge = function(sceneLayout) {
7676
for(var i = 0; i < 3; ++i) {
7777
var axes = sceneLayout[AXES_NAMES[i]];
7878

79-
/////// Axes labels //
79+
// Axes labels
8080
opts.labels[i] = convertHTMLToUnicode(axes.title);
8181
if('titlefont' in axes) {
8282
if(axes.titlefont.color) opts.labelColor[i] = str2RgbaArray(axes.titlefont.color);
8383
if(axes.titlefont.family) opts.labelFont[i] = axes.titlefont.family;
8484
if(axes.titlefont.size) opts.labelSize[i] = axes.titlefont.size;
8585
}
8686

87-
/////// LINES ////////
87+
// Lines
8888
if('showline' in axes) opts.lineEnable[i] = axes.showline;
8989
if('linecolor' in axes) opts.lineColor[i] = str2RgbaArray(axes.linecolor);
9090
if('linewidth' in axes) opts.lineWidth[i] = axes.linewidth;
@@ -100,8 +100,7 @@ proto.merge = function(sceneLayout) {
100100
if('zerolinecolor' in axes) opts.zeroLineColor[i] = str2RgbaArray(axes.zerolinecolor);
101101
if('zerolinewidth' in axes) opts.zeroLineWidth[i] = axes.zerolinewidth;
102102

103-
//////// TICKS /////////
104-
/// tick lines
103+
// tick lines
105104
if('ticks' in axes && !!axes.ticks) opts.lineTickEnable[i] = true;
106105
else opts.lineTickEnable[i] = false;
107106

src/plots/gl3d/layout/tick_marks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
/*eslint block-scoped-var: 0*/
10-
/*eslint no-redeclare: 0*/
9+
/* eslint block-scoped-var: 0*/
10+
/* eslint no-redeclare: 0*/
1111

1212
'use strict';
1313

@@ -82,7 +82,7 @@ function computeTickMarks(scene) {
8282

8383
axesOptions.ticks = ticks;
8484

85-
//Calculate tick lengths dynamically
85+
// Calculate tick lengths dynamically
8686
for(var i = 0; i < 3; ++i) {
8787
centerPoint[i] = 0.5 * (scene.glplot.bounds[0][i] + scene.glplot.bounds[1][i]);
8888
for(var j = 0; j < 2; ++j) {

0 commit comments

Comments
 (0)